Revision 45958

View differences:

tags/org.gvsig.desktop-2.0.337/org.gvsig.desktop.framework/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3

  
4
    <modelVersion>4.0.0</modelVersion>
5
    <artifactId>org.gvsig.desktop.framework</artifactId>
6
    <packaging>pom</packaging>
7
    <name>${project.artifactId}</name>
8
    <parent>
9
        <groupId>org.gvsig</groupId>
10
        <artifactId>org.gvsig.desktop</artifactId>
11
        <version>2.0.337</version>
12
    </parent>
13

  
14
    <modules>
15
        <module>org.gvsig.andami</module>
16
        <module>org.gvsig.andami.updater</module>
17
    </modules>
18

  
19
    <description>Contains the launcher and plugin framework used in gvSIG.</description>
20
</project>
21

  
0 22

  
tags/org.gvsig.desktop-2.0.337/org.gvsig.desktop.framework/org.gvsig.andami/src/test/java/org/gvsig/andami/AllTests.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.andami;
25

  
26
import junit.framework.Test;
27
import junit.framework.TestSuite;
28

  
29
public class AllTests {
30

  
31
	public static Test suite() {
32
		TestSuite suite = new TestSuite("Test for com.iver.andami");
33
		//$JUnit-BEGIN$
34

  
35
		//$JUnit-END$
36
		return suite;
37
	}
38

  
39
}
0 40

  
tags/org.gvsig.desktop-2.0.337/org.gvsig.desktop.framework/org.gvsig.andami/src/main/assembly/gvsig-andami-package.xml
1
<!--
2

  
3
    gvSIG. Desktop Geographic Information System.
4

  
5
    Copyright (C) 2007-2013 gvSIG Association.
6

  
7
    This program is free software; you can redistribute it and/or
8
    modify it under the terms of the GNU General Public License
9
    as published by the Free Software Foundation; either version 3
10
    of the License, or (at your option) any later version.
11

  
12
    This program is distributed in the hope that it will be useful,
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
    GNU General Public License for more details.
16

  
17
    You should have received a copy of the GNU General Public License
18
    along with this program; if not, write to the Free Software
19
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20
    MA  02110-1301, USA.
21

  
22
    For any additional information, do not hesitate to contact us
23
    at info AT gvsig.com, or visit our website www.gvsig.com.
24

  
25
-->
26
<assembly>
27
  <id>gvsig-andami-package</id>
28
  <formats>
29
    <format>zip</format>
30
  </formats>
31
  <baseDirectory>.</baseDirectory>
32
  <!-- 
33
  <includeBaseDirectory>true</includeBaseDirectory>
34
   -->
35
  <files>
36
    <file>
37
      <source>target/${project.artifactId}-${project.version}.jar</source>
38
      <outputDirectory>lib</outputDirectory>
39
    </file>
40
    <file>
41
      <source>src/main/resources/default-log4j/log4j.properties</source>
42
      <outputDirectory>.</outputDirectory>
43
    </file>  
44
  </files>
45
  <fileSets>
46
    <fileSet>
47
      <directory>src/main/resources-application</directory>
48
      <outputDirectory>.</outputDirectory>
49
    </fileSet>
50
    <fileSet>
51
      <directory>src/main/resources/org/gvsig/andami</directory>
52
      <outputDirectory>i18n/andami</outputDirectory>
53
    </fileSet>
54
  </fileSets>
55
  
56
  <dependencySets>
57
    <dependencySet>
58
      <useProjectArtifact>false</useProjectArtifact>
59
      <useTransitiveDependencies>true</useTransitiveDependencies>
60
      <outputDirectory>lib</outputDirectory>
61
    </dependencySet>
62
  </dependencySets>
63

  
64
</assembly>
65

  
0 66

  
tags/org.gvsig.desktop-2.0.337/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/LibraryExtension.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.andami;
25

  
26
import org.gvsig.andami.plugins.Extension;
27

  
28
public class LibraryExtension extends Extension {
29

  
30
	public void initialize() {
31
		// Do nothing
32
	}
33

  
34
	public void execute(String actionCommand) {
35
		// Do nothing
36
	}
37

  
38
	public boolean isEnabled() {
39
		return false;
40
	}
41

  
42
	public boolean isVisible() {
43
		return false;
44
	}
45

  
46
}
0 47

  
tags/org.gvsig.desktop-2.0.337/org.gvsig.desktop.framework/org.gvsig.andami/src/main/java/org/gvsig/andami/Launcher.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.andami;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Cursor;
27
import java.awt.Dimension;
28
import java.awt.EventQueue;
29
import java.awt.Frame;
30
import java.awt.KeyboardFocusManager;
31
import java.awt.Point;
32
import java.awt.Toolkit;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.awt.event.WindowAdapter;
36
import java.awt.event.WindowEvent;
37
import java.io.BufferedOutputStream;
38
import java.io.BufferedReader;
39
import java.io.File;
40
import java.io.FileFilter;
41
import java.io.FileInputStream;
42
import java.io.FileNotFoundException;
43
import java.io.FileOutputStream;
44
import java.io.FileReader;
45
import java.io.IOException;
46
import java.io.InputStream;
47
import java.io.InputStreamReader;
48
import java.io.OutputStreamWriter;
49
import java.io.Reader;
50
import java.io.StringWriter;
51
import java.net.Authenticator;
52
import java.net.MalformedURLException;
53
import java.net.PasswordAuthentication;
54
import java.net.URL;
55
import java.net.URLClassLoader;
56
import java.nio.channels.FileChannel;
57
import java.security.AllPermission;
58
import java.security.CodeSource;
59
import java.security.PermissionCollection;
60
import java.security.Permissions;
61
import java.security.Policy;
62
import java.text.MessageFormat;
63
import java.util.ArrayList;
64
import java.util.Arrays;
65
import java.util.Collections;
66
import java.util.Comparator;
67
import java.util.Enumeration;
68
import java.util.HashMap;
69
import java.util.HashSet;
70
import java.util.Iterator;
71
import java.util.List;
72
import java.util.Locale;
73
import java.util.Map;
74
import java.util.Map.Entry;
75
import java.util.Properties;
76
import java.util.Set;
77
import java.util.TreeSet;
78
import java.util.prefs.Preferences;
79

  
80
import javax.swing.ImageIcon;
81
import javax.swing.JButton;
82
import javax.swing.JComponent;
83
import javax.swing.JDialog;
84
import javax.swing.JFrame;
85
import javax.swing.JOptionPane;
86
import javax.swing.JPopupMenu;
87
import javax.swing.ListSelectionModel;
88
import javax.swing.SwingUtilities;
89
import javax.swing.UIManager;
90

  
91

  
92
import org.apache.commons.cli.CommandLine;
93
import org.apache.commons.cli.CommandLineParser;
94
import org.apache.commons.cli.Options;
95
import org.apache.commons.cli.ParseException;
96
import org.apache.commons.cli.PosixParser;
97
import org.apache.commons.configuration.PropertiesConfiguration;
98
import org.apache.commons.io.FileUtils;
99
import org.apache.commons.lang3.JavaVersion;
100
import org.apache.commons.lang3.StringUtils;
101
import org.apache.commons.lang3.SystemUtils;
102
import org.apache.log4j.AppenderSkeleton;
103
import org.apache.log4j.PatternLayout;
104
import org.apache.log4j.PropertyConfigurator;
105
import org.apache.log4j.RollingFileAppender;
106
import org.apache.log4j.spi.LoggingEvent;
107
import org.apache.log4j.spi.ThrowableInformation;
108
import org.exolab.castor.xml.MarshalException;
109
import org.exolab.castor.xml.ValidationException;
110

  
111
import org.gvsig.andami.actioninfo.ActionInfo;
112
import org.gvsig.andami.actioninfo.ActionInfoManager;
113
import org.gvsig.andami.config.generate.Andami;
114
import org.gvsig.andami.config.generate.AndamiConfig;
115
import org.gvsig.andami.config.generate.Plugin;
116
import org.gvsig.andami.impl.DefaultArguments;
117
import org.gvsig.andami.impl.UnsavedDataException;
118
import org.gvsig.andami.messages.Messages;
119
import org.gvsig.andami.messages.NotificationManager;
120
import org.gvsig.andami.persistence.serverData.ServerDataPersistence;
121
import org.gvsig.andami.plugins.ExclusiveUIExtension;
122
import org.gvsig.andami.plugins.ExtensionDecorator;
123
import org.gvsig.andami.plugins.IExtension;
124
import org.gvsig.andami.plugins.PluginClassLoader;
125
import org.gvsig.andami.plugins.config.generate.Action;
126
import org.gvsig.andami.plugins.config.generate.ActionTool;
127
import org.gvsig.andami.plugins.config.generate.AlternativeNames;
128
import org.gvsig.andami.plugins.config.generate.ComboButton;
129
import org.gvsig.andami.plugins.config.generate.ComboButtonElement;
130
import org.gvsig.andami.plugins.config.generate.ComboScale;
131
import org.gvsig.andami.plugins.config.generate.Depends;
132
import org.gvsig.andami.plugins.config.generate.Extension;
133
import org.gvsig.andami.plugins.config.generate.Extensions;
134
import org.gvsig.andami.plugins.config.generate.LabelSet;
135
import org.gvsig.andami.plugins.config.generate.Menu;
136
import org.gvsig.andami.plugins.config.generate.PluginConfig;
137
import org.gvsig.andami.plugins.config.generate.PopupMenu;
138
import org.gvsig.andami.plugins.config.generate.PopupMenus;
139
import org.gvsig.andami.plugins.config.generate.SelectableTool;
140
import org.gvsig.andami.plugins.config.generate.SkinExtension;
141
import org.gvsig.andami.plugins.config.generate.SkinExtensionType;
142
import org.gvsig.andami.plugins.config.generate.ToolBar;
143
import org.gvsig.andami.plugins.status.IExtensionStatus;
144
import org.gvsig.andami.plugins.status.IUnsavedData;
145
import org.gvsig.andami.ui.AndamiEventQueue;
146
import org.gvsig.andami.ui.DisablePluginsConflictingLayoutPanel;
147
import org.gvsig.andami.ui.MDIManagerLoadException;
148
import org.gvsig.andami.ui.ToolsWindowManager;
149
import org.gvsig.andami.ui.fonts.FontUtils;
150
import org.gvsig.andami.ui.mdiFrame.MDIFrame;
151
import org.gvsig.andami.ui.mdiFrame.MainFrame;
152
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
153
import org.gvsig.andami.ui.splash.MultiSplashWindow;
154
import org.gvsig.andami.ui.theme.Theme;
155
import org.gvsig.andami.ui.wizard.UnsavedDataPanel;
156
import org.gvsig.andami.ui.wizard.UnsavedDataPanel.UnsavedDataPanelListener;
157
import org.gvsig.installer.lib.api.Dependencies;
158
import org.gvsig.installer.lib.api.Dependency;
159
import org.gvsig.installer.lib.api.InstallerLocator;
160
import org.gvsig.installer.lib.api.InstallerManager;
161
import org.gvsig.installer.lib.api.PackageInfo;
162
import org.gvsig.installer.lib.api.creation.MakePluginPackageServiceException;
163
import org.gvsig.installer.swing.api.SwingInstallerLocator;
164
import org.gvsig.installer.swing.api.execution.InstallWizardPanel;
165
import org.gvsig.installer.swing.api.wizard.InstallerWizardActionListener;
166
import org.gvsig.installer.swing.api.wizard.InstallerWizardPanel;
167
import org.gvsig.tools.ToolsLocator;
168
import org.gvsig.tools.exception.ListBaseException;
169
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
170
import org.gvsig.tools.swing.api.ToolsSwingLocator;
171
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
172
import org.gvsig.tools.swing.icontheme.IconTheme;
173
import org.gvsig.tools.swing.icontheme.IconThemeManager;
174
import org.gvsig.tools.util.FolderSet;
175
import org.gvsig.tools.util.FolderSet.FolderEntry;
176
import org.gvsig.utils.DateTime;
177
import org.gvsig.utils.DefaultListModel;
178
import org.gvsig.utils.XMLEntity;
179
import org.gvsig.utils.xml.XMLEncodingUtils;
180
import org.gvsig.utils.xmlEntity.generate.XmlTag;
181

  
182
import org.slf4j.Logger;
183
import org.slf4j.LoggerFactory;
184

  
185
/**
186
 * <p>
187
 * Andami's launching class. This is the class used to create the Andami's
188
 * plugin environment.<br>
189
 * </p>
190
 *
191
 * <p>
192
 * <b>Syntax:</b> <br>
193
 * java [-Xmx512M (for 512MB of RAM)] [-classpath={a colon-separated(unix) or
194
 * semicolon-separated(windows) list of files containg base library of classes}]
195
 * [-Djava.library.path=PATH_TO_NATIVE_LIBRARIES]
196
 * PATH_TO_APPLICATION_HOME_DIRECTORY PATH_TO_APPLICATION_PLUGINS_DIRECTORY
197
 * [{list of additional custom application arguments separated by spaces}]
198
 * </p>
199
 *
200
 *
201
 */
202
public class Launcher {
203

  
204
    private static Arguments arguments;
205

  
206
    public static abstract class MapWithAlias<Item> extends HashMap<String, Item> {
207

  
208
        private HashMap<String, String> aliases = new HashMap<String, String>();
209

  
210
        public abstract String[] getAliases(Item item);
211

  
212
        public boolean isAlias(String key) {
213
            return aliases.get(key) != null;
214
        }
215

  
216
        public String getMainKey(String key) {
217
            Item item = super.get(key);
218
            if (item != null) {
219
                return key;
220
            }
221
            String alias = aliases.get(key);
222
            if (alias != null) {
223
                return alias;
224
            }
225
            return null;
226
        }
227

  
228
        public Item get(Object key) {
229
            Item item = super.get(key);
230
            if (item != null) {
231
                return item;
232
            }
233
            String alias = aliases.get(key);
234
            if (alias != null) {
235
                return super.get(alias);
236
            }
237
            return null;
238
        }
239

  
240
        public boolean containsKey(Object key) {
241
            boolean contains = super.containsKey(key);
242
            if (contains) {
243
                return true;
244
            }
245
            String alias = aliases.get(key);
246
            return super.containsKey(alias);
247
        }
248

  
249
        public Item put(String key, Item value) {
250
            super.put(key, value);
251
            String[] aliases = getAliases(value);
252
            if (aliases == null) {
253
                return value;
254
            }
255
            for (int n = 0; n < aliases.length; n++) {
256
                this.aliases.put(aliases[n].trim(), key);
257
            }
258
            return value;
259
        }
260

  
261
        public void putAll(Map<? extends String, ? extends Item> m) {
262
            Iterator<?> it = m.entrySet().iterator();
263
            while (it.hasNext()) {
264
                Map.Entry<String, Item> x = (Map.Entry<String, Item>) it.next();
265
                this.put(x.getKey(), x.getValue());
266
            }
267
        }
268

  
269
        public Item remove(Object key) {
270
            Item item = super.get(key);
271
            if (item == null) {
272
                String alias = aliases.get(key);
273
                if (alias == null) {
274
                    return null;
275
                }
276
                item = super.get(alias);
277
                super.remove(alias);
278
            } else {
279
                super.remove(key);
280
            }
281
            String[] aliases = getAliases(item);
282
            if (aliases == null) {
283
                return item;
284
            }
285
            // Rebuild the alias list
286
            this.aliases = new HashMap<String, String>();
287
            Iterator<java.util.Map.Entry<String, Item>> it = this.entrySet().iterator();
288
            while (it.hasNext()) {
289
                java.util.Map.Entry<String, Item> entry = it.next();
290
                aliases = getAliases(entry.getValue());
291
                if (aliases == null) {
292
                    continue;
293
                }
294
                for (int n = 0; n < aliases.length; n++) {
295
                    this.aliases.put(aliases[n].trim(), entry.getKey());
296
                }
297
            }
298

  
299
            return item;
300
        }
301

  
302
    }
303

  
304
    public static class PluginsConfig extends MapWithAlias<org.gvsig.andami.plugins.config.generate.PluginConfig> {
305

  
306
        public String[] getAliases(
307
                org.gvsig.andami.plugins.config.generate.PluginConfig item) {
308
            return getAlternativeNames(item);
309
        }
310

  
311
        static String[] getAlternativeNames(org.gvsig.andami.plugins.config.generate.PluginConfig item) {
312
            AlternativeNames[] x = item.getAlternativeNames();
313
            if (x == null) {
314
                return null;
315
            }
316
            String[] r = new String[x.length];
317
            for (int i = 0; i < x.length; i++) {
318
                r[i] = x[i].getName();
319
            }
320
            return r;
321
        }
322

  
323
    }
324

  
325
    public static class PluginsServices extends MapWithAlias<org.gvsig.andami.PluginServices> {
326

  
327
        public String[] getAliases(org.gvsig.andami.PluginServices item) {
328
            return item.getAlternativeNames();
329
        }
330
    }
331

  
332
    protected static Logger logger = LoggerFactory.getLogger(Launcher.class
333
            .getName());
334
    protected static Preferences prefs = Preferences.userRoot().node(
335
            "gvsig.connection");
336
    protected static AndamiConfig andamiConfig;
337
    protected static MultiSplashWindow splashWindow;
338
    protected static String appName;
339
    protected static Locale locale;
340
    protected static PluginsConfig pluginsConfig = new PluginsConfig();
341
    protected static PluginsServices pluginsServices = new PluginsServices();
342
    protected static MDIFrame frame;
343
    protected static HashMap<Class<? extends IExtension>, ExtensionDecorator> classesExtensions = new HashMap<Class<? extends IExtension>, ExtensionDecorator>();
344
    protected static String andamiConfigPath;
345
    protected static final String nonWinDefaultLookAndFeel = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
346

  
347
    protected static List<String> pluginsOrdered = new ArrayList<String>();
348
    protected static List<IExtension> extensions = new ArrayList<IExtension>();
349
    protected static String appHomeDir = null;
350
    // it seems castor uses this encoding
351
    protected static final String CASTORENCODING = "UTF8";
352

  
353
    protected static ListBaseException launcherrors = null;
354

  
355
    protected static Theme theme = null;
356

  
357
    private List<String> deprecatedPluginNames = null;
358

  
359
    private static final class ProxyAuth extends Authenticator {
360

  
361
        private PasswordAuthentication auth;
362

  
363
        private ProxyAuth(String user, String pass) {
364
            auth = new PasswordAuthentication(user, pass.toCharArray());
365
        }
366

  
367
        protected PasswordAuthentication getPasswordAuthentication() {
368
            return auth;
369
        }
370
    }
371

  
372
    private static Launcher launcherInstance;
373

  
374
    public static Launcher getInstance() {
375
        if (launcherInstance == null) {
376
            launcherInstance = new Launcher();
377
        }
378
        return launcherInstance;
379
    }
380

  
381
    public static void main(final String[] args) throws Exception {
382
        arguments = new DefaultArguments(args);
383

  
384
        final Launcher launcher = getInstance();
385
        try {
386
            if (arguments.contains("install")) {
387
                launcher.doInstall(args);
388
            } else {
389
                launcher.doMain(args);
390
            }
391
        } catch (Exception e) {
392
            logger.error("excepcion al arrancar", e);
393
            System.exit(-1);
394
        }
395
    }
396

  
397
    protected void downloadExtensions(String extDir) {
398
        // do nothing
399
    }
400

  
401
    public static class LaunchException extends ListBaseException {
402

  
403
        private static final long serialVersionUID = 4541192746962684705L;
404

  
405
        public LaunchException() {
406
            super("Errors in initialization of application.",
407
                    "_errors_in_initialization_of_application",
408
                    serialVersionUID);
409
        }
410

  
411
    }
412

  
413
    protected void addError(Throwable ex) {
414
        if (launcherrors == null) {
415
            launcherrors = new LaunchException();
416
        }
417
        launcherrors.add(ex);
418
    }
419

  
420
    protected void addError(String msg, Throwable cause) {
421
        logger.error(msg, cause);
422
        this.addError(new RuntimeException(msg, cause));
423
    }
424

  
425
    protected void addError(String msg) {
426
        this.addError(msg, null);
427
    }
428

  
429
    private String translate(String msg) {
430
        return PluginServices.getText(Launcher.class, msg);
431
    }
432

  
433
    private List<String> getDeprecatedPluginNames() {
434
        if (deprecatedPluginNames == null) {
435
            String[] ss = new String[]{
436
                "org.gvsig.app",
437
                "org.gvsig.coreplugin",
438
                "org.gvsig.editing",
439
                "org.gvsig.installer.app.extension",
440
                "org.gvsig.exportto.app.extension"
441
            };
442
            deprecatedPluginNames = Arrays.asList(ss);
443
        }
444
        return deprecatedPluginNames;
445
    }
446

  
447
    public static Arguments getArguments() {
448
        return arguments;
449
    }
450
    
451
    public void doMain(String[] args) throws Exception {
452

  
453
        if (args.length < 1) {
454
            System.err.println("Usage: Launcher appName plugins-directory [--language=locale]");
455
            System.err.println("No arguments specified.");
456
            System.err.println("Use default arguments 'gvSIG gvSIG/extensiones'");
457
            args = new String[]{"gvSIG", "gvSIG/extensiones"};
458
        }
459

  
460
        initializeApp(args, null);
461

  
462
        // Solucionamos el problema de permisos que se produc?do con Java
463
        // Web Start con este codigo.
464
        Policy.setPolicy(new Policy() {
465

  
466
            public PermissionCollection getPermissions(CodeSource codesource) {
467
                Permissions perms = new Permissions();
468
                perms.add(new AllPermission());
469
                return (perms);
470
            }
471

  
472
            public void refresh() {
473
            }
474
        });
475

  
476
        new DefaultLibrariesInitializer().fullInitialize(true);
477

  
478
        InstallerLocator.getInstallerManager().setDownloadBaseURL(
479
                new URL("http://downloads.gvsig.org/download/gvsig-desktop/"));
480

  
481
        try {
482
            initIconThemes();
483
        } catch (Exception ex) {
484
            this.addError("Can't initialize icon theme", ex);
485
        }
486
        // Registramos los iconos base
487
        try {
488
            registerIcons();
489
        } catch (Exception ex) {
490
            this.addError("Can't register icons", ex);
491
        }
492

  
493
        // Obtener la personalizaci�n de la aplicacion.
494
        try {
495
            logger.info("Initialize andami theme");
496
            theme = getTheme(andamiConfig.getPluginsDirectory());
497
        } catch (Exception ex) {
498
            this.addError("Can't get personalized theme for the application",
499
                    ex);
500
        }
501
        UIManager.put("Desktop.background", theme.getBackgroundColor());
502

  
503
        // Mostrar la ventana de inicio
504
        Frame f = new Frame();
505
        splashWindow = new MultiSplashWindow(f, theme, 27);
506

  
507
        // Ponemos los datos del proxy
508
        splashWindow.process(translate("SplashWindow.configuring_proxy"));
509
        logger.info("Configute http proxy");
510
        configureProxy();
511

  
512
        // Buscar actualizaciones de los plugins
513
        splashWindow.process(translate("SplashWindow.looking_for_updates"));
514
        try {
515
//			this.downloadExtensions(andamiConfig.getPluginsDirectory());
516
        } catch (Exception ex) {
517
            this.addError("Can't downloads plugins", ex);
518
        }
519

  
520
        splashWindow.process(translate("SplashWindow.initialize_install_manager"));
521
        initializeInstallerManager();
522

  
523
        InstallerManager installerManager = InstallerLocator.getInstallerManager();
524
        PackageInfo[] installedPackages = null;
525
        try {
526
            installedPackages = installerManager.getInstalledPackages();
527
        } catch (MakePluginPackageServiceException e) {
528
            // Do nothing, ignore errors
529
        }
530
        logger.info("Dump system information");
531
        logger_info(getInformation(installedPackages));
532
        saveEnvironInformation(installedPackages);
533

  
534
        // Se leen los config.xml de los plugins
535
        splashWindow.process(translate("SplashWindow.load_plugins_configuration"));
536
        try {
537
            logger.info("Load plugins information");
538
            this.loadPluginConfigs();
539
            if (pluginsConfig.isEmpty()) {
540
                logger.warn("No valid plugin was found.");
541
                System.exit(-1);
542
            }
543
        } catch (Throwable ex) {
544
            this.addError("Can't load plugins", ex);
545
        }
546

  
547
        splashWindow.process(translate("SplashWindow.check_incompatible_plugins"));
548
        fixIncompatiblePlugins(installedPackages);
549

  
550
        // Se configura el classloader del plugin
551
        splashWindow.process(translate("SplashWindow.setup_plugins_configuration"));
552
        try {
553
            logger.info("Configure plugins class loader");
554
            this.loadPluginServices();
555
        } catch (Throwable ex) {
556
            logger.warn("Can't initialize plugin's classloaders  ", ex);
557
        }
558
        try {
559
            registerActions();
560
        } catch (Throwable ex) {
561
            logger.warn("Can't register actions of plugins", ex);
562
        }
563

  
564
        initializeIdentityManagement(new File(andamiConfig.getPluginsDirectory()).getAbsoluteFile());
565

  
566
        // Initialize libraries
567
        splashWindow.process(translate("SplashWindow.initialize_plugins_libraries"));
568
        initializeLibraries();
569

  
570
        // Se carga un Skin si alguno ide los plugins trae informacion para ello
571
        splashWindow.process(translate("SplashWindow.looking_for_a_skin"));
572
        logger.info("Initialize skin");
573
        skinPlugin(null);
574

  
575
        // Se configura la cola de eventos
576
        splashWindow.process(translate("setting_up_event_queue"));
577
        EventQueue waitQueue = new AndamiEventQueue();
578
        Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);
579

  
580
        // Se configura la internacionalizacion del plugin
581
        splashWindow.process(translate("SplashWindow.starting_plugin_internationalization_system"));
582
        pluginsMessages();
583

  
584
        // Se modifica el andami-config con los plugins nuevos
585
        splashWindow.process(translate("SplashWindow.update_framework_configuration"));
586
        updateAndamiConfig();
587

  
588
        frame = MDIFrame.getInstance();
589
        // Se configura el nombre e icono de la aplicacion
590
        splashWindow.process(translate("SplashWindow.setting_up_applications_name_and_icons"));
591
        frameIcon(theme);
592

  
593
        // Se prepara el MainFrame para albergar las extensiones
594
        splashWindow.process(translate("SplashWindow.preparing_workbench"));
595
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
596
        SwingUtilities.invokeAndWait(new Runnable() {
597
            public void run() {
598
                frame.init();
599
                frame.setVisible((boolean) arguments.get("showgui", true));
600
            }
601
        });
602
        ToolsSwingLocator.registerWindowManager(ToolsWindowManager.class);
603

  
604
        // Leer el fichero de persistencia de los plugins
605
        splashWindow.process(translate("SplashWindow.loading_plugin_settings"));
606
        loadPluginsPersistence();
607

  
608
		// Se instalan los controles del skin
609
        // Se inicializan todas las extensiones de todos los plugins
610
        splashWindow.process(translate("SplashWindow.initializing_extensions"));
611
        SwingUtilities.invokeAndWait(new Runnable() {
612
            public void run() {
613
                initializeExtensions();
614
            }
615
        });
616

  
617
        // Se inicializan la extension exclusiva
618
        splashWindow.process(translate("SplashWindow.setting_up_master_extension"));
619
        SwingUtilities.invokeAndWait(new Runnable() {
620
            public void run() {
621
                initializeExclusiveUIExtension();
622
            }
623
        });
624
        frame.setClassesExtensions(classesExtensions);
625

  
626
        // Se instalan los controles de las extensiones de los plugins
627
        message(translate("SplashWindow.installing_extensions_controls"));
628
        SwingUtilities.invokeAndWait(new Runnable() {
629
            public void run() {
630
                installPluginsControls();
631
            }
632
        });
633

  
634
        // Se instalan los menus de las extensiones de los plugins
635
        message(translate("SplashWindow.installing_extensions_menus"));
636
        SwingUtilities.invokeAndWait(new Runnable() {
637
            public void run() {
638
                installPluginsMenus();
639
            }
640
        });
641

  
642
        message(translate("SplashWindow.initializing_server_data_persistence"));
643
        ServerDataPersistence.registerPersistence();
644

  
645
        // Se instalan las etiquetas de las extensiones de los plugins
646
        message(translate("SplashWindow.installing_extensions_labels"));
647
        SwingUtilities.invokeAndWait(new Runnable() {
648
            public void run() {
649
                installPluginsLabels();
650
            }
651
        });
652

  
653
        // Se muestra el frame principal
654
        message(translate("creating_main_window"));
655
        frame.setVisible(true);
656
        frame.setCursor(Cursor.WAIT_CURSOR);
657

  
658
		// Definimos un KeyEventDispatcher global para que las extensiones
659
        // puedan registrar sus "teclas rapidas".
660
        message(translate("SplashWindow.initializing_accelerator_keys"));
661
        GlobalKeyEventDispatcher keyDispatcher = GlobalKeyEventDispatcher.getInstance();
662
        KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(keyDispatcher);
663

  
664
        message(translate("SplashWindow.enable_controls"));
665
        SwingUtilities.invokeAndWait(new Runnable() {
666
            public void run() {
667
                try {
668
                    frame.enableControls();
669
                } catch (Throwable th) {
670
                    logger.warn("Problems enabling controls", th);
671
                }
672
            }
673
        });
674

  
675
        // Se ejecuta el postInitialize
676
        message(translate("SplashWindow.post_initializing_extensions"));
677
        SwingUtilities.invokeAndWait(new Runnable() {
678
            public void run() {
679
                postInitializeExtensions();
680
            }
681
        });
682

  
683
        message(translate("SplashWindow.enable_controls"));
684
        SwingUtilities.invokeAndWait(new Runnable() {
685
            public void run() {
686
                try {
687
                    frame.enableControls();
688
                } catch (Throwable th) {
689
                    logger.warn("Problems enabling controls", th);
690
                }
691
            }
692
        });
693

  
694
        splashWindow.close();
695

  
696
        frame.setCursor(Cursor.DEFAULT_CURSOR);
697

  
698
        if (launcherrors != null) {
699
            NotificationManager.addError(launcherrors);
700
        }
701
        if( !arguments.contains("showgui", "false") ) {
702
            org.apache.log4j.Logger.getRootLogger().addAppender(
703
                    new NotificationAppender());
704
        }
705

  
706
        /*
707
         * Executes additional tasks required by plugins
708
         */
709
        PluginsLocator.getManager().executeStartupTasks();
710

  
711
    }
712

  
713
    private void initializeInstallerManager() {
714
        PluginsManager pluginmgr = PluginsLocator.getManager();
715
        InstallerManager installerManager = InstallerLocator.getInstallerManager();
716

  
717
            //
718
        // Configure repository of plugins
719
        //
720
        List<File> folders = pluginmgr.getPluginsFolders();
721
        for (File folder : folders) {
722
            installerManager.addLocalAddonRepository(folder, "plugin");
723
        }
724
        installerManager.setDefaultLocalAddonRepository(folders.get(0), "plugin");
725

  
726
            //
727
        // Configure repository of iconsets
728
        //
729
        IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
730
        FolderSet fset = iconManager.getRepository();
731
        Iterator<FolderSet.FolderEntry> it = fset.iterator();
732
        boolean first = true;
733
        while (it.hasNext()) {
734
            FolderEntry entry = it.next();
735
            installerManager.addLocalAddonRepository(entry.getFolder(), "iconset");
736
            if (first) {
737
                first = false;
738
                installerManager.setDefaultLocalAddonRepository(entry.getFolder(), "iconset");
739
            }
740
        }
741

  
742
    }
743

  
744
    private void message(final String msg) {
745
        if (!SwingUtilities.isEventDispatchThread()) {
746
            try {
747
                SwingUtilities.invokeAndWait(new Runnable() {
748
                    public void run() {
749
                        message(msg);
750
                    }
751
                });
752
            } catch (Exception e) {
753
                logger.info(msg);
754
                logger.warn("Error showing message.", e);
755
            }
756
            return;
757
        }
758
        if (splashWindow.isVisible()) {
759
            splashWindow.process(msg);
760
        }
761
        if (frame.isVisible()) {
762
            frame.message(msg, JOptionPane.INFORMATION_MESSAGE);
763
        }
764
    }
765

  
766
    private void initializeLibraries() {
767
        List<ClassLoader> classLoaders = new ArrayList<ClassLoader>(
768
                pluginsOrdered.size() + 1);
769
        classLoaders.add(getClass().getClassLoader());
770
        Iterator<String> iter = pluginsOrdered.iterator();
771

  
772
        logger.info("Initializing plugins libraries: ");
773
        while (iter.hasNext()) {
774
            String pName = (String) iter.next();
775
            PluginServices ps = (PluginServices) pluginsServices.get(pName);
776
            logger.info("Initializing plugin libraries (" + pName + ")");
777
            classLoaders.add(ps.getClassLoader());
778
        }
779

  
780
		// Create the libraries initializer and
781
        // initialize the plugin libraries
782
        new DefaultLibrariesInitializer(classLoaders
783
                .toArray(new ClassLoader[classLoaders.size()]))
784
                .fullInitialize(true);
785

  
786
        // Remove them all, we don't need them anymore
787
        classLoaders.clear();
788
        classLoaders = null;
789
    }
790

  
791
    /**
792
     * @param args
793
     * @throws IOException
794
     * @throws ConfigurationException
795
     */
796
    private void initializeApp(String[] args, String applicationClasifier) throws IOException, ConfigurationException {
797
        if (args.length < 1) {
798
            appName = "gvSIG"; // Nombre de aplicacion por defecto es "gvSIG"
799
        } else {
800
            appName = args[0];
801
        }
802
        // Hacemos visibles los argumentos como una propiedad est�tica
803
        // de plugin services para quien lo quiera usar (por ejemplo, para
804
        // cargar un proyecto por l�nea de comandos)
805
        PluginServices.setArguments(args);
806

  
807
        getOrCreateConfigFolder();
808
        configureLogging(appName, applicationClasifier);
809
        if (!validJVM()) {
810
            logger.error("Not a valid JRE. Exit application.");
811
            System.exit(-1);
812
        }
813

  
814
        ToolsLocator.registerDefaultToolsLibraries();
815

  
816
        ToolsLocator.getFoldersManager().cleanTemporaryFiles();
817

  
818
        if (args.length < 2) {
819
            loadAndamiConfig("gvSIG/extensiones"); // Valor por defecto
820
        } else {
821
            loadAndamiConfig(args[1]);
822
        }
823

  
824
        configureLocales();
825

  
826
        logger.info("Configure LookAndFeel");
827
        configureLookAndFeel();
828
    }
829

  
830
    /**
831
     *
832
     */
833
    private void configureLookAndFeel() {
834
        // Se pone el lookAndFeel
835
        try {
836
            String lookAndFeel = getAndamiConfig().getLookAndFeel();
837
            if (lookAndFeel == null) {
838
                lookAndFeel = getDefaultLookAndFeel();
839
            }
840
            UIManager.setLookAndFeel(lookAndFeel);
841
        } catch (Exception e) {
842
            logger.warn(Messages.getString("Launcher.look_and_feel"), e);
843
        }
844
        FontUtils.initFonts();
845
    }
846

  
847
    /**
848
     * @param args
849
     * @throws ConfigurationException
850
     */
851
    private void loadAndamiConfig(String pluginFolder)
852
            throws ConfigurationException {
853
        andamiConfigPath = appHomeDir + File.separator + "andami-config.xml";
854
        andamiConfigFromXML(andamiConfigPath);
855
        andamiConfig.setPluginsDirectory(pluginFolder);
856
    }
857

  
858
    /**
859
     *
860
     */
861
    private void getOrCreateConfigFolder() {
862
        // Create application configuration folder
863
        appHomeDir = System.getProperty(appName + ".home");
864
        if (appHomeDir == null) {
865
            appHomeDir = System.getProperty("user.home");
866
        }
867

  
868
        appHomeDir += File.separator + appName;
869
        File parent = new File(appHomeDir);
870
        parent.mkdirs();
871
    }
872

  
873
    /**
874
     * @param args
875
     * @throws IOException
876
     */
877
    private void configureLogging(String appName, String applicationClasifier) throws IOException {
878
        // Configurar el log4j
879

  
880
        String pathname;
881
        if (StringUtils.isBlank(applicationClasifier)) {
882
            pathname = appHomeDir + File.separator + appName + ".log";
883
        } else {
884
            pathname = appHomeDir + File.separator + appName + "-" + applicationClasifier + ".log";
885
        }
886
        URL config = Launcher.class.getClassLoader().getResource("log4j.properties");
887
        if (config == null) {
888
            config = Launcher.class.getClassLoader().getResource("default-log4j/log4j.properties");
889
        }
890
        PropertyConfigurator.configure(config);
891
        PatternLayout l = new PatternLayout("%p %r %t %C - %m%n");
892
        RollingFileAppender fa = new RollingFileAppender(l, pathname, false);
893
        fa.setMaxFileSize("512KB");
894
        fa.setMaxBackupIndex(3);
895
        
896
        org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
897
        if( !(boolean) arguments.get("consolelogger", true) ) {
898
            rootLogger.removeAppender("stdout");
899
        }
900
        rootLogger.addAppender(fa);
901
        
902
        logger.info("Loadded log4j.properties from " + config.toString());
903
        if (StringUtils.isBlank(applicationClasifier)) {
904
            logger.info("Application " + appName);
905
        } else {
906
            logger.info("Application " + appName + "-" + applicationClasifier);
907
        }
908
    }
909

  
910
    public static String getApplicationName() {
911
        return appName;
912
    }
913

  
914
    private class NotificationAppender extends AppenderSkeleton {
915

  
916
        @Override
917
        protected void append(LoggingEvent event) {
918
            if (event.getLevel() == org.apache.log4j.Level.ERROR
919
                    || event.getLevel() == org.apache.log4j.Level.FATAL) {
920

  
921
                Throwable th = null;
922
                ThrowableInformation thi = event.getThrowableInformation();
923
                if (thi != null) {
924
                    th = thi.getThrowable();
925
                }
926
                NotificationManager.dispatchError(event.getRenderedMessage(), th);
927
                return;
928
            }
929
			// if (event.getLevel() == org.apache.log4j.Level.WARN) {
930
            // NotificationManager.dispatchWarning(event.getRenderedMessage(),
931
            // null);
932
            // return;
933
            // }
934
        }
935

  
936
        @Override
937
        public void close() {
938
            // TODO Auto-generated method stub
939

  
940
        }
941

  
942
        @Override
943
        public boolean requiresLayout() {
944
            // TODO Auto-generated method stub
945
            return false;
946
        }
947

  
948
    }
949

  
950
    /**
951
     * Return the directory applicaction is installed.
952
     */
953
    public static String getApplicationDirectory() {
954
        return getApplicationFolder().getAbsolutePath();
955
    }
956

  
957
    public static File getApplicationFolder() {
958
        // TODO: check if there is a better way to handle this
959
        return new File(System.getProperty("user.dir"));
960
    }
961

  
962
    private void registerIcons() {
963
        IconTheme theme = PluginServices.getIconTheme();
964
        ClassLoader loader = Launcher.class.getClassLoader();
965

  
966
        String[][] icons = {
967
            // MultiSplashWindow
968
            {"main", "splash-default"},
969
            // NewStatusBar
970
            {"main", "statusbar-info"},
971
            {"main", "statusbar-warning"},
972
            {"main", "statusbar-error"}
973
        };
974
        for (int i = 0; i < icons.length; i++) {
975
            try {
976
                IconThemeHelper.registerIcon(icons[i][0], icons[i][1], Launcher.class);
977
            } catch (Exception e) {
978
                logger.info("Can't register icon '" + icons[i][0] + "' (" + icons[i][1] + ").");
979
            }
980
        }
981
        theme.setDefaultIcon(loader.getResource("images/main/default-icon.png"));
982
    }
983

  
984
    private Properties loadProperties(File f) {
985
        FileInputStream fin = null;
986
        Properties p = null;
987
        try {
988
            fin = new FileInputStream(f);
989
            p = new Properties();
990
            p.load(fin);
991
        } catch (IOException ex) {
992
            // Do nothing
993
        }
994
        return p;
995
    }
996

  
997
    /**
998
     * Obtiene la personalizaci�n de los iconos, splash, fondo y el nombre de
999
     * la aplicacion.
1000
     *
1001
     * @return Theme
1002
     */
1003
    private Theme getTheme(String pluginsDirectory) {
1004
        File infoFile = new File(Launcher.getApplicationFolder(), "package.info");
1005
        File themeFile = null;
1006
        List<Theme> themes = new ArrayList<Theme>();
1007

  
1008
        // Try to get theme from args
1009
        String name = PluginServices.getArgumentByName("andamiTheme");
1010
        if (name != null) {
1011
            themeFile = new File(name);
1012
            logger.info("search andami-theme in {}", themeFile.getAbsolutePath());
1013
            if (themeFile.exists()) {
1014
                Theme theme = new Theme(loadProperties(infoFile));
1015
                theme.readTheme(themeFile);
1016
                logger.info("andami-theme found in {}", themeFile.getAbsolutePath());
1017
                return theme;
1018
            }
1019
        }
1020

  
1021
        // Try to get theme from a plugin
1022
        File pluginsDir = new File(pluginsDirectory);
1023
        if (!pluginsDir.isAbsolute()) {
1024
            pluginsDir = new File(getApplicationFolder(), pluginsDirectory);
1025
        }
1026
        if (pluginsDir.exists()) {
1027
            logger.info("search andami-theme in plugins folder '" + pluginsDir.getAbsolutePath() + "'.");
1028
            File[] pluginDirs = pluginsDir.listFiles();
1029
            if (pluginDirs.length > 0) {
1030
                for (int i = 0; i < pluginDirs.length; i++) {
1031
                    File pluginThemeFile = new File(pluginDirs[i],
1032
                            "theme" + File.separator + "andami-theme.xml");
1033
                    if (pluginThemeFile.exists()) {
1034
                        Theme theme = new Theme(loadProperties(infoFile));
1035
                        theme.readTheme(pluginThemeFile);
1036
                        themes.add(theme);
1037
                    }
1038
                }
1039
            }
1040
        }
1041

  
1042
        // Try to get theme from dir gvSIG in user home
1043
        themeFile = new File(getAppHomeDir(), "theme" + File.separator
1044
                + "andami-theme.xml");
1045
        logger.info("search andami-theme in user's home {}", themeFile
1046
                .getAbsolutePath());
1047
        if (themeFile.exists()) {
1048
            Theme theme = new Theme(loadProperties(infoFile));
1049
            theme.readTheme(themeFile);
1050
            themes.add(theme);
1051
        }
1052

  
1053
        // Try to get theme from the instalation dir of gvSIG.
1054
        themeFile = new File(getApplicationDirectory(), "theme"
1055
                + File.separator + "andami-theme.xml");
1056
        logger.info("search andami-theme in installation folder {}", themeFile
1057
                .getAbsolutePath());
1058
        if (themeFile.exists()) {
1059
            Theme theme = new Theme(loadProperties(infoFile));
1060
            theme.readTheme(themeFile);
1061
            themes.add(theme);
1062
        }
1063

  
1064
        Collections.sort(themes, new Comparator<Theme>() {
1065
            public int compare(Theme t1, Theme t2) {
1066
                return t2.getPriority() - t1.getPriority();
1067
            }
1068
        });
1069
        if (logger.isInfoEnabled()) {
1070
            logger.info("Found andami-themes in:");
1071
            for (Theme theme : themes) {
1072
                logger.info(" - " + theme.getPriority() + ", " + theme.getSource().getAbsolutePath());
1073
            }
1074
        }
1075
        Theme theme = themes.get(0);
1076
        logger.info("Using theme '" + theme.getSource() + "'.");
1077
        return theme;
1078
    }
1079

  
1080
    /**
1081
     * Establece los datos que tengamos guardados respecto de la configuracion
1082
     * del proxy.
1083
     */
1084
    private void configureProxy() {
1085
        String host = prefs.get("firewall.http.host", "");
1086
        String port = prefs.get("firewall.http.port", "");
1087

  
1088
        System.getProperties().put("http.proxyHost", host);
1089
        System.getProperties().put("http.proxyPort", port);
1090

  
1091
        // Ponemos el usuario y clave del proxy, si existe
1092
        String proxyUser = prefs.get("firewall.http.user", null);
1093
        String proxyPassword = prefs.get("firewall.http.password", null);
1094
        if (proxyUser != null) {
1095
            System.getProperties().put("http.proxyUserName", proxyUser);
1096
            System.getProperties().put("http.proxyPassword", proxyPassword);
1097

  
1098
            Authenticator.setDefault(new ProxyAuth(proxyUser, proxyPassword));
1099
        } else {
1100
            Authenticator.setDefault(new ProxyAuth("", ""));
1101
        }
1102
    }
1103

  
1104
    /**
1105
     * Recupera la geometr�a (tama�o, posic�n y estado) de la ventana
1106
     * principal de Andami. TODO Pendiente de ver como se asigna un
1107
     * pluginServices para el launcher.
1108
     *
1109
     * @author LWS
1110
     */
1111
    private void restoreMDIStatus(XMLEntity xml) {
1112
        if (xml == null) {
1113
            xml = new XMLEntity();
1114
        }
1115
        // ====================================
1116
        // restore frame size
1117
        Dimension sz = new Dimension(
1118
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[0],
1119
                MainFrame.MAIN_FRAME_SIZE_DEFAULT[1]);
1120
        if (xml.contains(MainFrame.MAIN_FRAME_SIZE)) {
1121
            int[] wh = xml.getIntArrayProperty(MainFrame.MAIN_FRAME_SIZE);
1122
            sz = new Dimension(wh[0], wh[1]);
1123
        }
1124
        frame.setSize(sz);
1125
        // ==========================================
1126
        // restore frame location
1127
        Point pos = new Point(
1128
                MainFrame.MAIN_FRAME_POS_DEFAULT[0],
1129
                MainFrame.MAIN_FRAME_POS_DEFAULT[1]);
1130
        if (xml.contains(MainFrame.MAIN_FRAME_POS)) {
1131
            int[] xy = xml.getIntArrayProperty(MainFrame.MAIN_FRAME_POS);
1132
            pos = new Point(xy[0], xy[1]);
1133
        }
1134
        frame.setLocation(pos);
1135
        // =============================================
1136
        // restore frame state (Maximized, minimized, etc);
1137
        int state = MainFrame.MAIN_FRAME_EXT_STATE_DEFAULT;
1138
        if (xml.contains(MainFrame.MAIN_FRAME_EXT_STATE)) {
1139
            state = xml.getIntProperty(MainFrame.MAIN_FRAME_EXT_STATE);
1140
        }
1141
        frame.setExtendedState(state);
1142
    }
1143

  
1144
    private XMLEntity saveMDIStatus() {
1145
        XMLEntity xml = new XMLEntity();
1146
        // save frame size
1147
        int[] wh = new int[2];
1148
        wh[0] = frame.getWidth();
1149
        wh[1] = frame.getHeight();
1150
        xml.putProperty(MainFrame.MAIN_FRAME_SIZE, wh);
1151
        // save frame location
1152
        int[] xy = new int[2];
1153
        xy[0] = frame.getX();
1154
        xy[1] = frame.getY();
1155
        xml.putProperty(MainFrame.MAIN_FRAME_POS, xy);
1156
        // save frame status
1157
        xml.putProperty(MainFrame.MAIN_FRAME_EXT_STATE,
1158
                frame.getExtendedState());
1159
        return xml;
1160
    }
1161

  
1162
    private boolean validJVM() {
1163
        if (!SystemUtils.isJavaVersionAtLeast(JavaVersion.JAVA_1_6)) {
1164
            logger.warn("gvSIG requires Java version 1.6 or higher.");
1165
            logger.warn("The Java HOME is '" + SystemUtils.getJavaHome().getAbsolutePath() + "'.");
1166
            return false;
1167
        }
1168
        if (SystemUtils.isJavaAwtHeadless()) {
1169
            logger.warn("The java used by gvSIG does not contain the libraries for access to the graphical interface (AWT-headless)");
1170
            logger.warn("The Java HOME is '" + SystemUtils.getJavaHome().getAbsolutePath() + "'.");
1171
            return false;
1172
        }
1173
        return true;
1174
    }
1175

  
1176
    private void loadPluginsPersistence() throws ConfigurationException {
1177
        XMLEntity entity = persistenceFromXML();
1178

  
1179
        for (int i = 0; i < entity.getChildrenCount(); i++) {
1180
            XMLEntity plugin = entity.getChild(i);
1181
            String pName = plugin
1182
                    .getStringProperty("com.iver.andami.pluginName");
1183

  
1184
            if (pName.compareToIgnoreCase("com.iver.cit.gvsig") == 0) {
1185
                pName = "org.gvsig.app";
1186
            }
1187
            if (pluginsServices.get(pName) != null) {
1188
                ((PluginServices) pluginsServices.get(pName))
1189
                        .setPersistentXML(plugin);
1190
            } else {
1191
                if (pName.startsWith("Andami.Launcher")) {
1192
                    restoreMDIStatus(plugin);
1193
                }
1194
            }
1195
        }
1196
    }
1197

  
1198
    /**
1199
     * Salva la persistencia de los plugins.
1200
     *
1201
     * @author LWS
1202
     */
1203
    private void savePluginPersistence() {
1204
        Iterator<String> i = pluginsConfig.keySet().iterator();
1205

  
1206
        XMLEntity entity = new XMLEntity();
1207

  
1208
        while (i.hasNext()) {
1209
            String pName = i.next();
1210
            PluginServices ps = (PluginServices) pluginsServices.get(pName);
1211
            XMLEntity ent = ps.getPersistentXML();
1212

  
1213
            if (ent != null) {
1214
                ent.putProperty("com.iver.andami.pluginName", pName);
1215
                entity.addChild(ent);
1216
            }
1217
        }
1218
        XMLEntity ent = saveMDIStatus();
1219
        if (ent != null) {
1220
            ent.putProperty("com.iver.andami.pluginName", "Andami.Launcher");
1221
            entity.addChild(ent);
1222
        }
1223
        try {
1224
            persistenceToXML(entity);
1225
        } catch (ConfigurationException e1) {
1226
            this
1227
                    .addError(
1228
                            Messages
1229
                            .getString("Launcher.Se_produjo_un_error_guardando_la_configuracion_de_los_plugins"),
1230
                            e1);
1231
        }
1232
    }
1233

  
1234
    private void installPluginsLabels() {
1235
        Iterator<String> i = pluginsConfig.keySet().iterator();
1236

  
1237
        while (i.hasNext()) {
1238
            String name = i.next();
1239
            PluginConfig pc = pluginsConfig.get(name);
1240
            PluginServices ps = (PluginServices) pluginsServices.get(name);
1241

  
1242
            LabelSet[] ls = pc.getLabelSet();
1243

  
1244
            for (int j = 0; j < ls.length; j++) {
1245
                PluginClassLoader loader = ps.getClassLoader();
1246

  
1247
                try {
1248
                    Class clase = loader.loadClass(ls[j].getClassName());
1249
                    frame.setStatusBarLabels(clase, ls[j].getLabel());
1250
                } catch (Throwable e) {
1251
                    this.addError(
1252
                            Messages.getString("Launcher.labelset_class"), e);
1253
                }
1254
            }
1255
        }
1256
    }
1257

  
1258
    private String configureSkin(XMLEntity xml, String defaultSkin) {
1259
        if (defaultSkin == null) {
1260
            for (int i = 0; i < xml.getChildrenCount(); i++) {
1261
                if (xml.getChild(i).contains("Skin-Selected")) {
1262
                    String className = xml.getChild(i).getStringProperty(
1263
                            "Skin-Selected");
1264
                    return className;
1265
                }
1266
            }
1267
        }
1268
        // return "com.iver.core.mdiManager.NewSkin";
1269
        return defaultSkin;
1270
    }
1271

  
1272
    private void fixSkin(SkinExtension skinExtension,
1273
            PluginClassLoader pluginClassLoader) throws MDIManagerLoadException {
1274
        // now insert the skin selected.
1275
        MDIManagerFactory.setSkinExtension(skinExtension, pluginClassLoader);
1276
		// MDIManagerFactory.setSkinExtension(se,
1277
        // ps.getClassLoader());
1278

  
1279
        Class<? extends IExtension> skinClass;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff