-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocalImageFactory.java
102 lines (83 loc) · 2.69 KB
/
LocalImageFactory.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package skyview.survey;
/** This class implements a cache where images
* may be stored after being retrieved. This class
* will generate a FitsImage if the file is in the
* cache, or a proxy image if it is not. The proxy
* will have an approximation to the WCS of the real image.
*/
import skyview.executive.Settings;
import skyview.survey.Image;
import skyview.survey.ProxyImage;
import skyview.geometry.Scaler;
import skyview.geometry.Projection;
import skyview.geometry.CoordinateSystem;
import skyview.geometry.WCS;
import java.io.File;
public class LocalImageFactory implements ImageFactory {
static final public String DFT_CACHE = "." + File.separator + "skycache" + File.separator;
static private java.util.regex.Pattern comma = java.util.regex.Pattern.compile(",");
public Image factory(String spell) {
if (Settings.get("SpellSuffix") != null) {
spell += Settings.get("SpellSuffix");
}
if (Settings.get("SpellPrefix") != null) {
spell = Settings.get("SpellPrefix") + spell;
}
String[] tokens = comma.split(spell);
String url = tokens[0];
System.err.println("LocalImageFactory: Opening image @ "+url);
if (new File(url).exists()) {
try {
return new FitsImage(url);
} catch (SurveyException s) {
System.err.println(s);
return null;
}
} else {
System.err.println("No such file " + url);
return null;
}
}
public static String getSurveySubdir() {
String subdir = null;
String[] dirs = Settings.getArray("shortname");
if (dirs.length == 0) {
return null;
} else {
subdir = dirs[0];
subdir = subdir.replaceAll("[^a-zA-Z0-9\\-\\_\\+\\.]", "_");
}
return subdir;
}
public static String getCachedFileName(String file) {
String cacheString = Settings.get("cache", DFT_CACHE);
String[] caches = comma.split(cacheString);
boolean appendSurvey = Settings.has("SaveBySurvey");
String subdir = null;
if (appendSurvey) {
subdir = getSurveySubdir();
if (subdir == null) {
appendSurvey = false;
}
}
// First try the caches without the survey
// name appended
for (String cache: caches) {
String test = cache+file;
if (new java.io.File(test).exists()) {
return test;
}
}
// Now if the user has asked for the cache to
// be split, try inside...
if (appendSurvey) {
for (String cache: caches) {
String test = cache+subdir+File.separatorChar+file;
if (new java.io.File(test).exists()) {
return test;
}
}
}
return null;
}
}