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