1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
package wjhk.jupload2.context; |
22 | |
|
23 | |
import java.awt.Cursor; |
24 | |
import java.io.IOException; |
25 | |
import java.io.InputStream; |
26 | |
import java.net.MalformedURLException; |
27 | |
import java.net.URL; |
28 | |
import java.net.URLConnection; |
29 | |
import java.util.Properties; |
30 | |
import java.util.Vector; |
31 | |
|
32 | |
import javax.swing.JApplet; |
33 | |
import javax.swing.JFrame; |
34 | |
|
35 | |
import wjhk.jupload2.JUploadDaemon; |
36 | |
import wjhk.jupload2.exception.JUploadException; |
37 | |
import wjhk.jupload2.gui.filepanel.FilePanel.FileListViewMode; |
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
public class JUploadContextExecutable extends DefaultJUploadContext { |
50 | |
|
51 | |
final static String DEFAULT_PROPERTIES_FILE = "/conf/default_daemon.properties"; |
52 | |
|
53 | |
final static String DAEMON_PROPERTIES_FILE = "/conf/daemon.properties"; |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | 0 | private JFrame jframe = null; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | 0 | protected Properties defaultProperties = null; |
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | 0 | protected Properties daemonProperties = null; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 0 | protected JUploadContextExecutable(JFrame jframe) { |
76 | 0 | if (jframe == null) { |
77 | 0 | throw new IllegalArgumentException("theApplet may not be null"); |
78 | |
} |
79 | 0 | this.jframe = jframe; |
80 | 0 | } |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 0 | public JUploadContextExecutable(JFrame jframe, String propertiesURL) { |
90 | 0 | if (jframe == null) { |
91 | 0 | throw new IllegalArgumentException("The jframe may not be null"); |
92 | |
} |
93 | 0 | this.jframe = jframe; |
94 | |
|
95 | |
|
96 | 0 | this.defaultProperties = loadPropertiesFromFileInJar(DEFAULT_PROPERTIES_FILE, null); |
97 | |
|
98 | |
|
99 | 0 | if (propertiesURL == null) { |
100 | |
|
101 | |
|
102 | 0 | this.daemonProperties = loadPropertiesFromFileInJar(DAEMON_PROPERTIES_FILE, this.defaultProperties); |
103 | |
} else { |
104 | |
|
105 | 0 | this.daemonProperties = loadPropertiesFromURL(propertiesURL, this.defaultProperties); |
106 | |
} |
107 | |
|
108 | |
|
109 | 0 | init(jframe, this.jframe); |
110 | 0 | } |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
Properties loadPropertiesFromFileInJar(String filename, Properties defaultProperties) { |
120 | 0 | Properties properties = new Properties(defaultProperties); |
121 | |
try { |
122 | |
|
123 | 0 | InputStream isProperties = Class.forName("wjhk.jupload2.JUploadApplet").getResourceAsStream(filename); |
124 | 0 | properties.load(isProperties); |
125 | 0 | isProperties.close(); |
126 | 0 | } catch (IOException e1) { |
127 | 0 | System.out.println("Error while loading " + filename + " (" + e1.getClass().getName() + ")"); |
128 | 0 | e1.printStackTrace(); |
129 | 0 | } catch (ClassNotFoundException e1) { |
130 | 0 | System.out.println("Error while loading " + filename + " (" + e1.getClass().getName() + ")"); |
131 | 0 | e1.printStackTrace(); |
132 | 0 | } |
133 | |
|
134 | 0 | return properties; |
135 | |
} |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
private Properties loadPropertiesFromURL(String propertiesURL, Properties defaultProperties) { |
145 | 0 | Properties properties = new Properties(defaultProperties); |
146 | |
URL url; |
147 | |
try { |
148 | 0 | url = new URL(propertiesURL); |
149 | 0 | URLConnection urlConnection = url.openConnection(); |
150 | 0 | properties.load(urlConnection.getInputStream()); |
151 | 0 | } catch (MalformedURLException e) { |
152 | 0 | System.out.println("Error while loading url " + propertiesURL + " (" + e.getClass().getName() + ")"); |
153 | 0 | e.printStackTrace(); |
154 | 0 | } catch (IOException e) { |
155 | 0 | System.out.println("Error while loading url " + propertiesURL + " (" + e.getClass().getName() + ")"); |
156 | 0 | e.printStackTrace(); |
157 | 0 | } |
158 | |
|
159 | 0 | return properties; |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
@Override |
171 | |
public String getParameter(String key, String def) { |
172 | 0 | String paramStr = (this.daemonProperties.getProperty(key) != null ? this.daemonProperties.getProperty(key) |
173 | |
: def); |
174 | 0 | displayDebugParameterValue(key, paramStr); |
175 | 0 | return paramStr; |
176 | |
} |
177 | |
|
178 | |
|
179 | |
|
180 | |
@Override |
181 | |
public int getParameter(String key, int def) { |
182 | 0 | String paramDef = Integer.toString(def); |
183 | 0 | String paramStr = this.daemonProperties.getProperty(key) != null ? this.daemonProperties.getProperty(key) |
184 | |
: paramDef; |
185 | 0 | displayDebugParameterValue(key, paramStr); |
186 | 0 | return parseInt(paramStr, def); |
187 | |
} |
188 | |
|
189 | |
|
190 | |
@Override |
191 | |
public float getParameter(String key, float def) { |
192 | 0 | String paramDef = Float.toString(def); |
193 | 0 | String paramStr = this.daemonProperties.getProperty(key) != null ? this.daemonProperties.getProperty(key) |
194 | |
: paramDef; |
195 | 0 | displayDebugParameterValue(key, paramStr); |
196 | 0 | return parseFloat(paramStr, def); |
197 | |
} |
198 | |
|
199 | |
|
200 | |
@Override |
201 | |
public long getParameter(String key, long def) { |
202 | 0 | String paramDef = Long.toString(def); |
203 | 0 | String paramStr = this.daemonProperties.getProperty(key) != null ? this.daemonProperties.getProperty(key) |
204 | |
: paramDef; |
205 | 0 | displayDebugParameterValue(key, paramStr); |
206 | 0 | return parseLong(paramStr, def); |
207 | |
} |
208 | |
|
209 | |
|
210 | |
@Override |
211 | |
public boolean getParameter(String key, boolean def) { |
212 | 0 | String paramDef = (def ? "true" : "false"); |
213 | 0 | String paramStr = this.daemonProperties.getProperty(key) != null ? this.daemonProperties.getProperty(key) |
214 | |
: paramDef; |
215 | 0 | displayDebugParameterValue(key, paramStr); |
216 | 0 | return parseBoolean(paramStr, def); |
217 | |
} |
218 | |
|
219 | |
|
220 | |
@Override |
221 | |
public FileListViewMode getParameter(String key, FileListViewMode def) { |
222 | 0 | String paramDef = def.toString(); |
223 | 0 | String paramStr = this.daemonProperties.getProperty(key) != null ? this.daemonProperties.getProperty(key) |
224 | |
: paramDef; |
225 | 0 | displayDebugParameterValue(key, paramStr); |
226 | 0 | return parseFileListViewMode(paramStr, def); |
227 | |
} |
228 | |
|
229 | |
|
230 | |
@Override |
231 | |
public void displayURL(String url, boolean success) { |
232 | 0 | throw new UnsupportedOperationException("JUploadContextExecution.displayURL(): Not implemented yet!"); |
233 | |
} |
234 | |
|
235 | |
|
236 | |
@Override |
237 | |
public JApplet getApplet() { |
238 | 0 | throw new UnsupportedOperationException("Can't use getApplet(), when using the JUploadDaemon!"); |
239 | |
} |
240 | |
|
241 | |
|
242 | |
@Override |
243 | |
public Cursor getCursor() { |
244 | 0 | return this.jframe.getCursor(); |
245 | |
} |
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
@Override |
251 | |
public String normalizeURL(String url) throws JUploadException { |
252 | 0 | return url; |
253 | |
} |
254 | |
|
255 | |
|
256 | |
@Override |
257 | |
public void readCookieFromNavigator(Vector<String> headers) { |
258 | 0 | throw new UnsupportedOperationException("Can't use readCookieFromNavigator(), when using the JUploadDaemon!"); |
259 | |
} |
260 | |
|
261 | |
|
262 | |
@Override |
263 | |
public void readUserAgentFromNavigator(Vector<String> headers) { |
264 | 0 | throw new UnsupportedOperationException("Can't use readUserAgentFromNavigator(), when using the JUploadDaemon!"); |
265 | |
} |
266 | |
|
267 | |
|
268 | |
@Override |
269 | |
public Cursor setCursor(Cursor cursor) { |
270 | 0 | Cursor previousCursor = this.jframe.getCursor(); |
271 | 0 | this.jframe.setCursor(cursor); |
272 | 0 | return previousCursor; |
273 | |
} |
274 | |
|
275 | |
|
276 | |
@Override |
277 | |
public void showStatus(String status) { |
278 | |
|
279 | |
|
280 | 0 | } |
281 | |
|
282 | |
} |