Statistics
| Revision:

root / branches / v1_9_0 / extGPE-gvSIG / src / org / gvsig / gpe / GPEReaderExtension.java @ 64

History | View | Annotate | Download (5.38 KB)

1
package org.gvsig.gpe;
2

    
3
import java.io.File;
4
import java.io.FileNotFoundException;
5
import java.util.Iterator;
6
import java.util.Properties;
7

    
8
import org.gvsig.fmap.drivers.gpe.addlayer.GPEFileOpen;
9
import org.gvsig.fmap.drivers.gpe.reader.GMLStreamedVectorialDriver;
10
import org.gvsig.fmap.drivers.gpe.reader.GMLVectorialDriver;
11
import org.gvsig.fmap.drivers.gpe.reader.KMLVectorialDriver;
12
import org.gvsig.gpe.gml.GmlProperties;
13
import org.gvsig.gpe.xml.XmlProperties;
14

    
15
import com.hardcode.driverManager.DriverManager;
16
import com.iver.andami.messages.NotificationManager;
17
import com.iver.andami.plugins.Extension;
18
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
19
import com.iver.utiles.extensionPoints.ExtensionPoints;
20
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
21

    
22
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
23
 *
24
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
25
 *
26
 * This program is free software; you can redistribute it and/or
27
 * modify it under the terms of the GNU General Public License
28
 * as published by the Free Software Foundation; either version 2
29
 * of the License, or (at your option) any later version.
30
 *
31
 * This program is distributed in the hope that it will be useful,
32
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34
 * GNU General Public License for more details.
35
 *
36
 * You should have received a copy of the GNU General Public License
37
 * along with this program; if not, write to the Free Software
38
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
39
 *
40
 * For more information, contact:
41
 *
42
 *  Generalitat Valenciana
43
 *   Conselleria d'Infraestructures i Transport
44
 *   Av. Blasco Ib??ez, 50
45
 *   46010 VALENCIA
46
 *   SPAIN
47
 *
48
 *      +34 963862235
49
 *   gvsig@gva.es
50
 *      www.gvsig.gva.es
51
 *
52
 *    or
53
 *
54
 *   IVER T.I. S.A
55
 *   Salamanca 50
56
 *   46005 Valencia
57
 *   Spain
58
 *
59
 *   +34 963163400
60
 *   dac@iver.es
61
 */
62
/* CVS MESSAGES:
63
 *
64
 * $Id: GPEReaderExtension.java 64 2009-10-12 16:20:02Z groldan $
65
 * $Log$
66
 *
67
 */
68
/**
69
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
70
 */
71
public class GPEReaderExtension extends Extension{
72
        private String parsersFile = "gvSIG" + File.separatorChar + "extensiones" + File.separatorChar +
73
        "org.gvsig.gpe" + File.separatorChar + "parser.properties";
74
        private String driversDir = "gvSIG" + File.separatorChar + "extensiones" + File.separatorChar +
75
        "org.gvsig.gpe" + File.separatorChar + "lib";
76

    
77
        /*
78
         * (non-Javadoc)
79
         * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
80
         */
81
        public void execute(String actionCommand) {
82
                // TODO Auto-generated method stub
83

    
84
        }
85

    
86
        /*
87
         * (non-Javadoc)
88
         * @see com.iver.andami.plugins.IExtension#initialize()
89
         */
90
        public void initialize() {
91
                loadParsers();
92
                loadProperties();
93
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
94
                extensionPoints.add("FileExtendingOpenDialog", "FileOpenGPE", new GPEFileOpen());
95
                //Register the GML driver
96
                DriverManager driverManager = LayerFactory.getDM();
97
                driverManager.addDriver(new File(driversDir), GMLVectorialDriver.DRIVERNAME, GMLVectorialDriver.class);
98
                driverManager.addDriver(new File(driversDir), KMLVectorialDriver.DRIVERNAME, KMLVectorialDriver.class);
99
        driverManager.addDriver(new File(driversDir), GMLStreamedVectorialDriver.DRIVERNAME, GMLStreamedVectorialDriver.class);
100
                //Register the GML driver in the WFS Driver
101
                extensionPoints.add("FMAPWFSDriver","FMAPWFSDriver", GMLVectorialDriver.class);
102
                /*
103
                //PluginServices pluginServices = PluginServices.getPluginServices(GPEXmlParserFactory.class);
104
                PluginServices pluginServices = PluginServices.getPluginServices("com.iver.cit.gvsig");
105
                URL[] urls = pluginServices.getClassLoader().getURLs();
106
                for (int i=0 ; i<urls.length ; i++){
107
                        System.out.println(urls[i]);
108
                }
109
                try {
110
                        pluginServices.getClassLoader().loadClass("org.gvsig.gpe.xml.stream.stax.StaxXmlStreamWriter");
111
                        pluginServices.getClassLoader().loadClass("org.gvsig.gpe.gml.GmlProperties");
112
                        GPEXmlParserFactory.setClassLoader(pluginServices.getClassLoader());
113
                        GPEXmlParserFactory.getParser("text/xml; subtype=gml/2.1.0", new FileInputStream("/home/jpiera/output.gml"));
114
                } catch (XmlStreamException e) {
115
                        e.printStackTrace();
116
                } catch (FileNotFoundException e) {
117
                        e.printStackTrace();
118
                } catch (ClassNotFoundException e) {
119
                        // TODO Auto-generated catch block
120
                        e.printStackTrace();
121
                }
122
                */
123
        }
124

    
125
        private void loadProperties() {
126
                loadProperties(new GPEProperties().getProperties());
127
                loadProperties(new XmlProperties().getProperties());
128
                loadProperties(new GmlProperties().getProperties());                
129
        }
130
        
131
        private void loadProperties(Properties properties){
132
                Iterator it = properties.keySet().iterator();
133
                while (it.hasNext()){
134
                        String key = (String)it.next();                                
135
                        GPEDefaults.setProperty(key, properties.get(key));
136
                }                        
137
        }
138

    
139
        private void loadParsers(){
140
                File file = new File(parsersFile);
141
                if (!file.exists()){
142
                        NotificationManager.addWarning("File not found",
143
                                        new FileNotFoundException());
144
                        return;
145
                }
146
                try {
147
                        GPERegister.addParsersFile(file);
148
                } catch (Exception e) {
149
                        NotificationManager.addWarning("GPE parsers file not found",
150
                                        new FileNotFoundException());
151
                }
152
        }
153

    
154
        /*
155
         * (non-Javadoc)
156
         * @see com.iver.andami.plugins.IExtension#isEnabled()
157
         */
158
        public boolean isEnabled() {
159
                return false;
160
        }
161

    
162
        /*
163
         * (non-Javadoc)
164
         * @see com.iver.andami.plugins.IExtension#isVisible()
165
         */
166
        public boolean isVisible() {
167
                return false;
168
        }
169

    
170
}