Statistics
| Revision:

svn-gvsig-desktop / trunk / frameworks / _fwAndami / src / com / iver / andami / Launcher.java @ 1078

History | View | Annotate | Download (36.6 KB)

1
package com.iver.andami;
2

    
3
import com.iver.andami.config.generate.Andami;
4
import com.iver.andami.config.generate.AndamiConfig;
5
import com.iver.andami.config.generate.Plugin;
6
import com.iver.andami.messages.Messages;
7
import com.iver.andami.messages.NotificationManager;
8
import com.iver.andami.plugins.PluginClassLoader;
9
import com.iver.andami.plugins.config.generate.ActionTool;
10
import com.iver.andami.plugins.config.generate.Depends;
11
import com.iver.andami.plugins.config.generate.Extension;
12
import com.iver.andami.plugins.config.generate.Extensions;
13
import com.iver.andami.plugins.config.generate.LabelSet;
14
import com.iver.andami.plugins.config.generate.Library;
15
import com.iver.andami.plugins.config.generate.Menu;
16
import com.iver.andami.plugins.config.generate.PluginConfig;
17
import com.iver.andami.plugins.config.generate.PopupMenu;
18
import com.iver.andami.plugins.config.generate.PopupMenus;
19
import com.iver.andami.plugins.config.generate.SelectableTool;
20
import com.iver.andami.plugins.config.generate.SkinExtension;
21
import com.iver.andami.plugins.config.generate.SkinExtensionType;
22
import com.iver.andami.plugins.config.generate.ToolBar;
23
import com.iver.andami.ui.MDIManagerLoadException;
24
import com.iver.andami.ui.SplashWindow;
25
import com.iver.andami.ui.WaitCursorEventQueue;
26
import com.iver.andami.ui.mdiFrame.MDIFrame;
27
import com.iver.andami.ui.mdiManager.MDIManagerFactory;
28

    
29
import com.iver.utiles.XMLEntity;
30
import com.iver.utiles.xmlEntity.generate.XmlTag;
31

    
32
import org.apache.log4j.FileAppender;
33
import org.apache.log4j.Layout;
34
import org.apache.log4j.Logger;
35
import org.apache.log4j.PatternLayout;
36
import org.apache.log4j.PropertyConfigurator;
37
import org.apache.log4j.RollingFileAppender;
38

    
39
import org.exolab.castor.xml.MarshalException;
40
import org.exolab.castor.xml.ValidationException;
41

    
42
import java.awt.EventQueue;
43
import java.awt.Toolkit;
44

    
45
import java.io.BufferedInputStream;
46
import java.io.BufferedOutputStream;
47
import java.io.File;
48
import java.io.FileInputStream;
49
import java.io.FileNotFoundException;
50
import java.io.FileOutputStream;
51
import java.io.FileReader;
52
import java.io.FileWriter;
53
import java.io.FilenameFilter;
54
import java.io.IOException;
55
import java.io.InputStream;
56

    
57
import java.lang.reflect.InvocationTargetException;
58

    
59
import java.net.MalformedURLException;
60
import java.net.URL;
61
import java.net.URLConnection;
62

    
63
import java.util.ArrayList;
64
import java.util.Comparator;
65
import java.util.Date;
66
import java.util.HashMap;
67
import java.util.HashSet;
68
import java.util.Iterator;
69
import java.util.Locale;
70
import java.util.Properties;
71
import java.util.TreeMap;
72

    
73
import javax.jnlp.BasicService;
74
import javax.jnlp.ServiceManager;
75
import javax.jnlp.UnavailableServiceException;
76

    
77
import javax.swing.ImageIcon;
78
import javax.swing.JComponent;
79
import javax.swing.SwingUtilities;
80
import javax.swing.UIManager;
81

    
82

    
83
/**
84
 * DOCUMENT ME!
85
 *
86
 * @author $author$
87
 * @version $Revision: 1078 $
88
 */
89
public class Launcher {
90
        private static Logger logger = Logger.getLogger(Launcher.class.getName());
91
        private static AndamiConfig andamiConfig;
92
        private static SplashWindow splashWindow;
93
        private static String userHome = System.getProperty("user.home");
94
        private static String appName;
95
        private static Locale locale;
96
        private static HashMap pluginsConfig = new HashMap();
97
        private static HashMap pluginsServices = new HashMap();
98
        private static MDIFrame frame;
99
        private static HashMap classesExtensions = new HashMap();
100
        private static String andamiConfigPath;
101
        private static String pluginsPersistencePath;
102

    
103
        /**
104
         * DOCUMENT ME!
105
         *
106
         * @param args DOCUMENT ME!
107
         *
108
         * @throws InterruptedException
109
         * @throws InvocationTargetException
110
         * @throws ConfigurationException
111
         * @throws MDIManagerLoadException
112
         * @throws IOException
113
         */
114
        public static void main(String[] args)
115
                throws InterruptedException, InvocationTargetException, 
116
                        ConfigurationException, MDIManagerLoadException, IOException {
117
                if ((args.length < 1) || (args.length > 2)) {
118
                        System.err.println("Uso: Launcher appName [locale]");
119
                }
120

    
121
                appName = args[0];
122
                
123
                //Se crea el directorio de configuraci?n de la aplicaci?n
124
                File parent = new File(System.getProperty("user.home") + File.separator + args[0] +
125
                                File.separator);
126
                parent.mkdirs();
127

    
128
                andamiConfigPath = System.getProperty("user.home") + File.separator +
129
                        appName + File.separator + "andami-config.xml";
130
                pluginsPersistencePath = System.getProperty("user.home") +
131
                        File.separator + appName + File.separator +
132
                        "plugins-persistence.xml";
133

    
134
                // Configurar el log4j
135
                PropertyConfigurator.configure(Launcher.class.getClassLoader()
136
                                                                                                         .getResource("log4j.properties"));
137

    
138
                PatternLayout l = new PatternLayout("%p %t %c - %m%n");
139
                RollingFileAppender fa = new RollingFileAppender(l,
140
                                System.getProperty("user.home") + File.separator + args[0] +
141
                                File.separator + args[0] + ".log", true);
142
                fa.setMaxFileSize("512KB");
143
                fa.setMaxBackupIndex(3);
144
                Logger.getRootLogger().addAppender(fa);
145

    
146
                // Leer el fichero de configuraci?n de andami (andami-config.xsd)
147
                // locale
148
                // Buscar actualizaci?nes al comenzar
149
                //  Andami
150
                //  Plugins
151
                // Directorio de las extensiones
152
                andamiConfigFromXML(andamiConfigPath);
153

    
154
                // Configurar el locale
155
                if (args.length == 2) {
156
                        locale = new Locale(args[1]);
157
                } else {
158
                        locale = getLocale(andamiConfig.getLocaleLanguage(),
159
                                        andamiConfig.getLocaleCountry(),
160
                                        andamiConfig.getLocaleVariant());
161
                }
162

    
163
                Locale.setDefault(locale);
164
                JComponent.setDefaultLocale(locale);
165
                Messages.init(locale);
166

    
167
                try {
168
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
169

    
170
                        // UIManager.setLookAndFeel("com.iver.WindowsLookAndFeel.WindowsLookAndFeel");
171
                } catch (Exception e) {
172
                        logger.warn("No se pudo poner el look and feel", e);
173
                }
174

    
175
                // Mostrar la ventana de inicio
176
                splashWindow = new SplashWindow(null);
177

    
178
                // TODO Buscar actualizaciones de Andami
179
                // TODO Buscar actualizaciones de los plugins
180
                downloadExtensions(andamiConfig.getPluginsDirectory());
181

    
182
                // Se leen los config.xml de los plugins -----++++
183
                loadPlugins(andamiConfig.getPluginsDirectory());
184

    
185
                // Se configura el classloader del plugin
186
                pluginsClassLoaders();
187

    
188
                // Se carga un Skin si alguno de los plugins trae informaci?n para ello
189
                skinPlugin();
190

    
191
                //Se configura la cola de eventos
192
                EventQueue waitQueue = new WaitCursorEventQueue(MDIManagerFactory.createManager(),
193
                                100);
194
                Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);
195

    
196
                // Se configura la mensajer?a del plugin
197
                pluginsMessages();
198

    
199
                // Se modifica el andami-config con los plugins nuevos
200
                updateAndamiConfig();
201

    
202
                // Se prepara el MainFrame para albergar las extensiones
203
                frame = new MDIFrame();
204

    
205
                // Se configura el nombre e icono de la aplicaci?n
206
                frameIcon();
207

    
208
                SwingUtilities.invokeAndWait(new Runnable() {
209
                                public void run() {
210
                                        frame.init();
211
                                }
212
                        });
213

    
214
                // Se instalan los controles de las extensiones de los plugins
215
                SwingUtilities.invokeAndWait(new Runnable() {
216
                                public void run() {
217
                                        installPluginsControls();
218
                                        installPluginsMenus();
219
                                        installPluginsLabels();
220
                                }
221
                        });
222

    
223
                // Leer el fichero de persistencia
224
                //  info de los plugins
225
                //  bookmarks de los plugins
226
                loadPluginsPersistence();
227

    
228
                // Se instalan los controles del skin
229
                // Se inicializan todas las extensiones de todos los plugins
230
                SwingUtilities.invokeAndWait(new Runnable() {
231
                                public void run() {
232
                                        initializeExtensions();
233
                                }
234
                        });
235
                frame.setClassesExtensions(classesExtensions);
236

    
237
                // Se instalan los bookmarks de los plugins
238
                splashWindow.close();
239

    
240
                //Se muestra el frame principal
241
                frame.show();
242

    
243
                SwingUtilities.invokeAndWait(new Runnable() {
244
                                public void run() {
245
                                        frame.enableControls();
246
                                }
247
                        });
248
        }
249

    
250
        /**
251
         * DOCUMENT ME!
252
         *
253
         * @throws ConfigurationException
254
         */
255
        private static void loadPluginsPersistence() throws ConfigurationException {
256
                XMLEntity entity = persistenceFromXML();
257

    
258
                for (int i = 0; i < entity.getNumChild(); i++) {
259
                        XMLEntity plugin = entity.getChild(i);
260
                        String pName = plugin.getStringProperty(
261
                                        "com.iver.andami.pluginName");
262
                        ((PluginServices) pluginsServices.get(pName)).setPresistentXML(plugin);
263
                }
264
        }
265

    
266
        /**
267
         * DOCUMENT ME!
268
         */
269
        private static void installPluginsLabels() {
270
                Iterator i = pluginsConfig.keySet().iterator();
271

    
272
                while (i.hasNext()) {
273
                        String name = (String) i.next();
274
                        PluginConfig pc = (PluginConfig) pluginsConfig.get(name);
275
                        PluginServices ps = (PluginServices) pluginsServices.get(name);
276

    
277
                        LabelSet[] ls = pc.getLabelSet();
278

    
279
                        for (int j = 0; j < ls.length; j++) {
280
                                PluginClassLoader loader = ps.getClassLoader();
281

    
282
                                try {
283
                                        Class clase = loader.loadClass(ls[j].getClassName());
284
                                        frame.setLabels(clase, ls[j].getLabel());
285
                                } catch (ClassNotFoundException e) {
286
                                        logger.error("No se pudo encontrar la clase de la labelset",
287
                                                e);
288
                                }
289
                        }
290
                }
291
        }
292

    
293
        /**
294
         * DOCUMENT ME!
295
         *
296
         * @throws MDIManagerLoadException
297
         */
298
        private static void skinPlugin() throws MDIManagerLoadException {
299
                Iterator i = pluginsConfig.keySet().iterator();
300

    
301
                while (i.hasNext()) {
302
                        String name = (String) i.next();
303
                        PluginConfig pc = (PluginConfig) pluginsConfig.get(name);
304
                        PluginServices ps = (PluginServices) pluginsServices.get(name);
305

    
306
                        if (pc.getExtensions().getSkinExtension() != null) {
307
                                if (MDIManagerFactory.getSkinExtension() != null) {
308
                                        logger.error("Dos skin-extension. Usamos el ?ltimo");
309
                                }
310

    
311
                                SkinExtension se = pc.getExtensions().getSkinExtension();
312

    
313
                                MDIManagerFactory.setSkinExtension(se, ps.getClassLoader());
314

    
315
                                Class skinClass;
316

    
317
                                try {
318
                                        skinClass = ps.getClassLoader().loadClass(se.getClassName());
319

    
320
                                        com.iver.andami.plugins.Extension skinInstance = (com.iver.andami.plugins.Extension) skinClass.newInstance();
321
                                        classesExtensions.put(skinClass, skinInstance);
322
                                } catch (ClassNotFoundException e) {
323
                                        logger.error("No se pudo instanciar la clase mdi manager", e);
324
                                        throw new MDIManagerLoadException(e);
325
                                } catch (InstantiationException e) {
326
                                        logger.error("No se pudo instanciar la clase mdi manager", e);
327
                                        throw new MDIManagerLoadException(e);
328
                                } catch (IllegalAccessException e) {
329
                                        logger.error("No se pudo instanciar la clase mdi manager", e);
330
                                        throw new MDIManagerLoadException(e);
331
                                }
332
                        }
333
                }
334
        }
335

    
336
        /**
337
         *
338
         */
339
        private static void frameIcon() {
340
                Iterator i = pluginsConfig.keySet().iterator();
341

    
342
                while (i.hasNext()) {
343
                        String pName = (String) i.next();
344
                        PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
345
                        PluginServices ps = (PluginServices) pluginsServices.get(pName);
346

    
347
                        if (pc.getIcon() != null) {
348
                                ImageIcon icon = new ImageIcon(ps.getClassLoader().getResource(pc.getIcon()
349
                                                                                                                                                                 .getSrc()));
350
                                frame.setIconImage(icon.getImage());
351
                                frame.setTitle(pc.getIcon().getText());
352
                        }
353
                }
354
        }
355

    
356
        /**
357
         *
358
         */
359
        private static void initializeExtensions() {
360
                Iterator i = pluginsConfig.keySet().iterator();
361

    
362
                while (i.hasNext()) {
363
                        String pName = (String) i.next();
364
                        PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
365
                        PluginServices ps = (PluginServices) pluginsServices.get(pName);
366

    
367
                        Extension[] exts = pc.getExtensions().getExtension();
368

    
369
                        TreeMap orderedExtensions = new TreeMap(new ExtensionComparator());
370

    
371
                        for (int j = 0; j < exts.length; j++) {
372
                                if (!exts[j].getActive()) {
373
                                        continue;
374
                                }
375

    
376
                                if (orderedExtensions.containsKey(exts[j])) {
377
                                        logger.error(
378
                                                "Two extensions with the same priority. Only will load one. " +
379
                                                exts[j].getClassName());
380
                                }
381

    
382
                                orderedExtensions.put(exts[j], null);
383
                        }
384

    
385
                        Iterator e = orderedExtensions.keySet().iterator();
386

    
387
                        while (e.hasNext()) {
388
                                Extension extension = (Extension) e.next();
389
                                com.iver.andami.plugins.Extension extensionInstance;
390

    
391
                                try {
392
                                        Class extensionClass = ps.getClassLoader().loadClass(extension.getClassName());
393
                                        extensionInstance = (com.iver.andami.plugins.Extension) extensionClass.newInstance();
394
                                        classesExtensions.put(extensionClass, extensionInstance);
395

    
396
                                        extensionInstance.inicializar();
397
                                } catch (InstantiationException e1) {
398
                                        logger.error("Error instanciando la extension " +
399
                                                extension.getClassName(), e1);
400
                                } catch (IllegalAccessException e1) {
401
                                        logger.error("Error instanciando la extension " +
402
                                                extension.getClassName(), e1);
403
                                } catch (ClassNotFoundException e1) {
404
                                        logger.error("Error instanciando la extension " +
405
                                                extension.getClassName(), e1);
406
                                } catch (NoClassDefFoundError e1) {
407
                                        logger.error("Error localizando la clase de la extension " +
408
                                                extension.getClassName(), e1);
409
                                }
410
                        }
411
                }
412
        }
413

    
414
        /**
415
         * DOCUMENT ME!
416
         */
417
        private static void installPluginsMenus() {
418
                TreeMap orderedMenus = new TreeMap(new MenuComparator());
419

    
420
                Iterator i = pluginsConfig.keySet().iterator();
421

    
422
                while (i.hasNext()) {
423
                        String pName = (String) i.next();
424
                        PluginServices ps = (PluginServices) pluginsServices.get(pName);
425
                        PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
426

    
427
                        Extension[] exts = pc.getExtensions().getExtension();
428

    
429
                        for (int j = 0; j < exts.length; j++) {
430
                                if (!exts[j].getActive()) {
431
                                        continue;
432
                                }
433

    
434
                                Menu[] menu = exts[j].getMenu();
435

    
436
                                for (int k = 0; k < menu.length; k++) {
437
                                        SortableMenu sm = new SortableMenu(ps.getClassLoader(),
438
                                                        exts[j], menu[k]);
439

    
440
                                        if (orderedMenus.containsKey(sm)) {
441
                                                logger.error(
442
                                                        "Two menus with the same position. Only will load one. " +
443
                                                        exts[j].getClassName());
444
                                        }
445

    
446
                                        orderedMenus.put(sm, null);
447
                                }
448
                        }
449

    
450
                        // Se instalan las extensiones de MDI
451
                        SkinExtension skinExt = pc.getExtensions().getSkinExtension();
452

    
453
                        if (skinExt != null) {
454
                                Menu[] menu = skinExt.getMenu();
455

    
456
                                for (int k = 0; k < menu.length; k++) {
457
                                        SortableMenu sm = new SortableMenu(ps.getClassLoader(),
458
                                                        skinExt, menu[k]);
459

    
460
                                        if (orderedMenus.containsKey(sm)) {
461
                                                logger.error(
462
                                                        "Two menus with the same position. Only will load one. " +
463
                                                        skinExt.getClassName());
464
                                        }
465

    
466
                                        orderedMenus.put(sm, null);
467
                                }
468
                        }
469
                }
470

    
471
                //Se itera por los menus ordenados
472
                Iterator e = orderedMenus.keySet().iterator();
473

    
474
                // Se ordenan los menues
475
                while (e.hasNext()) {
476
                        try {
477
                                SortableMenu sm = (SortableMenu) e.next();
478

    
479
                                frame.addMenu(sm.loader, sm.extension, sm.menu);
480
                        } catch (ClassNotFoundException ex) {
481
                                logger.error("No se pudo encontrar la clase de la extension", ex);
482
                        }
483
                }
484
        }
485

    
486
        /**
487
         *
488
         */
489
        private static void installPluginsControls() {
490
                Iterator i = pluginsConfig.keySet().iterator();
491

    
492
                while (i.hasNext()) {
493
                        try {
494
                                String pName = (String) i.next();
495
                                PluginConfig pc = (PluginConfig) pluginsConfig.get(pName);
496
                                PluginServices ps = (PluginServices) pluginsServices.get(pName);
497

    
498
                                Extension[] exts = pc.getExtensions().getExtension();
499

    
500
                                TreeMap orderedExtensions = new TreeMap(new ExtensionComparator());
501

    
502
                                for (int j = 0; j < exts.length; j++) {
503
                                        if (exts[j].getActive()) {
504
                                                if (orderedExtensions.containsKey(exts[j])) {
505
                                                        logger.error(
506
                                                                "Two extensions with the same priority. Only will load one. " +
507
                                                                exts[j].getClassName());
508
                                                }
509

    
510
                                                orderedExtensions.put(exts[j], null);
511
                                        }
512
                                }
513

    
514
                                Iterator e = orderedExtensions.keySet().iterator();
515

    
516
                                // Se instalan las extensiones
517
                                while (e.hasNext()) {
518
                                        Extension ext = (Extension) e.next();
519

    
520
                                        ToolBar[] toolbars = ext.getToolBar();
521

    
522
                                        for (int k = 0; k < toolbars.length; k++) {
523
                                                ActionTool[] tools = toolbars[k].getActionTool();
524

    
525
                                                for (int t = 0; t < tools.length; t++) {
526
                                                        frame.addTool(ps.getClassLoader(), ext,
527
                                                                toolbars[k], tools[t]);
528
                                                }
529

    
530
                                                SelectableTool[] sTools = toolbars[k].getSelectableTool();
531

    
532
                                                for (int t = 0; t < sTools.length; t++) {
533
                                                        frame.addTool(ps.getClassLoader(), ext,
534
                                                                toolbars[k], sTools[t]);
535
                                                }
536
                                        }
537

    
538
                                        /*
539
                                           Menu[] menu = ext.getMenu();
540
                                           for (int k = 0; k < menu.length; k++) {
541
                                               frame.addMenu(ps.getClassLoader(), ext, menu[k]);
542
                                           }
543
                                         */
544
                                }
545

    
546
                                // Se instalan las extensiones de MDI
547
                                SkinExtension skinExt = pc.getExtensions().getSkinExtension();
548

    
549
                                if (skinExt != null) {
550
                                        ToolBar[] toolbars = skinExt.getToolBar();
551

    
552
                                        for (int k = 0; k < toolbars.length; k++) {
553
                                                ActionTool[] tools = toolbars[k].getActionTool();
554

    
555
                                                for (int t = 0; t < tools.length; t++) {
556
                                                        frame.addTool(ps.getClassLoader(), skinExt,
557
                                                                toolbars[k], tools[t]);
558
                                                }
559

    
560
                                                SelectableTool[] sTools = toolbars[k].getSelectableTool();
561

    
562
                                                for (int t = 0; t < sTools.length; t++) {
563
                                                        frame.addTool(ps.getClassLoader(), skinExt,
564
                                                                toolbars[k], sTools[t]);
565
                                                }
566
                                        }
567

    
568
                                        /*
569
                                           Menu[] menu = skinExt.getMenu();
570
                                           for (int k = 0; k < menu.length; k++) {
571
                                               frame.addMenu(ps.getClassLoader(), skinExt, menu[k]);
572
                                           }
573
                                         */
574
                                }
575

    
576
                                //Se instalan los popup menus
577
                                PopupMenus pus = pc.getPopupMenus();
578

    
579
                                if (pus != null) {
580
                                        PopupMenu[] menus = pus.getPopupMenu();
581

    
582
                                        for (int j = 0; j < menus.length; j++) {
583
                                                frame.addPopupMenu(ps.getClassLoader(), menus[j]);
584
                                        }
585
                                }
586
                        } catch (ClassNotFoundException e) {
587
                                logger.error("No se pudo encontrar la clase de la extension", e);
588
                        }
589
                }
590
        }
591

    
592
        /**
593
         *
594
         */
595
        private static void updateAndamiConfig() {
596
                HashSet olds = new HashSet();
597

    
598
                Plugin[] plugins = andamiConfig.getPlugin();
599

    
600
                for (int i = 0; i < plugins.length; i++) {
601
                        olds.add(plugins[i].getName());
602
                }
603

    
604
                Iterator i = pluginsServices.values().iterator();
605

    
606
                while (i.hasNext()) {
607
                        PluginServices ps = (PluginServices) i.next();
608

    
609
                        if (!olds.contains(ps.getPluginName())) {
610
                                Plugin p = new Plugin();
611
                                p.setName(ps.getPluginName());
612
                                p.setUpdate(false);
613

    
614
                                andamiConfig.addPlugin(p);
615
                        }
616
                }
617
        }
618

    
619
        /**
620
         * DOCUMENT ME!
621
         */
622
        private static void pluginsClassLoaders() {
623
                HashSet instalados = new HashSet();
624

    
625
                // Se itera hasta que est?n todos instalados
626
                while (instalados.size() != pluginsConfig.size()) {
627
                        boolean circle = true;
628

    
629
                        //Hacemos una pasada por todos los plugins
630
                        Iterator i = pluginsConfig.keySet().iterator();
631

    
632
                        while (i.hasNext()) {
633
                                String pluginName = (String) i.next();
634
                                PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName);
635

    
636
                                if (instalados.contains(pluginName)) {
637
                                        continue;
638
                                }
639

    
640
                                //Se obtienen las dependencias y sus class loaders
641
                                boolean ready = true;
642
                                Depends[] dependencies = config.getDepends();
643
                                PluginClassLoader[] loaders = new PluginClassLoader[dependencies.length];
644

    
645
                                for (int j = 0; j < dependencies.length; j++) {
646
                                        if (pluginsConfig.get(dependencies[j].getPluginName()) == null) {
647
                                                logger.error("Dependencia no resuelta en plugin " +
648
                                                        pluginName + ": " +
649
                                                        dependencies[j].getPluginName() +
650
                                                        ". Dependencia ignorada");
651

    
652
                                                continue;
653
                                        }
654

    
655
                                        if (!instalados.contains(dependencies[j].getPluginName())) {
656
                                                ready = false;
657
                                        } else {
658
                                                loaders[j] = ((PluginServices) pluginsServices.get(dependencies[j].getPluginName())).getClassLoader();
659
                                        }
660
                                }
661

    
662
                                //Si no est?n sus dependencias satisfechas se aborta la instalaci?n
663
                                if (!ready) {
664
                                        continue;
665
                                }
666

    
667
                                //Se genera el class loader
668
                                Library[] jars = config.getLibraries().getLibrary();
669
                                URL[] urls = new URL[jars.length];
670

    
671
                                for (int j = 0; j < jars.length; j++) {
672
                                        try {
673
                                                urls[j] = new URL("file:" +
674
                                                                andamiConfig.getPluginsDirectory() +
675
                                                                File.separator + pluginName + File.separator +
676
                                                                jars[j].getFile());
677
                                        } catch (MalformedURLException e) {
678
                                                logger.error("No se puede acceder a " +
679
                                                        jars[j].getFile());
680
                                        }
681
                                }
682

    
683
                                PluginClassLoader loader;
684

    
685
                                try {
686
                                        loader = new PluginClassLoader(urls,
687
                                                        andamiConfig.getPluginsDirectory() +
688
                                                        File.separator + pluginName,
689
                                                        Launcher.class.getClassLoader(), loaders);
690

    
691
                                        PluginServices ps = new PluginServices(loader);
692

    
693
                                        pluginsServices.put(ps.getPluginName(), ps);
694

    
695
                                        instalados.add(pluginName);
696

    
697
                                        circle = false;
698
                                } catch (IOException e) {
699
                                        logger.error("Error con las librer?as del plugin", e);
700
                                        pluginsConfig.remove(pluginName);
701
                                        i = pluginsConfig.keySet().iterator();
702
                                }
703
                        }
704

    
705
                        if (circle) {
706
                                logger.error("Hay dependencias circulares entre los plugins");
707

    
708
                                break;
709
                        }
710
                }
711

    
712
                //Se eliminan los plugins que no fueron instalados
713
                Iterator i = pluginsConfig.keySet().iterator();
714

    
715
                while (i.hasNext()) {
716
                        String pluginName = (String) i.next();
717
                        PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName);
718
                        PluginServices ps = (PluginServices) pluginsServices.get(pluginName);
719

    
720
                        if (ps == null) {
721
                                pluginsConfig.remove(pluginName);
722
                                i = pluginsConfig.keySet().iterator();
723
                        }
724
                }
725
        }
726

    
727
        /**
728
         * DOCUMENT ME!
729
         */
730
        private static void pluginsMessages() {
731
                //Iteramos por todos los plugins
732
                Iterator i = pluginsConfig.keySet().iterator();
733

    
734
                while (i.hasNext()) {
735
                        String pluginName = (String) i.next();
736
                        PluginConfig config = (PluginConfig) pluginsConfig.get(pluginName);
737

    
738
                        PluginServices ps = (PluginServices) pluginsServices.get(pluginName);
739

    
740
                        if (config.getResourceBundle() != null) {
741
                                ps.setResourceBundle(config.getResourceBundle().getName(),
742
                                        locale);
743
                        }
744
                }
745
        }
746

    
747
        /**
748
         * DOCUMENT ME!
749
         *
750
         * @param name DOCUMENT ME!
751
         *
752
         * @return DOCUMENT ME!
753
         */
754
        static PluginServices getPluginServices(String name) {
755
                return (PluginServices) pluginsServices.get(name);
756
        }
757

    
758
        /**
759
         * DOCUMENT ME!
760
         *
761
         * @return DOCUMENT ME!
762
         */
763
        static String getPluginsDir() {
764
                return andamiConfig.getPluginsDirectory();
765
        }
766

    
767
        /**
768
         * DOCUMENT ME!
769
         *
770
         * @param s DOCUMENT ME!
771
         */
772
        static void setPluginsDir(String s) {
773
                andamiConfig.setPluginsDirectory(s);
774
        }
775

    
776
        /**
777
         * DOCUMENT ME!
778
         *
779
         * @return DOCUMENT ME!
780
         */
781
        static MDIFrame getMDIFrame() {
782
                return frame;
783
        }
784

    
785
        /**
786
         * DOCUMENT ME!
787
         *
788
         * @param pluginsDirectory
789
         */
790
        private static void loadPlugins(String pluginsDirectory) {
791
                File pDir = new File(pluginsDirectory);
792

    
793
                if (!pDir.exists()) {
794
                        return;
795
                }
796

    
797
                File[] pluginDirs = pDir.listFiles();
798

    
799
                for (int i = 0; i < pluginDirs.length; i++) {
800
                        if (pluginDirs[i].isDirectory()) {
801
                                File configXml = new File(pluginDirs[i].getAbsolutePath() +
802
                                                File.separator + "config.xml");
803

    
804
                                try {
805
                                        FileReader xml = new FileReader(configXml);
806
                                        PluginConfig pConfig = (PluginConfig) PluginConfig.unmarshal(xml);
807
                                        pluginsConfig.put(pluginDirs[i].getName(), pConfig);
808
                                } catch (FileNotFoundException e) {
809
                                        logger.info("Ignorando el directorio " +
810
                                                pluginDirs[i].getAbsolutePath() +
811
                                                " por no encontrar su fichero 'config.xml'");
812
                                } catch (MarshalException e) {
813
                                        logger.info("Ignorando el directorio " +
814
                                                pluginDirs[i].getAbsolutePath() +
815
                                                " por fichero 'config.xml' mal formado", e);
816
                                } catch (ValidationException e) {
817
                                        logger.info("Ignorando el directorio " +
818
                                                pluginDirs[i].getAbsolutePath() +
819
                                                " por fichero 'config.xml' mal formado", e);
820
                                }
821
                        }
822
                }
823
        }
824

    
825
        /**
826
         * DOCUMENT ME!
827
         *
828
         * @param language
829
         * @param country
830
         * @param variant
831
         *
832
         * @return DOCUMENT ME!
833
         */
834
        private static Locale getLocale(String language, String country,
835
                String variant) {
836
                if (variant != null) {
837
                        return new Locale(language, country, variant);
838
                } else if (country != null) {
839
                        return new Locale(language, country);
840
                } else if (language != null) {
841
                        return new Locale(language);
842
                } else {
843
                        return new Locale("es");
844
                }
845
        }
846

    
847
        /**
848
         * DOCUMENT ME!
849
         *
850
         * @param file DOCUMENT ME!
851
         *
852
         * @throws IOException DOCUMENT ME!
853
         * @throws MarshalException DOCUMENT ME!
854
         * @throws ValidationException DOCUMENT ME!
855
         */
856
        private static void andamiConfigToXML(String file)
857
                throws IOException, MarshalException, ValidationException {
858
                File xml = new File(file);
859
                File parent = xml.getParentFile();
860
                parent.mkdirs();
861

    
862
                FileWriter writer = new FileWriter(xml);
863
                andamiConfig.marshal(writer);
864
        }
865

    
866
        /**
867
         * DOCUMENT ME!
868
         *
869
         * @param file DOCUMENT ME!
870
         *
871
         * @throws ConfigurationException DOCUMENT ME!
872
         */
873
        private static void andamiConfigFromXML(String file)
874
                throws ConfigurationException {
875
                File xml = new File(file);
876

    
877
                //Si no existe se ponen los valores por defecto
878
                if (!xml.exists()) {
879
                        andamiConfig = new AndamiConfig();
880

    
881
                        Andami andami = new Andami();
882
                        andami.setUpdate(true);
883
                        andamiConfig.setAndami(andami);
884
                        andamiConfig.setLocaleCountry(Locale.getDefault().getCountry());
885
                        andamiConfig.setLocaleLanguage(Locale.getDefault().getLanguage());
886
                        andamiConfig.setLocaleVariant(Locale.getDefault().getVariant());
887

    
888
                        if (System.getProperty("javawebstart.version") != null) // Es java web start)
889
                         {
890
                                andamiConfig.setPluginsDirectory(new File(System.getProperty(
891
                                                        "user.home") + File.separator + appName +
892
                                                File.separator + "extensiones").getAbsolutePath());
893
                        } else {
894
                                andamiConfig.setPluginsDirectory(new File(appName +
895
                                                File.separator + "extensiones").getAbsolutePath());
896
                        }
897

    
898
                        andamiConfig.setPlugin(new Plugin[0]);
899
                } else {
900
                        //Se lee la configuraci?n
901
                        FileReader reader;
902

    
903
                        try {
904
                                reader = new FileReader(xml);
905
                                andamiConfig = (AndamiConfig) AndamiConfig.unmarshal(reader);
906
                        } catch (FileNotFoundException e) {
907
                                throw new ConfigurationException(e);
908
                        } catch (MarshalException e) {
909
                                throw new ConfigurationException(e);
910
                        } catch (ValidationException e) {
911
                                throw new ConfigurationException(e);
912
                        }
913
                }
914
        }
915

    
916
        /**
917
         * DOCUMENT ME!
918
         *
919
         * @return DOCUMENT ME!
920
         *
921
         * @throws ConfigurationException DOCUMENT ME!
922
         */
923
        private static XMLEntity persistenceFromXML() throws ConfigurationException {
924
                File xml = new File(pluginsPersistencePath);
925

    
926
                if (xml.exists()) {
927
                        FileReader reader;
928

    
929
                        try {
930
                                reader = new FileReader(xml);
931

    
932
                                XmlTag tag = (XmlTag) XmlTag.unmarshal(reader);
933

    
934
                                return new XMLEntity(tag);
935
                        } catch (FileNotFoundException e) {
936
                                throw new ConfigurationException(e);
937
                        } catch (MarshalException e) {
938
                                throw new ConfigurationException(e);
939
                        } catch (ValidationException e) {
940
                                throw new ConfigurationException(e);
941
                        }
942
                } else {
943
                        return new XMLEntity();
944
                }
945
        }
946

    
947
        /**
948
         * DOCUMENT ME!
949
         *
950
         * @param entity DOCUMENT ME!
951
         *
952
         * @throws ConfigurationException DOCUMENT ME!
953
         */
954
        private static void persistenceToXML(XMLEntity entity)
955
                throws ConfigurationException {
956
                File xml = new File(pluginsPersistencePath);
957

    
958
                FileWriter writer;
959

    
960
                try {
961
                        writer = new FileWriter(xml);
962
                        entity.getXmlTag().marshal(writer);
963
                } catch (FileNotFoundException e) {
964
                        throw new ConfigurationException(e);
965
                } catch (MarshalException e) {
966
                        throw new ConfigurationException(e);
967
                } catch (ValidationException e) {
968
                        throw new ConfigurationException(e);
969
                } catch (IOException e) {
970
                        throw new ConfigurationException(e);
971
                }
972
        }
973

    
974
        /**
975
         * Devuelve un array con los directorios de los plugins
976
         *
977
         * @param dirExt Directorio de las extensiones a partir del cual cuelgan
978
         *                   todos los directorios de los plugins
979
         *
980
         * @return ArrayList con los directorios
981
         */
982
        private String[] getLocales(File dirExt) {
983
                ArrayList types = new ArrayList();
984
                File[] files = dirExt.listFiles();
985

    
986
                for (int i = 0; i < files.length; i++) {
987
                        if (files[i].isDirectory()) {
988
                                File[] textFile = files[i].listFiles(new FilenameFilter() {
989
                                                        public boolean accept(File dir, String fileName) {
990
                                                                return fileName.toLowerCase().startsWith("text_"); //$NON-NLS-1$
991
                                                        }
992
                                                });
993

    
994
                                for (int j = 0; j < textFile.length; j++) {
995
                                        String s = (textFile[j]).getName().replaceAll("text_", "");
996
                                        s = s.replaceAll(".properties", "");
997
                                        s = s.trim();
998

    
999
                                        if (!types.contains(s)) {
1000
                                                types.add(s);
1001
                                        }
1002
                                }
1003
                        }
1004
                }
1005

    
1006
                return (String[]) types.toArray(new String[0]);
1007
        }
1008

    
1009
        /**
1010
         * DOCUMENT ME!
1011
         *
1012
         * @return Returns the frame.
1013
         */
1014
        static MDIFrame getFrame() {
1015
                return frame;
1016
        }
1017

    
1018
        /**
1019
         * Secuencia de cerrado de Andami
1020
         */
1021
        public static void closeApplication() {
1022
                //Configuraci?n de Andami
1023
                try {
1024
                        andamiConfigToXML(andamiConfigPath);
1025
                } catch (MarshalException e) {
1026
                        logger.error("No se pudo guardar la configuraci?n de Andami", e);
1027
                } catch (ValidationException e) {
1028
                        logger.error("No se pudo guardar la configuraci?n de Andami", e);
1029
                } catch (IOException e) {
1030
                        logger.error("No se pudo guardar la configuraci?n de Andami", e);
1031
                }
1032

    
1033
                //Persistencia de los plugins
1034
                Iterator i = pluginsConfig.keySet().iterator();
1035

    
1036
                XMLEntity entity = new XMLEntity();
1037

    
1038
                while (i.hasNext()) {
1039
                        String pName = (String) i.next();
1040
                        PluginServices ps = (PluginServices) pluginsServices.get(pName);
1041
                        XMLEntity ent = ps.getPersistentXML();
1042

    
1043
                        if (ent != null) {
1044
                                ent.putProperty("com.iver.andami.pluginName", pName);
1045
                                entity.addChild(ent);
1046
                        }
1047
                }
1048

    
1049
                try {
1050
                        persistenceToXML(entity);
1051
                } catch (ConfigurationException e1) {
1052
                        logger.error("Se produjo un error guardando la configuraci?n de los plugins",
1053
                                e1);
1054
                }
1055

    
1056
                System.exit(0);
1057
        }
1058

    
1059
        /**
1060
         * DOCUMENT ME!
1061
         *
1062
         * @return DOCUMENT ME!
1063
         */
1064
        static HashMap getClassesExtensions() {
1065
                return classesExtensions;
1066
        }
1067

    
1068
        /**
1069
         * DOCUMENT ME!
1070
         *
1071
         * @param extDir DOCUMENT ME!
1072
         */
1073
        private static void downloadExtensions(String extDir) {
1074
                java.util.Date fechaActual = null;
1075

    
1076
                try {
1077
                        if (System.getProperty("javawebstart.version") != null) {
1078
                                //Obtenemos la URL del servidor
1079
                                BasicService bs = (BasicService) ServiceManager.lookup(
1080
                                                "javax.jnlp.BasicService");
1081
                                URL baseURL = bs.getCodeBase();
1082

    
1083
                                //Se descargan las extensiones
1084
                                SplashWindow.process(5,
1085
                                        "Descargando las extensiones desde " + baseURL + " a " +
1086
                                        extDir);
1087

    
1088
                                URL url = new URL(baseURL + "extensiones.zip");
1089
                                URLConnection connection = url.openConnection();
1090

    
1091
                                System.out.println(url.toExternalForm() + ":");
1092
                                System.out.println("  Content Type: " +
1093
                                        connection.getContentType());
1094
                                System.out.println("  Content Length: " +
1095
                                        connection.getContentLength());
1096
                                System.out.println("  Last Modified: " +
1097
                                        new Date(connection.getLastModified()));
1098
                                System.out.println("  Expiration: " +
1099
                                        connection.getExpiration());
1100
                                System.out.println("  Content Encoding: " +
1101
                                        connection.getContentEncoding());
1102

    
1103
                                // Guardamos la fecha del fichero de extensiones que nos hemos bajado, y
1104
                                // comprobamos el ?ltimo que se ha bajado. Si no son
1105
                                // iguales, nos bajamos el nuevo. Si son iguales, no
1106
                                // nos bajamos nada.
1107
                                Long miliSecondsInWeb = new Long(connection.getLastModified());
1108

    
1109
                                // PluginServices ps = PluginServices.getPluginServices("com.iver.core");
1110
                                // if (ps.getPersistentXML().getStringProperty("timestamp") != null)
1111
                                File destDir = new File(extDir);
1112

    
1113
                                if (!destDir.exists()) {
1114
                                        // Creamos gvSIG
1115
                                        destDir.getParentFile().mkdir();
1116

    
1117
                                        if (!destDir.mkdir()) {
1118
                                                System.err.println("Imposible crear el directorio " +
1119
                                                        destDir.getAbsolutePath());
1120
                                        }
1121
                                }
1122

    
1123
                                File timeFile = new File(destDir.getParent() + File.separator +
1124
                                                "timeStamp.properties");
1125

    
1126
                                if (!timeFile.exists()) {
1127
                                        timeFile.createNewFile();
1128
                                }
1129

    
1130
                                FileInputStream inAux = new FileInputStream(timeFile);
1131
                                Properties prop = new Properties();
1132
                                prop.load(inAux);
1133
                                inAux.close();
1134

    
1135
                                if (prop.getProperty("timestamp") != null) {
1136
                                        Long lastMiliSeconds = (Long) new Long(prop.getProperty(
1137
                                                                "timestamp"));
1138

    
1139
                                        if (lastMiliSeconds.longValue() == miliSecondsInWeb.longValue()) {
1140
                                                System.out.println("No hay nueva actualizaci?n");
1141

    
1142
                                                return;
1143
                                        }
1144

    
1145
                                        System.out.println("timeStampWeb= " + miliSecondsInWeb);
1146
                                        System.out.println("timeStampLocal= " + lastMiliSeconds);
1147
                                } else {
1148
                                        System.out.println("El timeStamp no est? escrito en " +
1149
                                                timeFile.getAbsolutePath());
1150
                                }
1151

    
1152
                                InputStream stream = connection.getInputStream();
1153
                                File temp = File.createTempFile("gvsig", ".zip");
1154
                                temp.deleteOnExit();
1155

    
1156
                                FileOutputStream file = new FileOutputStream(temp);
1157
                                BufferedInputStream in = new BufferedInputStream(stream);
1158
                                BufferedOutputStream out = new BufferedOutputStream(file);
1159

    
1160
                                int i;
1161
                                int pct;
1162
                                int desde;
1163
                                int hasta;
1164

    
1165
                                hasta = connection.getContentLength() / 1024;
1166
                                desde = 0;
1167

    
1168
                                while ((i = in.read()) != -1) {
1169
                                        pct = ((desde / 1024) * 100) / hasta;
1170

    
1171
                                        if (((desde % 10240) == 0) && (pct > 10) &&
1172
                                                        ((pct % 10) == 0)) {
1173
                                                SplashWindow.process(pct,
1174
                                                        (desde / 1024) + "Kb de " + hasta +
1175
                                                        "Kb descargados...");
1176
                                        }
1177

    
1178
                                        out.write(i);
1179
                                        desde++;
1180
                                }
1181

    
1182
                                out.flush();
1183
                                out.close();
1184
                                in.close();
1185

    
1186
                                //Se extrae el zip
1187
                                SplashWindow.process(5, "Extensiones descargadas.");
1188

    
1189
                                System.out.println("Extrayendo a " + destDir.getAbsolutePath());
1190

    
1191
                                Date fechaDir = new Date(destDir.lastModified());
1192
                                System.out.println("Fecha del directorio " + extDir + " = " +
1193
                                        fechaDir.toString());
1194
                                Utilities.extractTo(temp, new File(extDir), splashWindow);
1195

    
1196
                                // Si todo ha ido bien, guardamos el timestamp.
1197
                                ///  App.instance.getPc().addProperties("timestamp", miliSecondsInWeb);
1198
                                // XMLEntity xml=ps.getPersistentXML();
1199
                                fechaActual = new java.util.Date();
1200

    
1201
                                FileOutputStream outAux = new FileOutputStream(timeFile);
1202
                                prop.setProperty("timestamp", miliSecondsInWeb.toString());
1203
                                prop.store(outAux, "last download");
1204
                                outAux.close();
1205
                                System.out.println("Fecha actual guardada: " +
1206
                                        fechaActual.toGMTString());
1207

    
1208
                                /* xml.putProperty("timestamp",fechaActual.toGMTString());
1209
                                   ps.setPresistentXML(xml); */
1210
                        }
1211
                } catch (IOException e) {
1212
                        NotificationManager.addError("", e);
1213
                } catch (UnavailableServiceException e) {
1214
                        NotificationManager.addError("", e);
1215
                } catch (SecurityException e) {
1216
                        System.err.println("No se puede escribir el timeStamp " +
1217
                                fechaActual.toGMTString());
1218
                        NotificationManager.addError("", e);
1219
                }
1220
        }
1221

    
1222
        /**
1223
         * DOCUMENT ME!
1224
         *
1225
         * @return DOCUMENT ME!
1226
         */
1227
        private static Extensions[] getExtensions() {
1228
                ArrayList array = new ArrayList();
1229
                Iterator iter = pluginsConfig.values().iterator();
1230

    
1231
                while (iter.hasNext()) {
1232
                        array.add(((PluginConfig) iter.next()).getExtensions());
1233
                }
1234

    
1235
                return (Extensions[]) array.toArray(new Extensions[0]);
1236
        }
1237

    
1238
        /**
1239
         * DOCUMENT ME!
1240
         *
1241
         * @return DOCUMENT ME!
1242
         */
1243
        public static HashMap getPluginConfig() {
1244
                return pluginsConfig;
1245
        }
1246

    
1247
        /**
1248
         * DOCUMENT ME!
1249
         *
1250
         * @param s DOCUMENT ME!
1251
         *
1252
         * @return DOCUMENT ME!
1253
         */
1254
        public static Extension getExtension(String s) {
1255
                Extensions[] exts = getExtensions();
1256

    
1257
                for (int i = 0; i < exts.length; i++) {
1258
                        for (int j = 0; j < exts[i].getExtensionCount(); j++) {
1259
                                if (exts[i].getExtension(j).getClassName().equals(s)) {
1260
                                        return exts[i].getExtension(j);
1261
                                }
1262
                        }
1263
                }
1264

    
1265
                return null;
1266
        }
1267

    
1268
        /**
1269
         * DOCUMENT ME!
1270
         *
1271
         * @return DOCUMENT ME!
1272
         */
1273
        public static AndamiConfig getAndamiConfig() {
1274
                return andamiConfig;
1275
        }
1276

    
1277
        /**
1278
         * DOCUMENT ME!
1279
         *
1280
         * @author $author$
1281
         * @version $Revision: 1078 $
1282
         */
1283
        public static class ExtensionComparator implements Comparator {
1284
                /**
1285
                 * DOCUMENT ME!
1286
                 *
1287
                 * @param o1 DOCUMENT ME!
1288
                 * @param o2 DOCUMENT ME!
1289
                 *
1290
                 * @return DOCUMENT ME!
1291
                 */
1292
                public int compare(Object o1, Object o2) {
1293
                        Extension e1 = (Extension) o1;
1294
                        Extension e2 = (Extension) o2;
1295

    
1296
                        if (!e1.hasPriority() && !e2.hasPriority()) {
1297
                                return -1;
1298
                        }
1299

    
1300
                        if (e1.hasPriority() && !e2.hasPriority()) {
1301
                                return -Integer.MAX_VALUE;
1302
                        }
1303

    
1304
                        if (e2.hasPriority() && !e1.hasPriority()) {
1305
                                return Integer.MAX_VALUE;
1306
                        }
1307

    
1308
                        return e1.getPriority() - e2.getPriority();
1309
                }
1310
        }
1311

    
1312
        /**
1313
         * DOCUMENT ME!
1314
         */
1315
        public static class MenuComparator implements Comparator {
1316
                private static ExtensionComparator extComp = new ExtensionComparator();
1317

    
1318
                /**
1319
                 * DOCUMENT ME!
1320
                 *
1321
                 * @param o1 DOCUMENT ME!
1322
                 * @param o2 DOCUMENT ME!
1323
                 *
1324
                 * @return DOCUMENT ME!
1325
                 */
1326
                public int compare(Object o1, Object o2) {
1327
                        SortableMenu e1 = (SortableMenu) o1;
1328
                        SortableMenu e2 = (SortableMenu) o2;
1329

    
1330
                        if (!e1.menu.hasPosition() && !e2.menu.hasPosition()) {
1331
                                if (e1.extension instanceof SkinExtensionType) {
1332
                                        return 1;
1333
                                } else if (e2.extension instanceof SkinExtensionType) {
1334
                                        return -1;
1335
                                } else {
1336
                                        return extComp.compare(e1.extension, e2.extension);
1337
                                }
1338
                        }
1339

    
1340
                        if (e1.menu.hasPosition() && !e2.menu.hasPosition()) {
1341
                                return -Integer.MAX_VALUE;
1342
                        }
1343

    
1344
                        if (e2.menu.hasPosition() && !e1.menu.hasPosition()) {
1345
                                return Integer.MAX_VALUE;
1346
                        }
1347

    
1348
                        return e1.menu.getPosition() - e2.menu.getPosition();
1349
                }
1350
        }
1351

    
1352
        /**
1353
         * DOCUMENT ME!
1354
         *
1355
         * @author $author$
1356
         * @version $Revision: 1078 $
1357
         */
1358
        public static class SortableMenu {
1359
                public PluginClassLoader loader;
1360
                public Menu menu;
1361
                public SkinExtensionType extension;
1362

    
1363
                /**
1364
                 * DOCUMENT ME!
1365
                 *
1366
                 * @param loader DOCUMENT ME!
1367
                 * @param skinExt
1368
                 * @param menu2
1369
                 */
1370
                public SortableMenu(PluginClassLoader loader,
1371
                        SkinExtensionType skinExt, Menu menu2) {
1372
                        extension = skinExt;
1373
                        menu = menu2;
1374
                        this.loader = loader;
1375
                }
1376
        }
1377

    
1378
        /*public static Extension getExtension(Class s) {
1379
           //String aux=s.getName().substring(s.getName().lastIndexOf("."),s.getName().length());
1380
           String aux1=s.getName().substring(0,s.getName().lastIndexOf("."));
1381
           PluginConfig p=(PluginConfig)pluginsConfig.get(aux1);
1382
           Extension ext=null;
1383
           if (p!=null){
1384
           Extensions exts=p.getExtensions();
1385
        
1386
           for (int i=0;i<exts.getExtensionCount();i++){
1387
                   if (exts.getExtension(i).getClassName().equals(s.getName())){
1388
                           ext=exts.getExtension(i);
1389
                   }
1390
           }
1391
           }
1392
           return ext;
1393
           }
1394
         */
1395
}