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