svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / Launcher.java @ 1217
History | View | Annotate | Download (37.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.andami; |
42 |
|
43 |
import java.awt.EventQueue; |
44 |
import java.awt.Toolkit; |
45 |
import java.io.BufferedInputStream; |
46 |
import java.io.BufferedOutputStream; |
47 |
import java.io.File; |
48 |
import java.io.FileFilter; |
49 |
import java.io.FileInputStream; |
50 |
import java.io.FileNotFoundException; |
51 |
import java.io.FileOutputStream; |
52 |
import java.io.FileReader; |
53 |
import java.io.FileWriter; |
54 |
import java.io.FilenameFilter; |
55 |
import java.io.IOException; |
56 |
import java.io.InputStream; |
57 |
import java.lang.reflect.InvocationTargetException; |
58 |
import java.net.MalformedURLException; |
59 |
import java.net.URL; |
60 |
import java.net.URLConnection; |
61 |
import java.util.ArrayList; |
62 |
import java.util.Comparator; |
63 |
import java.util.Date; |
64 |
import java.util.HashMap; |
65 |
import java.util.HashSet; |
66 |
import java.util.Iterator; |
67 |
import java.util.Locale; |
68 |
import java.util.Properties; |
69 |
import java.util.PropertyResourceBundle; |
70 |
import java.util.ResourceBundle; |
71 |
import java.util.TreeMap; |
72 |
|
73 |
import javax.jnlp.BasicService; |
74 |
import javax.jnlp.ServiceManager; |
75 |
import javax.jnlp.UnavailableServiceException; |
76 |
import javax.swing.ImageIcon; |
77 |
import javax.swing.JComponent; |
78 |
import javax.swing.SwingUtilities; |
79 |
import javax.swing.UIManager; |
80 |
|
81 |
import org.apache.log4j.Logger; |
82 |
import org.apache.log4j.PatternLayout; |
83 |
import org.apache.log4j.PropertyConfigurator; |
84 |
import org.apache.log4j.RollingFileAppender; |
85 |
import org.exolab.castor.xml.MarshalException; |
86 |
import org.exolab.castor.xml.ValidationException; |
87 |
|
88 |
import com.iver.andami.config.generate.Andami; |
89 |
import com.iver.andami.config.generate.AndamiConfig; |
90 |
import com.iver.andami.config.generate.Plugin; |
91 |
import com.iver.andami.messages.Messages; |
92 |
import com.iver.andami.messages.NotificationManager; |
93 |
import com.iver.andami.plugins.PluginClassLoader; |
94 |
import com.iver.andami.plugins.config.generate.ActionTool; |
95 |
import com.iver.andami.plugins.config.generate.Depends; |
96 |
import com.iver.andami.plugins.config.generate.Extension; |
97 |
import com.iver.andami.plugins.config.generate.Extensions; |
98 |
import com.iver.andami.plugins.config.generate.LabelSet; |
99 |
import com.iver.andami.plugins.config.generate.Menu; |
100 |
import com.iver.andami.plugins.config.generate.PluginConfig; |
101 |
import com.iver.andami.plugins.config.generate.PopupMenu; |
102 |
import com.iver.andami.plugins.config.generate.PopupMenus; |
103 |
import com.iver.andami.plugins.config.generate.SelectableTool; |
104 |
import com.iver.andami.plugins.config.generate.SkinExtension; |
105 |
import com.iver.andami.plugins.config.generate.SkinExtensionType; |
106 |
import com.iver.andami.plugins.config.generate.ToolBar; |
107 |
import com.iver.andami.ui.MDIManagerLoadException; |
108 |
import com.iver.andami.ui.SplashWindow; |
109 |
import com.iver.andami.ui.AndamiEventQueue; |
110 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
111 |
import com.iver.andami.ui.mdiManager.MDIManagerFactory; |
112 |
import com.iver.utiles.XMLEntity; |
113 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
114 |
|
115 |
|
116 |
/**
|
117 |
* DOCUMENT ME!
|
118 |
*
|
119 |
* @author $author$
|
120 |
* @version $Revision: 1217 $
|
121 |
*/
|
122 |
public class Launcher { |
123 |
private static Logger logger = Logger.getLogger(Launcher.class.getName()); |
124 |
private static AndamiConfig andamiConfig; |
125 |
private static SplashWindow splashWindow; |
126 |
private static String userHome = System.getProperty("user.home"); |
127 |
private static String appName; |
128 |
private static Locale locale; |
129 |
private static HashMap pluginsConfig = new HashMap(); |
130 |
private static HashMap pluginsServices = new HashMap(); |
131 |
private static MDIFrame frame; |
132 |
private static HashMap classesExtensions = new HashMap(); |
133 |
private static String andamiConfigPath; |
134 |
private static String pluginsPersistencePath; |
135 |
|
136 |
/**
|
137 |
* DOCUMENT ME!
|
138 |
*
|
139 |
* @param args DOCUMENT ME!
|
140 |
*
|
141 |
* @throws InterruptedException
|
142 |
* @throws InvocationTargetException
|
143 |
* @throws ConfigurationException
|
144 |
* @throws MDIManagerLoadException
|
145 |
* @throws IOException
|
146 |
*/
|
147 |
public static void main(String[] args) |
148 |
throws InterruptedException, InvocationTargetException, |
149 |
ConfigurationException, MDIManagerLoadException, IOException { |
150 |
if ((args.length < 1) || (args.length > 2)) { |
151 |
System.err.println("Uso: Launcher appName [locale]"); |
152 |
} |
153 |
|
154 |
appName = args[0];
|
155 |
|
156 |
//Se crea el directorio de configuraci?n de la aplicaci?n
|
157 |
File parent = new File(System.getProperty("user.home") + File.separator + args[0] + |
158 |
File.separator);
|
159 |
parent.mkdirs(); |
160 |
|
161 |
andamiConfigPath = System.getProperty("user.home") + File.separator + |
162 |
appName + File.separator + "andami-config.xml"; |
163 |
pluginsPersistencePath = System.getProperty("user.home") + |
164 |
File.separator + appName + File.separator + |
165 |
"plugins-persistence.xml";
|
166 |
|
167 |
// Configurar el log4j
|
168 |
PropertyConfigurator.configure(Launcher.class.getClassLoader() |
169 |
.getResource("log4j.properties"));
|
170 |
|
171 |
PatternLayout l = new PatternLayout("%p %t %C - %m%n"); |
172 |
RollingFileAppender fa = new RollingFileAppender(l,
|
173 |
System.getProperty("user.home") + File.separator + args[0] + |
174 |
File.separator + args[0] + ".log", true); |
175 |
fa.setMaxFileSize("512KB");
|
176 |
fa.setMaxBackupIndex(3);
|
177 |
Logger.getRootLogger().addAppender(fa);
|
178 |
|
179 |
// Leer el fichero de configuraci?n de andami (andami-config.xsd)
|
180 |
// locale
|
181 |
// Buscar actualizaci?nes al comenzar
|
182 |
// Andami
|
183 |
// Plugins
|
184 |
// Directorio de las extensiones
|
185 |
andamiConfigFromXML(andamiConfigPath); |
186 |
|
187 |
// Configurar el locale
|
188 |
if (args.length == 2) { |
189 |
locale = new Locale(args[1]); |
190 |
} else {
|
191 |
locale = getLocale(andamiConfig.getLocaleLanguage(), |
192 |
andamiConfig.getLocaleCountry(), |
193 |
andamiConfig.getLocaleVariant()); |
194 |
} |
195 |
|
196 |
Locale.setDefault(locale);
|
197 |
JComponent.setDefaultLocale(locale);
|
198 |
Messages.init(locale); |
199 |
|
200 |
//Se pone el lookAndFeel
|
201 |
try {
|
202 |
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); |
203 |
} catch (Exception e) { |
204 |
logger.warn(Messages.getString("Launcher.look_and_feel"), e);
|
205 |
} |
206 |
|
207 |
// Mostrar la ventana de inicio
|
208 |
splashWindow = new SplashWindow(null); |
209 |
|
210 |
// TODO Buscar actualizaciones de Andami
|
211 |
// TODO Buscar actualizaciones de los plugins
|
212 |
downloadExtensions(andamiConfig.getPluginsDirectory()); |
213 |
|
214 |
// Se leen los config.xml de los plugins -----++++
|
215 |
loadPlugins(andamiConfig.getPluginsDirectory()); |
216 |
|
217 |
// Se configura el classloader del plugin
|
218 |
pluginsClassLoaders(); |
219 |
|
220 |
// Se carga un Skin si alguno de los plugins trae informaci?n para ello
|
221 |
skinPlugin(); |
222 |
|
223 |
//Se configura la cola de eventos
|
224 |
EventQueue waitQueue = new AndamiEventQueue(); |
225 |
Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);
|
226 |
|
227 |
// Se configura la mensajer?a del plugin
|
228 |
pluginsMessages(); |
229 |
|
230 |
// Se modifica el andami-config con los plugins nuevos
|
231 |
updateAndamiConfig(); |
232 |
|
233 |
// Se prepara el MainFrame para albergar las extensiones
|
234 |
frame = new MDIFrame();
|
235 |
|
236 |
// Se configura el nombre e icono de la aplicaci?n
|
237 |
frameIcon(); |
238 |
|
239 |
SwingUtilities.invokeAndWait(new Runnable() { |
240 |
public void run() { |
241 |
frame.init(); |
242 |
} |
243 |
}); |
244 |
|
245 |
// Se instalan los controles de las extensiones de los plugins
|
246 |
SwingUtilities.invokeAndWait(new Runnable() { |
247 |
public void run() { |
248 |
installPluginsControls(); |
249 |
installPluginsMenus(); |
250 |
installPluginsLabels(); |
251 |
} |
252 |
}); |
253 |
|
254 |
// Leer el fichero de persistencia
|
255 |
// info de los plugins
|
256 |
// bookmarks de los plugins
|
257 |
loadPluginsPersistence(); |
258 |
|
259 |
// Se instalan los controles del skin
|
260 |
// Se inicializan todas las extensiones de todos los plugins
|
261 |
SwingUtilities.invokeAndWait(new Runnable() { |
262 |
public void run() { |
263 |
initializeExtensions(); |
264 |
} |
265 |
}); |
266 |
frame.setClassesExtensions(classesExtensions); |
267 |
|
268 |
// Se instalan los bookmarks de los plugins
|
269 |
splashWindow.close(); |
270 |
|
271 |
//Se muestra el frame principal
|
272 |
frame.show(); |
273 |
|
274 |
SwingUtilities.invokeAndWait(new Runnable() { |
275 |
public void run() { |
276 |
frame.enableControls(); |
277 |
} |
278 |
}); |
279 |
} |
280 |
|
281 |
/**
|
282 |
* DOCUMENT ME!
|
283 |
*
|
284 |
* @throws ConfigurationException
|
285 |
*/
|
286 |
private static void loadPluginsPersistence() throws ConfigurationException { |
287 |
XMLEntity entity = persistenceFromXML(); |
288 |
|
289 |
for (int i = 0; i < entity.getNumChild(); i++) { |
290 |
XMLEntity plugin = entity.getChild(i); |
291 |
String pName = plugin.getStringProperty(
|
292 |
"com.iver.andami.pluginName");
|
293 |
((PluginServices) pluginsServices.get(pName)).setPersistentXML(plugin); |
294 |
} |
295 |
} |
296 |
|
297 |
/**
|
298 |
* DOCUMENT ME!
|
299 |
*/
|
300 |
private static void installPluginsLabels() { |
301 |
Iterator i = pluginsConfig.keySet().iterator();
|
302 |
|
303 |
while (i.hasNext()) {
|
304 |
String name = (String) i.next(); |
305 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(name); |
306 |
PluginServices ps = (PluginServices) pluginsServices.get(name); |
307 |
|
308 |
LabelSet[] ls = pc.getLabelSet();
|
309 |
|
310 |
for (int j = 0; j < ls.length; j++) { |
311 |
PluginClassLoader loader = ps.getClassLoader(); |
312 |
|
313 |
try {
|
314 |
Class clase = loader.loadClass(ls[j].getClassName());
|
315 |
frame.setLabels(clase, ls[j].getLabel()); |
316 |
} catch (ClassNotFoundException e) { |
317 |
logger.error(Messages.getString("Launcher.labelset_class"),
|
318 |
e); |
319 |
} |
320 |
} |
321 |
} |
322 |
} |
323 |
|
324 |
/**
|
325 |
* DOCUMENT ME!
|
326 |
*
|
327 |
* @throws MDIManagerLoadException
|
328 |
*/
|
329 |
private static void skinPlugin() throws MDIManagerLoadException { |
330 |
Iterator i = pluginsConfig.keySet().iterator();
|
331 |
|
332 |
while (i.hasNext()) {
|
333 |
String name = (String) i.next(); |
334 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(name); |
335 |
PluginServices ps = (PluginServices) pluginsServices.get(name); |
336 |
|
337 |
if (pc.getExtensions().getSkinExtension() != null) { |
338 |
if (MDIManagerFactory.getSkinExtension() != null) { |
339 |
logger.warn(Messages.getString("Launcher.Dos_skin_extension"));
|
340 |
} |
341 |
|
342 |
SkinExtension se = pc.getExtensions().getSkinExtension(); |
343 |
|
344 |
MDIManagerFactory.setSkinExtension(se, ps.getClassLoader()); |
345 |
|
346 |
Class skinClass;
|
347 |
|
348 |
try {
|
349 |
skinClass = ps.getClassLoader().loadClass(se.getClassName()); |
350 |
|
351 |
com.iver.andami.plugins.Extension skinInstance = (com.iver.andami.plugins.Extension) skinClass.newInstance(); |
352 |
classesExtensions.put(skinClass, skinInstance); |
353 |
} catch (ClassNotFoundException e) { |
354 |
logger.error(Messages.getString("Launcher.No_se_encontro_la_clase_mdi_manager"), e);
|
355 |
throw new MDIManagerLoadException(e); |
356 |
} catch (InstantiationException e) { |
357 |
logger.error(Messages.getString("Launcher.No_se_pudo_instanciar_la_clase_mdi_manager"), e);
|
358 |
throw new MDIManagerLoadException(e); |
359 |
} catch (IllegalAccessException e) { |
360 |
logger.error(Messages.getString("Launcher.No_se_pudo_acceder_a_la_clase_mdi_manager"), e);
|
361 |
throw new MDIManagerLoadException(e); |
362 |
} |
363 |
} |
364 |
} |
365 |
} |
366 |
|
367 |
/**
|
368 |
*
|
369 |
*/
|
370 |
private static void frameIcon() { |
371 |
Iterator i = pluginsConfig.keySet().iterator();
|
372 |
|
373 |
while (i.hasNext()) {
|
374 |
String pName = (String) i.next(); |
375 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
376 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
377 |
|
378 |
if (pc.getIcon() != null) { |
379 |
ImageIcon icon = new ImageIcon(ps.getClassLoader().getResource(pc.getIcon() |
380 |
.getSrc())); |
381 |
frame.setIconImage(icon.getImage()); |
382 |
frame.setTitle(pc.getIcon().getText()); |
383 |
} |
384 |
} |
385 |
} |
386 |
|
387 |
/**
|
388 |
*
|
389 |
*/
|
390 |
private static void initializeExtensions() { |
391 |
Iterator i = pluginsConfig.keySet().iterator();
|
392 |
|
393 |
while (i.hasNext()) {
|
394 |
String pName = (String) i.next(); |
395 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
396 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
397 |
|
398 |
Extension[] exts = pc.getExtensions().getExtension();
|
399 |
|
400 |
TreeMap orderedExtensions = new TreeMap(new ExtensionComparator()); |
401 |
|
402 |
for (int j = 0; j < exts.length; j++) { |
403 |
if (!exts[j].getActive()) {
|
404 |
continue;
|
405 |
} |
406 |
|
407 |
if (orderedExtensions.containsKey(exts[j])) {
|
408 |
logger.warn( |
409 |
Messages.getString("Launcher.Two_extensions_with_the_same_priority") +
|
410 |
exts[j].getClassName()); |
411 |
} |
412 |
|
413 |
orderedExtensions.put(exts[j], null);
|
414 |
} |
415 |
|
416 |
Iterator e = orderedExtensions.keySet().iterator();
|
417 |
|
418 |
while (e.hasNext()) {
|
419 |
Extension extension = (Extension) e.next(); |
420 |
com.iver.andami.plugins.Extension extensionInstance; |
421 |
|
422 |
try {
|
423 |
Class extensionClass = ps.getClassLoader().loadClass(extension.getClassName());
|
424 |
extensionInstance = (com.iver.andami.plugins.Extension) extensionClass.newInstance(); |
425 |
classesExtensions.put(extensionClass, extensionInstance); |
426 |
|
427 |
extensionInstance.inicializar(); |
428 |
} catch (InstantiationException e1) { |
429 |
logger.error(Messages.getString("Launcher.Error_instanciando_la_extension") +
|
430 |
extension.getClassName(), e1); |
431 |
} catch (IllegalAccessException e1) { |
432 |
logger.error(Messages.getString("Launcher.Error_instanciando_la_extension") +
|
433 |
extension.getClassName(), e1); |
434 |
} catch (ClassNotFoundException e1) { |
435 |
logger.error(Messages.getString("Launcher.No_se_encontro_la_clase_de_la_extension") +
|
436 |
extension.getClassName(), e1); |
437 |
} catch (NoClassDefFoundError e1) { |
438 |
logger.error(Messages.getString("Launcher.Error_localizando_la_clase_de_la_extension") +
|
439 |
extension.getClassName(), e1); |
440 |
} |
441 |
} |
442 |
} |
443 |
} |
444 |
|
445 |
/**
|
446 |
* DOCUMENT ME!
|
447 |
*/
|
448 |
private static void installPluginsMenus() { |
449 |
TreeMap orderedMenus = new TreeMap(new MenuComparator()); |
450 |
|
451 |
Iterator i = pluginsConfig.keySet().iterator();
|
452 |
|
453 |
while (i.hasNext()) {
|
454 |
String pName = (String) i.next(); |
455 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
456 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
457 |
|
458 |
Extension[] exts = pc.getExtensions().getExtension();
|
459 |
|
460 |
for (int j = 0; j < exts.length; j++) { |
461 |
if (!exts[j].getActive()) {
|
462 |
continue;
|
463 |
} |
464 |
|
465 |
Menu[] menu = exts[j].getMenu(); |
466 |
|
467 |
for (int k = 0; k < menu.length; k++) { |
468 |
SortableMenu sm = new SortableMenu(ps.getClassLoader(),
|
469 |
exts[j], menu[k]); |
470 |
|
471 |
if (orderedMenus.containsKey(sm)) {
|
472 |
logger.error( |
473 |
Messages.getString("Launcher.Two_menus_with_the_same_position") +
|
474 |
exts[j].getClassName()); |
475 |
} |
476 |
|
477 |
orderedMenus.put(sm, null);
|
478 |
} |
479 |
} |
480 |
|
481 |
// Se instalan las extensiones de MDI
|
482 |
SkinExtension skinExt = pc.getExtensions().getSkinExtension(); |
483 |
|
484 |
if (skinExt != null) { |
485 |
Menu[] menu = skinExt.getMenu(); |
486 |
|
487 |
for (int k = 0; k < menu.length; k++) { |
488 |
SortableMenu sm = new SortableMenu(ps.getClassLoader(),
|
489 |
skinExt, menu[k]); |
490 |
|
491 |
if (orderedMenus.containsKey(sm)) {
|
492 |
logger.error( |
493 |
Messages.getString("Launcher.Two_menus_with_the_same_position") +
|
494 |
skinExt.getClassName()); |
495 |
} |
496 |
|
497 |
orderedMenus.put(sm, null);
|
498 |
} |
499 |
} |
500 |
} |
501 |
|
502 |
//Se itera por los menus ordenados
|
503 |
Iterator e = orderedMenus.keySet().iterator();
|
504 |
|
505 |
// Se ordenan los menues
|
506 |
while (e.hasNext()) {
|
507 |
try {
|
508 |
SortableMenu sm = (SortableMenu) e.next(); |
509 |
|
510 |
frame.addMenu(sm.loader, sm.extension, sm.menu); |
511 |
} catch (ClassNotFoundException ex) { |
512 |
logger.error(Messages.getString("Launcher.No_se_encontro_la_clase_de_la_extension"), ex);
|
513 |
} |
514 |
} |
515 |
} |
516 |
|
517 |
/**
|
518 |
*
|
519 |
*/
|
520 |
private static void installPluginsControls() { |
521 |
Iterator i = pluginsConfig.keySet().iterator();
|
522 |
|
523 |
while (i.hasNext()) {
|
524 |
try {
|
525 |
String pName = (String) i.next(); |
526 |
PluginConfig pc = (PluginConfig) pluginsConfig.get(pName); |
527 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
528 |
|
529 |
Extension[] exts = pc.getExtensions().getExtension();
|
530 |
|
531 |
TreeMap orderedExtensions = new TreeMap(new ExtensionComparator()); |
532 |
|
533 |
for (int j = 0; j < exts.length; j++) { |
534 |
if (exts[j].getActive()) {
|
535 |
if (orderedExtensions.containsKey(exts[j])) {
|
536 |
logger.error( |
537 |
Messages.getString("Launcher.Two_extensions_with_the_same_priority") +
|
538 |
exts[j].getClassName()); |
539 |
} |
540 |
|
541 |
orderedExtensions.put(exts[j], null);
|
542 |
} |
543 |
} |
544 |
|
545 |
Iterator e = orderedExtensions.keySet().iterator();
|
546 |
|
547 |
// Se instalan las extensiones
|
548 |
while (e.hasNext()) {
|
549 |
Extension ext = (Extension) e.next(); |
550 |
|
551 |
ToolBar[] toolbars = ext.getToolBar();
|
552 |
|
553 |
for (int k = 0; k < toolbars.length; k++) { |
554 |
ActionTool[] tools = toolbars[k].getActionTool();
|
555 |
|
556 |
for (int t = 0; t < tools.length; t++) { |
557 |
frame.addTool(ps.getClassLoader(), ext, |
558 |
toolbars[k], tools[t]); |
559 |
} |
560 |
|
561 |
SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
562 |
|
563 |
for (int t = 0; t < sTools.length; t++) { |
564 |
frame.addTool(ps.getClassLoader(), ext, |
565 |
toolbars[k], sTools[t]); |
566 |
} |
567 |
} |
568 |
|
569 |
/*
|
570 |
Menu[] menu = ext.getMenu();
|
571 |
for (int k = 0; k < menu.length; k++) {
|
572 |
frame.addMenu(ps.getClassLoader(), ext, menu[k]);
|
573 |
}
|
574 |
*/
|
575 |
} |
576 |
|
577 |
// Se instalan las extensiones de MDI
|
578 |
SkinExtension skinExt = pc.getExtensions().getSkinExtension(); |
579 |
|
580 |
if (skinExt != null) { |
581 |
ToolBar[] toolbars = skinExt.getToolBar();
|
582 |
|
583 |
for (int k = 0; k < toolbars.length; k++) { |
584 |
ActionTool[] tools = toolbars[k].getActionTool();
|
585 |
|
586 |
for (int t = 0; t < tools.length; t++) { |
587 |
frame.addTool(ps.getClassLoader(), skinExt, |
588 |
toolbars[k], tools[t]); |
589 |
} |
590 |
|
591 |
SelectableTool[] sTools = toolbars[k].getSelectableTool();
|
592 |
|
593 |
for (int t = 0; t < sTools.length; t++) { |
594 |
frame.addTool(ps.getClassLoader(), skinExt, |
595 |
toolbars[k], sTools[t]); |
596 |
} |
597 |
} |
598 |
|
599 |
/*
|
600 |
Menu[] menu = skinExt.getMenu();
|
601 |
for (int k = 0; k < menu.length; k++) {
|
602 |
frame.addMenu(ps.getClassLoader(), skinExt, menu[k]);
|
603 |
}
|
604 |
*/
|
605 |
} |
606 |
|
607 |
//Se instalan los popup menus
|
608 |
PopupMenus pus = pc.getPopupMenus(); |
609 |
|
610 |
if (pus != null) { |
611 |
PopupMenu[] menus = pus.getPopupMenu(); |
612 |
|
613 |
for (int j = 0; j < menus.length; j++) { |
614 |
frame.addPopupMenu(ps.getClassLoader(), menus[j]); |
615 |
} |
616 |
} |
617 |
} catch (ClassNotFoundException e) { |
618 |
logger.error(Messages.getString("Launcher.No_se_encontro_la_clase_de_la_extension"), e);
|
619 |
} |
620 |
} |
621 |
} |
622 |
|
623 |
/**
|
624 |
*
|
625 |
*/
|
626 |
private static void updateAndamiConfig() { |
627 |
HashSet olds = new HashSet(); |
628 |
|
629 |
Plugin[] plugins = andamiConfig.getPlugin();
|
630 |
|
631 |
for (int i = 0; i < plugins.length; i++) { |
632 |
olds.add(plugins[i].getName()); |
633 |
} |
634 |
|
635 |
Iterator i = pluginsServices.values().iterator();
|
636 |
|
637 |
while (i.hasNext()) {
|
638 |
PluginServices ps = (PluginServices) i.next(); |
639 |
|
640 |
if (!olds.contains(ps.getPluginName())) {
|
641 |
Plugin p = new Plugin();
|
642 |
p.setName(ps.getPluginName()); |
643 |
p.setUpdate(false);
|
644 |
|
645 |
andamiConfig.addPlugin(p); |
646 |
} |
647 |
} |
648 |
} |
649 |
|
650 |
/**
|
651 |
* DOCUMENT ME!
|
652 |
*/
|
653 |
private static void pluginsClassLoaders() { |
654 |
HashSet instalados = new HashSet(); |
655 |
|
656 |
// Se itera hasta que est?n todos instalados
|
657 |
while (instalados.size() != pluginsConfig.size()) {
|
658 |
boolean circle = true; |
659 |
|
660 |
//Hacemos una pasada por todos los plugins
|
661 |
Iterator i = pluginsConfig.keySet().iterator();
|
662 |
|
663 |
while (i.hasNext()) {
|
664 |
String pluginName = (String) i.next(); |
665 |
PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName); |
666 |
|
667 |
if (instalados.contains(pluginName)) {
|
668 |
continue;
|
669 |
} |
670 |
|
671 |
//Se obtienen las dependencias y sus class loaders
|
672 |
boolean ready = true; |
673 |
Depends[] dependencies = config.getDepends();
|
674 |
PluginClassLoader[] loaders = new PluginClassLoader[dependencies.length]; |
675 |
|
676 |
for (int j = 0; j < dependencies.length; j++) { |
677 |
if (pluginsConfig.get(dependencies[j].getPluginName()) == null) { |
678 |
logger.error(Messages.getString("Launcher.Dependencia_no_resuelta_en_plugin") +
|
679 |
pluginName + ": " +
|
680 |
dependencies[j].getPluginName()); |
681 |
|
682 |
continue;
|
683 |
} |
684 |
|
685 |
if (!instalados.contains(dependencies[j].getPluginName())) {
|
686 |
ready = false;
|
687 |
} else {
|
688 |
loaders[j] = ((PluginServices) pluginsServices.get(dependencies[j].getPluginName())).getClassLoader(); |
689 |
} |
690 |
} |
691 |
|
692 |
//Si no est?n sus dependencias satisfechas se aborta la instalaci?n
|
693 |
if (!ready) {
|
694 |
continue;
|
695 |
} |
696 |
|
697 |
//Se genera el class loader
|
698 |
String jardir = config.getLibraries().getLibraryDir();
|
699 |
File jarDir = new File(andamiConfig.getPluginsDirectory() + |
700 |
File.separator + pluginName + File.separator + jardir); |
701 |
File[] jarFiles = jarDir.listFiles(new FileFilter() { |
702 |
public boolean accept(File pathname) { |
703 |
return (pathname.getName().toUpperCase().endsWith(".JAR")) || |
704 |
(pathname.getName().toUpperCase().endsWith(".ZIP"));
|
705 |
} |
706 |
}); |
707 |
|
708 |
URL[] urls = new URL[jarFiles.length]; |
709 |
for (int j = 0; j < jarFiles.length; j++) { |
710 |
try {
|
711 |
urls[j] = new URL("file:" + jarFiles[j]); |
712 |
} catch (MalformedURLException e) { |
713 |
logger.error(Messages.getString("Launcher.No_se_puede_acceder_a") +
|
714 |
jarFiles[j]); |
715 |
} |
716 |
} |
717 |
|
718 |
PluginClassLoader loader; |
719 |
|
720 |
try {
|
721 |
loader = new PluginClassLoader(urls,
|
722 |
andamiConfig.getPluginsDirectory() + |
723 |
File.separator + pluginName,
|
724 |
Launcher.class.getClassLoader(), loaders); |
725 |
|
726 |
PluginServices ps = new PluginServices(loader);
|
727 |
|
728 |
pluginsServices.put(ps.getPluginName(), ps); |
729 |
|
730 |
instalados.add(pluginName); |
731 |
|
732 |
circle = false;
|
733 |
} catch (IOException e) { |
734 |
logger.error(Messages.getString("Launcher.Error_con_las_librerias_del_plugin"), e);
|
735 |
pluginsConfig.remove(pluginName); |
736 |
i = pluginsConfig.keySet().iterator(); |
737 |
} |
738 |
} |
739 |
|
740 |
if (circle) {
|
741 |
logger.error(Messages.getString("Launcher.Hay_dependencias_circulares"));
|
742 |
|
743 |
break;
|
744 |
} |
745 |
} |
746 |
|
747 |
//Se eliminan los plugins que no fueron instalados
|
748 |
Iterator i = pluginsConfig.keySet().iterator();
|
749 |
|
750 |
while (i.hasNext()) {
|
751 |
String pluginName = (String) i.next(); |
752 |
PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName); |
753 |
PluginServices ps = (PluginServices) pluginsServices.get(pluginName); |
754 |
|
755 |
if (ps == null) { |
756 |
pluginsConfig.remove(pluginName); |
757 |
i = pluginsConfig.keySet().iterator(); |
758 |
} |
759 |
} |
760 |
} |
761 |
|
762 |
/**
|
763 |
* DOCUMENT ME!
|
764 |
*/
|
765 |
private static void pluginsMessages() { |
766 |
//Iteramos por todos los plugins
|
767 |
Iterator i = pluginsConfig.keySet().iterator();
|
768 |
|
769 |
while (i.hasNext()) {
|
770 |
String pluginName = (String) i.next(); |
771 |
PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName); |
772 |
|
773 |
PluginServices ps = (PluginServices) pluginsServices.get(pluginName); |
774 |
|
775 |
if (config.getResourceBundle() != null) { |
776 |
ps.setResourceBundle(config.getResourceBundle().getName(), |
777 |
locale); |
778 |
} |
779 |
} |
780 |
} |
781 |
|
782 |
/**
|
783 |
* DOCUMENT ME!
|
784 |
*
|
785 |
* @param name DOCUMENT ME!
|
786 |
*
|
787 |
* @return DOCUMENT ME!
|
788 |
*/
|
789 |
static PluginServices getPluginServices(String name) { |
790 |
return (PluginServices) pluginsServices.get(name);
|
791 |
} |
792 |
|
793 |
/**
|
794 |
* DOCUMENT ME!
|
795 |
*
|
796 |
* @return DOCUMENT ME!
|
797 |
*/
|
798 |
static String getPluginsDir() { |
799 |
return andamiConfig.getPluginsDirectory();
|
800 |
} |
801 |
|
802 |
/**
|
803 |
* DOCUMENT ME!
|
804 |
*
|
805 |
* @param s DOCUMENT ME!
|
806 |
*/
|
807 |
static void setPluginsDir(String s) { |
808 |
andamiConfig.setPluginsDirectory(s); |
809 |
} |
810 |
|
811 |
/**
|
812 |
* DOCUMENT ME!
|
813 |
*
|
814 |
* @return DOCUMENT ME!
|
815 |
*/
|
816 |
static MDIFrame getMDIFrame() {
|
817 |
return frame;
|
818 |
} |
819 |
|
820 |
/**
|
821 |
* DOCUMENT ME!
|
822 |
*
|
823 |
* @param pluginsDirectory
|
824 |
*/
|
825 |
private static void loadPlugins(String pluginsDirectory) { |
826 |
File pDir = new File(pluginsDirectory); |
827 |
|
828 |
if (!pDir.exists()) {
|
829 |
return;
|
830 |
} |
831 |
|
832 |
File[] pluginDirs = pDir.listFiles(); |
833 |
|
834 |
for (int i = 0; i < pluginDirs.length; i++) { |
835 |
if (pluginDirs[i].isDirectory()) {
|
836 |
File configXml = new File(pluginDirs[i].getAbsolutePath() + |
837 |
File.separator + "config.xml"); |
838 |
|
839 |
try {
|
840 |
FileReader xml = new FileReader(configXml); |
841 |
PluginConfig pConfig = (PluginConfig) PluginConfig.unmarshal(xml); |
842 |
pluginsConfig.put(pluginDirs[i].getName(), pConfig); |
843 |
} catch (FileNotFoundException e) { |
844 |
logger.info(Messages.getString("Launcher.Ignorando_el_directorio") +
|
845 |
pluginDirs[i].getAbsolutePath() + |
846 |
Messages.getString("Launcher.config_no_encontrado"));
|
847 |
} catch (MarshalException e) { |
848 |
logger.info(Messages.getString("Launcher.Ignorando_el_directorio") +
|
849 |
pluginDirs[i].getAbsolutePath() + |
850 |
Messages.getString("Launcher.config_mal_formado"), e);
|
851 |
} catch (ValidationException e) {
|
852 |
logger.info(Messages.getString("Launcher.Ignorando_el_directorio") +
|
853 |
pluginDirs[i].getAbsolutePath() + |
854 |
Messages.getString("Launcher.config_mal_formado"), e);
|
855 |
} |
856 |
} |
857 |
} |
858 |
} |
859 |
|
860 |
/**
|
861 |
* DOCUMENT ME!
|
862 |
*
|
863 |
* @param language
|
864 |
* @param country
|
865 |
* @param variant
|
866 |
*
|
867 |
* @return DOCUMENT ME!
|
868 |
*/
|
869 |
private static Locale getLocale(String language, String country, |
870 |
String variant) {
|
871 |
if (variant != null) { |
872 |
return new Locale(language, country, variant); |
873 |
} else if (country != null) { |
874 |
return new Locale(language, country); |
875 |
} else if (language != null) { |
876 |
return new Locale(language); |
877 |
} else {
|
878 |
return new Locale("es"); |
879 |
} |
880 |
} |
881 |
|
882 |
/**
|
883 |
* DOCUMENT ME!
|
884 |
*
|
885 |
* @param file DOCUMENT ME!
|
886 |
*
|
887 |
* @throws IOException DOCUMENT ME!
|
888 |
* @throws MarshalException DOCUMENT ME!
|
889 |
* @throws ValidationException DOCUMENT ME!
|
890 |
*/
|
891 |
private static void andamiConfigToXML(String file) |
892 |
throws IOException, MarshalException, ValidationException { |
893 |
File xml = new File(file); |
894 |
File parent = xml.getParentFile();
|
895 |
parent.mkdirs(); |
896 |
|
897 |
FileWriter writer = new FileWriter(xml); |
898 |
andamiConfig.marshal(writer); |
899 |
} |
900 |
|
901 |
/**
|
902 |
* DOCUMENT ME!
|
903 |
*
|
904 |
* @param file DOCUMENT ME!
|
905 |
*
|
906 |
* @throws ConfigurationException DOCUMENT ME!
|
907 |
*/
|
908 |
private static void andamiConfigFromXML(String file) |
909 |
throws ConfigurationException { |
910 |
File xml = new File(file); |
911 |
|
912 |
//Si no existe se ponen los valores por defecto
|
913 |
if (!xml.exists()) {
|
914 |
andamiConfig = new AndamiConfig();
|
915 |
|
916 |
Andami andami = new Andami();
|
917 |
andami.setUpdate(true);
|
918 |
andamiConfig.setAndami(andami); |
919 |
andamiConfig.setLocaleCountry(Locale.getDefault().getCountry());
|
920 |
andamiConfig.setLocaleLanguage(Locale.getDefault().getLanguage());
|
921 |
andamiConfig.setLocaleVariant(Locale.getDefault().getVariant());
|
922 |
|
923 |
if (System.getProperty("javawebstart.version") != null) // Es java web start) |
924 |
{ |
925 |
andamiConfig.setPluginsDirectory(new File(System.getProperty( |
926 |
"user.home") + File.separator + appName + |
927 |
File.separator + "extensiones").getAbsolutePath()); |
928 |
} else {
|
929 |
andamiConfig.setPluginsDirectory(new File(appName + |
930 |
File.separator + "extensiones").getAbsolutePath()); |
931 |
} |
932 |
|
933 |
andamiConfig.setPlugin(new Plugin[0]); |
934 |
} else {
|
935 |
//Se lee la configuraci?n
|
936 |
FileReader reader;
|
937 |
|
938 |
try {
|
939 |
reader = new FileReader(xml); |
940 |
andamiConfig = (AndamiConfig) AndamiConfig.unmarshal(reader); |
941 |
} catch (FileNotFoundException e) { |
942 |
throw new ConfigurationException(e); |
943 |
} catch (MarshalException e) { |
944 |
throw new ConfigurationException(e); |
945 |
} catch (ValidationException e) {
|
946 |
throw new ConfigurationException(e); |
947 |
} |
948 |
} |
949 |
} |
950 |
|
951 |
/**
|
952 |
* DOCUMENT ME!
|
953 |
*
|
954 |
* @return DOCUMENT ME!
|
955 |
*
|
956 |
* @throws ConfigurationException DOCUMENT ME!
|
957 |
*/
|
958 |
private static XMLEntity persistenceFromXML() throws ConfigurationException { |
959 |
File xml = new File(pluginsPersistencePath); |
960 |
|
961 |
if (xml.exists()) {
|
962 |
FileReader reader;
|
963 |
|
964 |
try {
|
965 |
reader = new FileReader(xml); |
966 |
|
967 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
968 |
|
969 |
return new XMLEntity(tag); |
970 |
} catch (FileNotFoundException e) { |
971 |
throw new ConfigurationException(e); |
972 |
} catch (MarshalException e) { |
973 |
throw new ConfigurationException(e); |
974 |
} catch (ValidationException e) {
|
975 |
throw new ConfigurationException(e); |
976 |
} |
977 |
} else {
|
978 |
return new XMLEntity(); |
979 |
} |
980 |
} |
981 |
|
982 |
/**
|
983 |
* DOCUMENT ME!
|
984 |
*
|
985 |
* @param entity DOCUMENT ME!
|
986 |
*
|
987 |
* @throws ConfigurationException DOCUMENT ME!
|
988 |
*/
|
989 |
private static void persistenceToXML(XMLEntity entity) |
990 |
throws ConfigurationException { |
991 |
File xml = new File(pluginsPersistencePath); |
992 |
|
993 |
FileWriter writer;
|
994 |
|
995 |
try {
|
996 |
writer = new FileWriter(xml); |
997 |
entity.getXmlTag().marshal(writer); |
998 |
} catch (FileNotFoundException e) { |
999 |
throw new ConfigurationException(e); |
1000 |
} catch (MarshalException e) { |
1001 |
throw new ConfigurationException(e); |
1002 |
} catch (ValidationException e) {
|
1003 |
throw new ConfigurationException(e); |
1004 |
} catch (IOException e) { |
1005 |
throw new ConfigurationException(e); |
1006 |
} |
1007 |
} |
1008 |
|
1009 |
/**
|
1010 |
* Devuelve un array con los directorios de los plugins
|
1011 |
*
|
1012 |
* @param dirExt Directorio de las extensiones a partir del cual cuelgan
|
1013 |
* todos los directorios de los plugins
|
1014 |
*
|
1015 |
* @return ArrayList con los directorios
|
1016 |
*/
|
1017 |
private String[] getLocales(File dirExt) { |
1018 |
ArrayList types = new ArrayList(); |
1019 |
File[] files = dirExt.listFiles(); |
1020 |
|
1021 |
for (int i = 0; i < files.length; i++) { |
1022 |
if (files[i].isDirectory()) {
|
1023 |
File[] textFile = files[i].listFiles(new FilenameFilter() { |
1024 |
public boolean accept(File dir, String fileName) { |
1025 |
return fileName.toLowerCase().startsWith("text_"); //$NON-NLS-1$ |
1026 |
} |
1027 |
}); |
1028 |
|
1029 |
for (int j = 0; j < textFile.length; j++) { |
1030 |
String s = (textFile[j]).getName().replaceAll("text_", ""); |
1031 |
s = s.replaceAll(".properties", ""); |
1032 |
s = s.trim(); |
1033 |
|
1034 |
if (!types.contains(s)) {
|
1035 |
types.add(s); |
1036 |
} |
1037 |
} |
1038 |
} |
1039 |
} |
1040 |
|
1041 |
return (String[]) types.toArray(new String[0]); |
1042 |
} |
1043 |
|
1044 |
/**
|
1045 |
* DOCUMENT ME!
|
1046 |
*
|
1047 |
* @return Returns the frame.
|
1048 |
*/
|
1049 |
static MDIFrame getFrame() {
|
1050 |
return frame;
|
1051 |
} |
1052 |
|
1053 |
/**
|
1054 |
* Secuencia de cerrado de Andami
|
1055 |
*/
|
1056 |
public static void closeApplication() { |
1057 |
//Configuraci?n de Andami
|
1058 |
try {
|
1059 |
andamiConfigToXML(andamiConfigPath); |
1060 |
} catch (MarshalException e) { |
1061 |
logger.error(Messages.getString("Launcher.No_se_pudo_guardar_la_configuracion_de_andami"), e);
|
1062 |
} catch (ValidationException e) {
|
1063 |
logger.error(Messages.getString("Launcher.No_se_pudo_guardar_la_configuracion_de_andami"), e);
|
1064 |
} catch (IOException e) { |
1065 |
logger.error(Messages.getString("Launcher.No_se_pudo_guardar_la_configuracion_de_andami"), e);
|
1066 |
} |
1067 |
|
1068 |
//Persistencia de los plugins
|
1069 |
Iterator i = pluginsConfig.keySet().iterator();
|
1070 |
|
1071 |
XMLEntity entity = new XMLEntity();
|
1072 |
|
1073 |
while (i.hasNext()) {
|
1074 |
String pName = (String) i.next(); |
1075 |
PluginServices ps = (PluginServices) pluginsServices.get(pName); |
1076 |
XMLEntity ent = ps.getPersistentXML(); |
1077 |
|
1078 |
if (ent != null) { |
1079 |
ent.putProperty("com.iver.andami.pluginName", pName);
|
1080 |
entity.addChild(ent); |
1081 |
} |
1082 |
} |
1083 |
|
1084 |
try {
|
1085 |
persistenceToXML(entity); |
1086 |
} catch (ConfigurationException e1) { |
1087 |
logger.error(Messages.getString("Launcher.Se_produjo_un_error_guardando_la_configuracion_de_los_plugins"),
|
1088 |
e1); |
1089 |
} |
1090 |
|
1091 |
System.exit(0); |
1092 |
} |
1093 |
|
1094 |
/**
|
1095 |
* DOCUMENT ME!
|
1096 |
*
|
1097 |
* @return DOCUMENT ME!
|
1098 |
*/
|
1099 |
static HashMap getClassesExtensions() { |
1100 |
return classesExtensions;
|
1101 |
} |
1102 |
|
1103 |
/**
|
1104 |
* DOCUMENT ME!
|
1105 |
*
|
1106 |
* @param extDir DOCUMENT ME!
|
1107 |
*/
|
1108 |
private static void downloadExtensions(String extDir) { |
1109 |
java.util.Date fechaActual = null;
|
1110 |
|
1111 |
try {
|
1112 |
if (System.getProperty("javawebstart.version") != null) { |
1113 |
//Obtenemos la URL del servidor
|
1114 |
BasicService bs = (BasicService) ServiceManager.lookup( |
1115 |
"javax.jnlp.BasicService");
|
1116 |
URL baseURL = bs.getCodeBase();
|
1117 |
|
1118 |
//Se descargan las extensiones
|
1119 |
SplashWindow.process(5,
|
1120 |
"Descargando las extensiones desde " + baseURL + " a " + |
1121 |
extDir); |
1122 |
|
1123 |
URL url = new URL(baseURL + "extensiones.zip"); |
1124 |
URLConnection connection = url.openConnection();
|
1125 |
|
1126 |
System.out.println(url.toExternalForm() + ":"); |
1127 |
System.out.println(" Content Type: " + |
1128 |
connection.getContentType()); |
1129 |
System.out.println(" Content Length: " + |
1130 |
connection.getContentLength()); |
1131 |
System.out.println(" Last Modified: " + |
1132 |
new Date(connection.getLastModified())); |
1133 |
System.out.println(" Expiration: " + |
1134 |
connection.getExpiration()); |
1135 |
System.out.println(" Content Encoding: " + |
1136 |
connection.getContentEncoding()); |
1137 |
|
1138 |
// Guardamos la fecha del fichero de extensiones que nos hemos bajado, y
|
1139 |
// comprobamos el ?ltimo que se ha bajado. Si no son
|
1140 |
// iguales, nos bajamos el nuevo. Si son iguales, no
|
1141 |
// nos bajamos nada.
|
1142 |
Long miliSecondsInWeb = new Long(connection.getLastModified()); |
1143 |
|
1144 |
// PluginServices ps = PluginServices.getPluginServices("com.iver.core");
|
1145 |
// if (ps.getPersistentXML().getStringProperty("timestamp") != null)
|
1146 |
File destDir = new File(extDir); |
1147 |
|
1148 |
if (!destDir.exists()) {
|
1149 |
// Creamos gvSIG
|
1150 |
destDir.getParentFile().mkdir(); |
1151 |
|
1152 |
if (!destDir.mkdir()) {
|
1153 |
System.err.println("Imposible crear el directorio " + |
1154 |
destDir.getAbsolutePath()); |
1155 |
} |
1156 |
} |
1157 |
|
1158 |
File timeFile = new File(destDir.getParent() + File.separator + |
1159 |
"timeStamp.properties");
|
1160 |
|
1161 |
if (!timeFile.exists()) {
|
1162 |
timeFile.createNewFile(); |
1163 |
} |
1164 |
|
1165 |
FileInputStream inAux = new FileInputStream(timeFile); |
1166 |
Properties prop = new Properties(); |
1167 |
prop.load(inAux); |
1168 |
inAux.close(); |
1169 |
|
1170 |
if (prop.getProperty("timestamp") != null) { |
1171 |
Long lastMiliSeconds = (Long) new Long(prop.getProperty( |
1172 |
"timestamp"));
|
1173 |
|
1174 |
if (lastMiliSeconds.longValue() == miliSecondsInWeb.longValue()) {
|
1175 |
System.out.println("No hay nueva actualizaci?n"); |
1176 |
|
1177 |
return;
|
1178 |
} |
1179 |
|
1180 |
System.out.println("timeStampWeb= " + miliSecondsInWeb); |
1181 |
System.out.println("timeStampLocal= " + lastMiliSeconds); |
1182 |
} else {
|
1183 |
System.out.println("El timeStamp no est? escrito en " + |
1184 |
timeFile.getAbsolutePath()); |
1185 |
} |
1186 |
|
1187 |
InputStream stream = connection.getInputStream();
|
1188 |
File temp = File.createTempFile("gvsig", ".zip"); |
1189 |
temp.deleteOnExit(); |
1190 |
|
1191 |
FileOutputStream file = new FileOutputStream(temp); |
1192 |
BufferedInputStream in = new BufferedInputStream(stream); |
1193 |
BufferedOutputStream out = new BufferedOutputStream(file); |
1194 |
|
1195 |
int i;
|
1196 |
int pct;
|
1197 |
int desde;
|
1198 |
int hasta;
|
1199 |
|
1200 |
hasta = connection.getContentLength() / 1024;
|
1201 |
desde = 0;
|
1202 |
|
1203 |
while ((i = in.read()) != -1) { |
1204 |
pct = ((desde / 1024) * 100) / hasta; |
1205 |
|
1206 |
if (((desde % 10240) == 0) && (pct > 10) && |
1207 |
((pct % 10) == 0)) { |
1208 |
SplashWindow.process(pct, |
1209 |
(desde / 1024) + "Kb de " + hasta + |
1210 |
"Kb descargados...");
|
1211 |
} |
1212 |
|
1213 |
out.write(i); |
1214 |
desde++; |
1215 |
} |
1216 |
|
1217 |
out.flush(); |
1218 |
out.close(); |
1219 |
in.close(); |
1220 |
|
1221 |
//Se extrae el zip
|
1222 |
SplashWindow.process(5, "Extensiones descargadas."); |
1223 |
|
1224 |
System.out.println("Extrayendo a " + destDir.getAbsolutePath()); |
1225 |
|
1226 |
Date fechaDir = new Date(destDir.lastModified()); |
1227 |
System.out.println("Fecha del directorio " + extDir + " = " + |
1228 |
fechaDir.toString()); |
1229 |
Utilities.extractTo(temp, new File(extDir), splashWindow); |
1230 |
|
1231 |
// Si todo ha ido bien, guardamos el timestamp.
|
1232 |
/// App.instance.getPc().addProperties("timestamp", miliSecondsInWeb);
|
1233 |
// XMLEntity xml=ps.getPersistentXML();
|
1234 |
fechaActual = new java.util.Date();
|
1235 |
|
1236 |
FileOutputStream outAux = new FileOutputStream(timeFile); |
1237 |
prop.setProperty("timestamp", miliSecondsInWeb.toString());
|
1238 |
prop.store(outAux, "last download");
|
1239 |
outAux.close(); |
1240 |
System.out.println("Fecha actual guardada: " + |
1241 |
fechaActual.toGMTString()); |
1242 |
|
1243 |
/* xml.putProperty("timestamp",fechaActual.toGMTString());
|
1244 |
ps.setPresistentXML(xml); */
|
1245 |
} |
1246 |
} catch (IOException e) { |
1247 |
NotificationManager.addError("", e);
|
1248 |
} catch (UnavailableServiceException e) {
|
1249 |
NotificationManager.addError("", e);
|
1250 |
} catch (SecurityException e) { |
1251 |
System.err.println("No se puede escribir el timeStamp " + |
1252 |
fechaActual.toGMTString()); |
1253 |
NotificationManager.addError("", e);
|
1254 |
} |
1255 |
} |
1256 |
|
1257 |
/**
|
1258 |
* DOCUMENT ME!
|
1259 |
*
|
1260 |
* @return DOCUMENT ME!
|
1261 |
*/
|
1262 |
private static Extensions[] getExtensions() { |
1263 |
ArrayList array = new ArrayList(); |
1264 |
Iterator iter = pluginsConfig.values().iterator();
|
1265 |
|
1266 |
while (iter.hasNext()) {
|
1267 |
array.add(((PluginConfig) iter.next()).getExtensions()); |
1268 |
} |
1269 |
|
1270 |
return (Extensions[]) array.toArray(new Extensions[0]); |
1271 |
} |
1272 |
|
1273 |
/**
|
1274 |
* DOCUMENT ME!
|
1275 |
*
|
1276 |
* @return DOCUMENT ME!
|
1277 |
*/
|
1278 |
public static HashMap getPluginConfig() { |
1279 |
return pluginsConfig;
|
1280 |
} |
1281 |
|
1282 |
/**
|
1283 |
* DOCUMENT ME!
|
1284 |
*
|
1285 |
* @param s DOCUMENT ME!
|
1286 |
*
|
1287 |
* @return DOCUMENT ME!
|
1288 |
*/
|
1289 |
public static Extension getExtension(String s) { |
1290 |
Extensions[] exts = getExtensions();
|
1291 |
|
1292 |
for (int i = 0; i < exts.length; i++) { |
1293 |
for (int j = 0; j < exts[i].getExtensionCount(); j++) { |
1294 |
if (exts[i].getExtension(j).getClassName().equals(s)) {
|
1295 |
return exts[i].getExtension(j);
|
1296 |
} |
1297 |
} |
1298 |
} |
1299 |
|
1300 |
return null; |
1301 |
} |
1302 |
|
1303 |
/**
|
1304 |
* DOCUMENT ME!
|
1305 |
*
|
1306 |
* @return DOCUMENT ME!
|
1307 |
*/
|
1308 |
public static AndamiConfig getAndamiConfig() { |
1309 |
return andamiConfig;
|
1310 |
} |
1311 |
|
1312 |
/**
|
1313 |
* DOCUMENT ME!
|
1314 |
*
|
1315 |
* @author $author$
|
1316 |
* @version $Revision: 1217 $
|
1317 |
*/
|
1318 |
private static class ExtensionComparator implements Comparator { |
1319 |
/**
|
1320 |
* DOCUMENT ME!
|
1321 |
*
|
1322 |
* @param o1 DOCUMENT ME!
|
1323 |
* @param o2 DOCUMENT ME!
|
1324 |
*
|
1325 |
* @return DOCUMENT ME!
|
1326 |
*/
|
1327 |
public int compare(Object o1, Object o2) { |
1328 |
Extension e1 = (Extension) o1; |
1329 |
Extension e2 = (Extension) o2; |
1330 |
|
1331 |
if (!e1.hasPriority() && !e2.hasPriority()) {
|
1332 |
return -1; |
1333 |
} |
1334 |
|
1335 |
if (e1.hasPriority() && !e2.hasPriority()) {
|
1336 |
return -Integer.MAX_VALUE; |
1337 |
} |
1338 |
|
1339 |
if (e2.hasPriority() && !e1.hasPriority()) {
|
1340 |
return Integer.MAX_VALUE; |
1341 |
} |
1342 |
|
1343 |
return e1.getPriority() - e2.getPriority();
|
1344 |
} |
1345 |
} |
1346 |
|
1347 |
/**
|
1348 |
* DOCUMENT ME!
|
1349 |
*/
|
1350 |
private static class MenuComparator implements Comparator { |
1351 |
private static ExtensionComparator extComp = new ExtensionComparator(); |
1352 |
|
1353 |
/**
|
1354 |
* DOCUMENT ME!
|
1355 |
*
|
1356 |
* @param o1 DOCUMENT ME!
|
1357 |
* @param o2 DOCUMENT ME!
|
1358 |
*
|
1359 |
* @return DOCUMENT ME!
|
1360 |
*/
|
1361 |
public int compare(Object o1, Object o2) { |
1362 |
SortableMenu e1 = (SortableMenu) o1; |
1363 |
SortableMenu e2 = (SortableMenu) o2; |
1364 |
|
1365 |
if (!e1.menu.hasPosition() && !e2.menu.hasPosition()) {
|
1366 |
if (e1.extension instanceof SkinExtensionType) { |
1367 |
return 1; |
1368 |
} else if (e2.extension instanceof SkinExtensionType) { |
1369 |
return -1; |
1370 |
} else {
|
1371 |
return extComp.compare(e1.extension, e2.extension);
|
1372 |
} |
1373 |
} |
1374 |
|
1375 |
if (e1.menu.hasPosition() && !e2.menu.hasPosition()) {
|
1376 |
return -Integer.MAX_VALUE; |
1377 |
} |
1378 |
|
1379 |
if (e2.menu.hasPosition() && !e1.menu.hasPosition()) {
|
1380 |
return Integer.MAX_VALUE; |
1381 |
} |
1382 |
|
1383 |
return e1.menu.getPosition() - e2.menu.getPosition();
|
1384 |
} |
1385 |
} |
1386 |
|
1387 |
/**
|
1388 |
* DOCUMENT ME!
|
1389 |
*
|
1390 |
* @author $author$
|
1391 |
* @version $Revision: 1217 $
|
1392 |
*/
|
1393 |
private static class SortableMenu { |
1394 |
public PluginClassLoader loader;
|
1395 |
public Menu menu; |
1396 |
public SkinExtensionType extension;
|
1397 |
|
1398 |
/**
|
1399 |
* DOCUMENT ME!
|
1400 |
*
|
1401 |
* @param loader DOCUMENT ME!
|
1402 |
* @param skinExt
|
1403 |
* @param menu2
|
1404 |
*/
|
1405 |
public SortableMenu(PluginClassLoader loader,
|
1406 |
SkinExtensionType skinExt, Menu menu2) {
|
1407 |
extension = skinExt; |
1408 |
menu = menu2; |
1409 |
this.loader = loader;
|
1410 |
} |
1411 |
} |
1412 |
|
1413 |
} |