Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / IntializeApplicationExtension.java @ 9900

History | View | Annotate | Download (4.33 KB)

1
package com.iver.cit.gvsig;
2

    
3
import java.io.BufferedReader;
4
import java.io.File;
5
import java.io.IOException;
6
import java.io.InputStream;
7
import java.io.InputStreamReader;
8
import java.io.Reader;
9
import java.io.StringWriter;
10
import java.security.KeyException;
11
import java.util.Properties;
12

    
13
import org.apache.log4j.Logger;
14

    
15
import com.iver.andami.Launcher;
16
import com.iver.andami.plugins.Extension;
17
import com.iver.cit.gvsig.fmap.layers.FLayerFileVectorial;
18
import com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial;
19
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
20
import com.iver.utiles.extensionPoints.ExtensionPoint;
21
import com.iver.utiles.extensionPoints.ExtensionPoints;
22
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
23

    
24
public class IntializeApplicationExtension extends Extension {
25
        private ExtensionPoints extensionPoints = 
26
                ExtensionPointsSingleton.getInstance();
27
        private static Logger logger = Logger.getLogger("gvSIG");
28
        
29
        public void initialize() {
30
                
31
                addToLogInfo();
32
                //this.extensionPoints.add("Layers","FileVectorial", FLayerFileVectorial.class);
33
                this.extensionPoints.add("Layers",FLayerFileVectorial.class.getName(), FLayerFileVectorial.class);
34
                
35
                //this.extensionPoints.add("Layers","GenericVectorial", FLayerGenericVectorial.class);
36
                this.extensionPoints.add("Layers",FLayerGenericVectorial.class.getName(), FLayerGenericVectorial.class);
37
                try {
38
                        ((ExtensionPoint)this.extensionPoints.get("Layers")).addAlias(FLayerFileVectorial.class.getName(), "FileVectorial");
39
                        ((ExtensionPoint)this.extensionPoints.get("Layers")).addAlias(FLayerGenericVectorial.class.getName(), "GenericVectorial");
40
                } catch (KeyException e) {
41
                        // TODO Auto-generated catch block
42
                        e.printStackTrace();
43
                }
44
        }
45

    
46
        public void execute(String actionCommand) {
47

    
48
        }
49

    
50
        public boolean isEnabled() {
51
                return false;
52
        }
53

    
54
        public boolean isVisible() {
55
                return false;
56
        }
57
        
58
        private void addToLogInfo() {
59
                String info[] = this.getStringInfo().split("\n");
60
                for (int i=0;i< info.length;i++) {
61
                        logger.info(info[i]);
62
                }
63
        }
64
        
65
        public String getStringInfo() {
66
                StringWriter writer = new StringWriter();
67
                String andamiPath;
68
                String extensionsPath;
69
                String jaiVersion;
70
                
71
                Properties props = System.getProperties();
72
                
73
                try {
74
                        try {
75
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getCanonicalPath();
76
                        } catch (IOException e) {
77
                                andamiPath = (new File(Launcher.class.getResource(".").getFile() + File.separator + ".." + File.separator + ".." + File.separator +"..")).getAbsolutePath();
78
                        }
79
                } catch (Exception e1) {
80
                        andamiPath = (String)props.get("user.dir");
81
                }
82
                try {
83
                        try {
84
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getCanonicalPath();
85
                        } catch (IOException e) {
86
                                extensionsPath = (new File(Launcher.getAndamiConfig().getPluginsDirectory())).getAbsolutePath();                        
87
                        }
88
                } catch (Exception e1) {
89
                        extensionsPath = "???";
90
                }
91
                
92
                        
93
                
94
                writer.write("gvSIG version: " + Version.longFormat() + "\n");
95
                writer.write("    gvSIG app exec path: " + andamiPath + "\n");
96
                writer.write("    gvSIG user app home: " + Launcher.getAppHomeDir() + "\n");
97
                writer.write("    gvSIG extension path: " + extensionsPath + "\n");
98
                writer.write("    gvSIG locale language: " + Launcher.getAndamiConfig().getLocaleLanguage() + "\n");
99
                String osName = props.getProperty("os.name");
100
                writer.write("OS name: " + osName + "\n");
101
                writer.write("    arch:" + props.get("os.arch") + "\n");
102
                writer.write("    version:"+ props.get("os.version") + "\n");
103
                if (osName.startsWith("Linux")) {
104
                        try {
105
                                String[] command = {"lsb_release", "-a"};
106
                                Process p = Runtime.getRuntime().exec(command);
107
                                InputStream is = p.getInputStream();
108
                                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
109
                                String line;
110
                                while ( (line = reader.readLine()) != null)
111
                                        writer.write("    "+line+"\n");
112
                        }
113
                        catch (Exception ex) {
114
                                
115
                        }
116
                }
117
                
118
                writer.write("JAVA vendor: " + props.get("java.vendor") + "\n");
119
                writer.write("    version:" +props.get("java.version")+ "\n");
120
                writer.write("    home: " + props.get("java.home") + "\n");
121
                return writer.toString();
122
        }
123
        
124
        public void terminate() {
125
                
126
                super.terminate();
127
                try {
128
                        LayerFactory.getDataSourceFactory().finalizeThis();
129
                } catch (Exception e) {
130
                        //e.printStackTrace();
131
                }
132
                
133
        }
134
}