Revision 587

View differences:

org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.api/src/main/java/org/gvsig/gpe/lib/api/GPEManager.java
2 2
*
3 3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4 4
* of the Valencian Government (CIT)
5
* 
5
*
6 6
* This program is free software; you can redistribute it and/or
7 7
* modify it under the terms of the GNU General Public License
8 8
* as published by the Free Software Foundation; either version 2
9 9
* of the License, or (at your option) any later version.
10
* 
10
*
11 11
* This program is distributed in the hope that it will be useful,
12 12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
* GNU General Public License for more details.
15
* 
15
*
16 16
* You should have received a copy of the GNU General Public License
17 17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19
* MA  02110-1301, USA.
20
* 
20
*
21 21
*/
22 22

  
23 23
/*
24 24
* AUTHORS (In addition to CIT):
25 25
* 2009 {Iver T.I.}   {Task}
26 26
*/
27
 
27

  
28 28
package org.gvsig.gpe.lib.api;
29 29

  
30 30
import java.io.File;
......
42 42
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
43 43
 */
44 44
public interface GPEManager {
45
		
45

  
46 46
    /**
47 47
     * Return true if exists a driver that can open the file
48 48
     * @param uri
......
51 51
     * true if the driver exists
52 52
     */
53 53
    public boolean accept(URI uri);
54
    
54

  
55 55
    /**
56
	 * Method to parse a file. It cannot to throw 
56
	 * Method to parse a file. It cannot to throw
57 57
	 * any exception and it cannot to return any value.
58 58
	 * In a future it could be implemented like a independent
59 59
	 * thread
......
63 63
	 * Application ErrorsHandler
64 64
	 * @param uri
65 65
	 * File to open
66
	 * @throws ParserCreationException 
66
	 * @throws ParserCreationException
67 67
	 * @throws Exception
68 68
	 */
69 69
	public void parse(IGPEContentHandler contents, IGPEErrorHandler errors, URI uri) throws ParserCreationException;
70
	
70

  
71 71
	/**
72
	 * Method to parse a file. It cannot to throw 
72
	 * Method to parse a file. It cannot to throw
73 73
	 * any exception and it cannot to return any value.
74 74
	 * In a future it could be implemented like a independent
75 75
	 * thread
......
79 79
	 * Application ErrorsHandler
80 80
	 * @param file
81 81
	 * File to open
82
	 * @throws ParserCreationException 
82
	 * @throws ParserCreationException
83 83
	 * @throws Exception
84 84
	 */
85 85
	public void parse(IGPEContentHandler contents, IGPEErrorHandler errors, File file) throws ParserCreationException;
86
	
86

  
87 87
	 /**
88
	 * Method to parse a file. It cannot to throw 
88
	 * Method to parse a file. It cannot to throw
89 89
	 * any exception and it cannot to return any value.
90 90
	 * In a future it could be implemented like a independent
91 91
	 * thread
......
95 95
	 * Application ErrorsHandler
96 96
	 * @param uri
97 97
	 * File to open
98
	 * @throws ParserCreationException 
98
	 * @throws ParserCreationException
99 99
	 * @throws Exception
100 100
	 */
101 101
	public void parse(IGPEContentHandlerInmGeom contents, IGPEErrorHandler errors, URI uri) throws ParserCreationException;
102
	
102

  
103 103
	/**
104
	 * Method to parse a file. It cannot to throw 
104
	 * Method to parse a file. It cannot to throw
105 105
	 * any exception and it cannot to return any value.
106 106
	 * In a future it could be implemented like a independent
107 107
	 * thread
......
111 111
	 * Application ErrorsHandler
112 112
	 * @param file
113 113
	 * File to open
114
	 * @throws ParserCreationException 
114
	 * @throws ParserCreationException
115 115
	 * @throws Exception
116 116
	 */
117 117
	public void parse(IGPEContentHandlerInmGeom contents, IGPEErrorHandler errors, File file) throws ParserCreationException;
118
	
118

  
119 119
	/**
120 120
	 * Create a new content writer from a name
121 121
	 * @param name
......
125 125
	 * Application contenHandler usett to throw the parsing events
126 126
	 * @param errorHandler
127 127
	 * Application errror handler used to put errors and warnings
128
	 * @throws GPEWriterHandlerCreationException 	
128
	 * @throws GPEWriterHandlerCreationException
129 129
	 */
130 130
	public IGPEWriterHandler createWriter(String name) throws WriterHandlerCreationException;
131
	
131

  
132 132
	/**
133
	 * Create a new writer from a class name. This method can be used 
133
	 * Create a new writer from a class name. This method can be used
134 134
	 * if the class name is known but, the common method to get a writer
135
	 * is using the mime type.     * 
135
	 * is using the mime type.     *
136 136
	 * @param prefferredImplClassName
137 137
	 * The name of the class that implements {@link GPEWriterHandler}
138 138
	 * @return
......
140 140
	 * @throws WriterHandlerCreationException
141 141
	 * If it is not possible to create a writer
142 142
	 */
143
	public IGPEWriterHandler createWriterByClass(String prefferredImplClassName) throws WriterHandlerCreationException; 
144
		
143
	public IGPEWriterHandler createWriterByClass(String prefferredImplClassName) throws WriterHandlerCreationException;
144

  
145 145
	/**
146 146
	 * Create a new writer from a mime type. Each writer has a method
147 147
	 * named {@link GPEWriterHandler#getFormat()} that returns the mimetype
......
157 157
	 * A writer that can write the mimetype.
158 158
	 * @throws WriterHandlerCreationException
159 159
	 * If it is not possible to create a writer
160
	 * @see 
160
	 * @see
161 161
	 * <a href="http://www.iana.org/assignments/media-types/">http://www.iana.org/assignments/media-types/</a>
162 162
	 */
163 163
	public IGPEWriterHandler createWriterByMimeType(String mimeType) throws WriterHandlerCreationException;
164 164

  
165
	
165

  
166 166
	/**
167
	 * Returns an iterator with the name of all the properties that 
167
	 * Returns an iterator with the name of all the properties that
168 168
	 * has been established.
169 169
	 */
170 170
	public Iterator getKeys();
171
		
172
	
171

  
172

  
173 173
	/**
174 174
	 * Gets a String property
175 175
	 * @param key
......
177 177
	 * @return
178 178
	 */
179 179
	public String getStringProperty(String key);
180
	
180

  
181 181
	/**
182 182
	 * Gets a int property
183 183
	 * @param key
......
186 186
	 * The int property or -1
187 187
	 */
188 188
	public int getIntPropertyProperty(String key);
189
	
189

  
190 190
	/**
191 191
	 * Gets a boolean property. If the property doesn't exist
192 192
	 * it returns false.
......
196 196
	 * The boolean property or false
197 197
	 */
198 198
	public boolean getBooleanProperty(String key);
199
	
199

  
200 200
	/**
201 201
	 * Gets a property
202 202
	 * @param key
......
204 204
	 * @return
205 205
	 */
206 206
	public Object getProperty(String key);
207
	
207

  
208 208
	/**
209 209
	 * Sets a property
210 210
	 * @param key
211 211
	 * @param value
212 212
	 */
213 213
	public void setProperty(String key, Object value);
214

  
215

  
216
	public String getDefaultProjection(File file) throws ParserCreationException;
214 217
}
215 218

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.spi/src/main/java/org/gvsig/gpe/lib/spi/parser/IGPEParser.java
2 2
*
3 3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4 4
* of the Valencian Government (CIT)
5
* 
5
*
6 6
* This program is free software; you can redistribute it and/or
7 7
* modify it under the terms of the GNU General Public License
8 8
* as published by the Free Software Foundation; either version 2
9 9
* of the License, or (at your option) any later version.
10
* 
10
*
11 11
* This program is distributed in the hope that it will be useful,
12 12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
* GNU General Public License for more details.
15
* 
15
*
16 16
* You should have received a copy of the GNU General Public License
17 17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19
* MA  02110-1301, USA.
20
* 
20
*
21 21
*/
22 22

  
23 23
/*
24 24
* AUTHORS (In addition to CIT):
25 25
* 2010 {Iver T.I.}   {Task}
26 26
*/
27
 
27

  
28 28
package org.gvsig.gpe.lib.spi.parser;
29 29

  
30 30
import java.io.InputStream;
......
38 38
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
39 39
 */
40 40
public interface IGPEParser {
41
	
42
		
41

  
42

  
43 43
	/**
44
	 * Method to parse a file. It cannot to throw 
44
	 * Method to parse a file. It cannot to throw
45 45
	 * any exception and it cannot to return any value.
46 46
	 * In a future it could be implemented like a independent
47 47
	 * thread
......
54 54
	 * @throws Exception
55 55
	 */
56 56
	public void parse(IGPEContentHandlerInmGeom contents, IGPEErrorHandler errors, URI uri);
57
		
58
	
57

  
58

  
59 59
	/**
60
	 * Method to parse an InputStream. It cannot to throw 
60
	 * Method to parse an InputStream. It cannot to throw
61 61
	 * any exception and it cannot to return any value.
62 62
	 * In a future it could be implemented like a independent
63 63
	 * thread
......
70 70
	 * @throws Exception
71 71
	 */
72 72
	public void parse(IGPEContentHandlerInmGeom contents, IGPEErrorHandler errors, InputStream is);
73
	
73

  
74 74
	/**
75 75
	 * Return if the driver can open the file
76 76
	 * @param uri
......
86 86
	 * @return
87 87
	 */
88 88
	public String getFormat();
89
	
89

  
90 90
	/**
91 91
	 * @return the contentHandler
92 92
	 */
......
123 123
	 */
124 124
	public void setContentHandler(IGPEContentHandlerInmGeom contentHandler);
125 125

  
126
	/**
127
	 * gets the default parser projection
128
	 * @return
129
	 */
130
	public String getProjection();
131

  
126 132
}
127 133

  
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.lib/org.gvsig.gpe.lib.impl/src/main/java/org/gvsig/gpe/lib/impl/DefaultGPEManager.java
2 2
 *
3 3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4 4
 * of the Valencian Government (CIT)
5
 * 
5
 *
6 6
 * This program is free software; you can redistribute it and/or
7 7
 * modify it under the terms of the GNU General Public License
8 8
 * as published by the Free Software Foundation; either version 2
9 9
 * of the License, or (at your option) any later version.
10
 * 
10
 *
11 11
 * This program is distributed in the hope that it will be useful,
12 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
 * GNU General Public License for more details.
15
 * 
15
 *
16 16
 * You should have received a copy of the GNU General Public License
17 17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19
 * MA  02110-1301, USA.
20
 * 
20
 *
21 21
 */
22 22

  
23 23
/*
......
34 34
import java.util.Iterator;
35 35
import java.util.Properties;
36 36

  
37
import javax.xml.datatype.DatatypeFactory;
38

  
37 39
import org.gvsig.gpe.lib.api.GPEManager;
38 40
import org.gvsig.gpe.lib.api.exceptions.ParserCreationException;
39 41
import org.gvsig.gpe.lib.api.exceptions.WriterHandlerCreationException;
......
46 48
import org.gvsig.gpe.lib.spi.GPEProviderLocator;
47 49
import org.gvsig.gpe.lib.spi.GPEProviderManager;
48 50
import org.gvsig.gpe.lib.spi.parser.IGPEParser;
51
import org.gvsig.tools.dataTypes.DataTypesManager;
52
import org.gvsig.tools.dataTypes.impl.DefaultDataTypesManager;
49 53

  
50 54
/**
51 55
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
......
56 60

  
57 61
	/*
58 62
	 * (non-Javadoc)
59
	 * 
63
	 *
60 64
	 * @see org.gvsig.gpe.GPEManager#getKeys()
61 65
	 */
62 66
	public Iterator getKeys() {
......
65 69

  
66 70
	/*
67 71
	 * (non-Javadoc)
68
	 * 
72
	 *
69 73
	 * @see org.gvsig.gpe.GPEManager#getStringProperty(java.lang.String)
70 74
	 */
71 75
	public String getStringProperty(String key) {
......
78 82

  
79 83
	/*
80 84
	 * (non-Javadoc)
81
	 * 
85
	 *
82 86
	 * @see org.gvsig.gpe.GPEManager#getIntPropertyProperty(java.lang.String)
83 87
	 */
84 88
	public int getIntPropertyProperty(String key) {
......
94 98

  
95 99
	/*
96 100
	 * (non-Javadoc)
97
	 * 
101
	 *
98 102
	 * @see org.gvsig.gpe.GPEManager#getBooleanProperty(java.lang.String)
99 103
	 */
100 104
	public boolean getBooleanProperty(String key) {
......
110 114

  
111 115
	/*
112 116
	 * (non-Javadoc)
113
	 * 
117
	 *
114 118
	 * @see org.gvsig.gpe.GPEManager#getProperty(java.lang.String)
115 119
	 */
116 120
	public Object getProperty(String key) {
......
119 123

  
120 124
	/*
121 125
	 * (non-Javadoc)
122
	 * 
126
	 *
123 127
	 * @see org.gvsig.gpe.GPEManager#setProperty(java.lang.String,
124 128
	 * java.lang.Object)
125 129
	 */
......
189 193
		}
190 194
	}
191 195

  
196

  
197
	public String getDefaultProjection(File file) throws ParserCreationException{
198
        try {
199
            IGPEParser parser = getGPEProviderManager().createParser(file);
200
            return parser.getProjection();
201
        } catch (ParserCreationException e) {
202
            throw new ParserCreationException(e);
203
        }
204
	}
192 205
}
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.prov/org.gvsig.gpe.prov.gml/src/main/java/org/gvsig/gpe/prov/gml/parser/GPEDefaultGmlParser.java
107 107
	private IXmlStreamReader fileParser = null;
108 108
	private IBindingProfile profile = null;
109 109
	protected QNameComparator qNameComparator = null;
110
	
110

  
111 111
	/***********************************************************************************************
112 112
	 * <GPEGmlParser> Constructor Method
113 113
	 **********************************************************************************************/
......
117 117

  
118 118
	/***********************************************************************************************
119 119
	 * <getFormats> Returns the file extensions that are accepted to GML Parser
120
	 * 
120
	 *
121 121
	 * @return String[] Accepted Extensions
122 122
	 **********************************************************************************************/
123 123
	public String[] getFormats() {
......
130 130

  
131 131
	/***********************************************************************************************
132 132
	 * <accept> Returns true if the file is a gml file and the parser has to parse it
133
	 * 
133
	 *
134 134
	 * @param URI uri
135 135
	 * @return boolean
136 136
	 **********************************************************************************************/
......
142 142
		}
143 143
		return false;
144 144
	}
145
	
146
	
147 145

  
146

  
147

  
148 148
	public boolean accept(File file) {
149 149
		if ((file.getPath().toUpperCase().endsWith("GML"))
150 150
				|| (file.getPath().toUpperCase().endsWith("XML"))
......
156 156

  
157 157
	/***********************************************************************************************
158 158
	 * <createInputStream> Creates an InputStream from a file.
159
	 * 
159
	 *
160 160
	 * @param File file
161 161
	 * @return FileInputStream
162 162
	 **********************************************************************************************/
......
166 166

  
167 167
	/***********************************************************************************************
168 168
	 * <initParse> Starts to parse the file.
169
	 * 
169
	 *
170 170
	 * @throws XmlStreamException
171 171
	 * @throws GPEXmlEmptyFileException
172 172
	 **********************************************************************************************/
......
179 179
		}
180 180
		try{
181 181
			getProfile().getFeatureCollectionBinding().
182
			parse(getParser(), this);		
182
			parse(getParser(), this);
183 183
		} catch (IOException e) {
184 184
			getErrorHandler().addError(e);
185
		}	
185
		}
186 186
	}
187 187

  
188 188
	public IXmlStreamReader getFileParser() {
......
224 224
	public IBindingProfile getProfile() {
225 225
		return profile;
226 226
	}
227
	
227

  
228 228
	   /**
229 229
     * Utility method just to access to the QName comparator
230 230
     * @return the comparator used to comare QName's
......
232 232
    public QNameComparator getQNameComparator(){
233 233
        return qNameComparator;
234 234
    }
235

  
236
    /**
237
     * gets the default parser projection
238
     * @return
239
     */
240
    public String getProjection(){
241
        return null;
242
    }
235 243
}
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.prov/org.gvsig.gpe.prov.kml/src/main/java/org/gvsig/gpe/prov/kml/parser/GPEDeafultKmlParser.java
93 93
 *
94 94
 */
95 95
/**
96
 * This is a KML parser. This class must be registered in 
96
 * This is a KML parser. This class must be registered in
97 97
 * the GPE register to read and write KML/KMZ files.
98 98
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
99 99
 */
100 100
public abstract class GPEDeafultKmlParser extends GPEXmlParser {
101
    private final static String DEFAULT_CRS="EPSG:4326";
101 102
    private IBindingProfile profile = null;
102 103
    private Object layer = null;
103 104
    protected QNameComparator qNameComparator = null;
......
125 126
     * @param profile the profile to set
126 127
     */
127 128
    public void setProfile(IBindingProfile profile) {
128
        this.profile = profile;		
129
    }	
129
        this.profile = profile;
130
    }
130 131

  
131 132
    public GPEDeafultKmlParser() {
132 133
        super();
......
141 142
        try {
142 143
            String namespace = getProfile().getHeaderBinding().parse(getParser(),this);
143 144
            boolean endFeature = false;
144
            int currentTag;		
145
            int currentTag;
145 146

  
146 147
            IQName tag = getParser().getName();
147 148
            currentTag = getParser().getEventType();
......
149 150
            XMLAttributesIterator attributesIterator = new XMLAttributesIterator(getParser());
150 151

  
151 152
            boolean hasOnlyPlacemarks = false;
152
            
153

  
153 154
            while (!endFeature){
154 155
                switch(currentTag){
155 156
                case IXmlStreamReader.START_ELEMENT:
......
163 164
                            hasOnlyPlacemarks = true;
164 165
                        }
165 166
                        Object feature = getProfile().getPlaceMarketBinding().parse(getParser(), this);
166
                        getContentHandler().addFeatureToLayer(feature, layer);			
167
                        getContentHandler().addFeatureToLayer(feature, layer);
167 168
                    }
168 169
                    break;
169 170
                case IXmlStreamReader.END_DOCUMENT:
170 171
                    endFeature = true;
171
                    break;					
172
                    break;
172 173
                }
173
                if (!endFeature){					
174
                if (!endFeature){
174 175
                    currentTag = getParser().next();
175 176
                    tag = getParser().getName();
176 177
                }
177 178
            }
178 179
            if ((layer != null) && (hasOnlyPlacemarks)){
179 180
                getContentHandler().endLayer(layer);
180
            }			
181
            }
181 182
        } catch (KmlHeaderParseException e) {
182 183
            getErrorHandler().addError(e);
183 184
        } catch (BaseException e) {
......
186 187
            getErrorHandler().addError(e);
187 188
        } catch (IOException e) {
188 189
            getErrorHandler().addError(e);
189
        }		
190
        }
190 191
    }
191 192

  
193
    /**
194
     * gets the default parser projection
195
     * @return
196
     */
197
    public String getProjection(){
198
        return DEFAULT_CRS;
199
    }
200

  
192 201
}
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.prov/org.gvsig.gpe.prov.kml/src/main/java/org/gvsig/gpe/prov/kml/parser/GPEKmz2_1_Parser.java
12 12
import java.util.zip.ZipFile;
13 13
import java.util.zip.ZipInputStream;
14 14

  
15
import org.apache.commons.io.FilenameUtils;
15 16
import org.gvsig.gpe.prov.kml.exceptions.KmlException;
16 17
import org.gvsig.gpe.prov.kml.parser.profiles.Kml2_1_BindingProfile;
17 18
import org.gvsig.gpe.prov.xml.utils.NamespaceAwareComparator;
......
93 94
	 * (non-Javadoc)
94 95
	 * @see org.gvsig.gpe.parser.GPEParser#getFormat()
95 96
	 */
96
	public String getFormat() {		
97
		return "application/zip; subtype=kml/2.1";		
97
	public String getFormat() {
98
		return "application/zip; subtype=kml/2.1";
98 99
	}
99
	
100

  
100 101
	/**
101 102
	 * It creates an InputStream. The Kml file can have the
102 103
	 * KML or the KMZ extension
......
112 113
			while((entry = zis.getNextEntry()) != null){
113 114
				if (!entry.isDirectory()){
114 115
					ZipFile fz = new ZipFile(file);
115
					return fz.getInputStream(entry);
116
					if ( FilenameUtils.getExtension(entry.getName()).equalsIgnoreCase("KML") ){
117
					    return fz.getInputStream(entry);
118
					}
116 119
				}
117 120
			}
118 121
		} catch (FileNotFoundException e) {
......
124 127
		}
125 128
		return null;
126 129
	}
127
	
130

  
128 131
	/*
129 132
	 * (non-Javadoc)
130 133
	 * @see org.gvsig.gpe.GPEParser#accept(java.io.File)
......
134 137
			return true;
135 138
		}
136 139
		return false;
137
	}	
138
	
140
	}
139 141

  
142

  
140 143
	public boolean accept(File file) {
141
		if (file.getPath().toUpperCase().endsWith("KMZ")){				
144
		if (file.getPath().toUpperCase().endsWith("KMZ")){
142 145
			return true;
143 146
		}
144 147
		return false;
145
	}	
148
	}
146 149

  
147 150
}
org.gvsig.gpe/library/trunk/org.gvsig.gpe/org.gvsig.gpe.app/org.gvsig.gpe.app.mainplugin/src/main/java/org/gvsig/fmap/dal/store/gpe/GPEStoreParameters.java
2 2
 *
3 3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4 4
 * of the Valencian Government (CIT)
5
 * 
5
 *
6 6
 * This program is free software; you can redistribute it and/or
7 7
 * modify it under the terms of the GNU General Public License
8 8
 * as published by the Free Software Foundation; either version 2
9 9
 * of the License, or (at your option) any later version.
10
 * 
10
 *
11 11
 * This program is distributed in the hope that it will be useful,
12 12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14
 * GNU General Public License for more details.
15
 * 
15
 *
16 16
 * You should have received a copy of the GNU General Public License
17 17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 19
 * MA  02110-1301, USA.
20
 * 
20
 *
21 21
 */
22 22

  
23 23
/*
......
31 31
import org.apache.commons.lang3.BooleanUtils;
32 32

  
33 33
import org.cresques.cts.IProjection;
34
import org.gvsig.fmap.crs.CRSFactory;
35
import org.gvsig.fmap.dal.DataStore;
34 36
import org.gvsig.fmap.dal.DataStoreParameters;
35 37
import org.gvsig.fmap.dal.FileHelper;
36 38
import org.gvsig.fmap.dal.feature.EditableFeatureType;
......
40 42
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
41 43
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
42 44
import org.gvsig.fmap.geom.primitive.Envelope;
45
import org.gvsig.gpe.lib.api.GPELocator;
46
import org.gvsig.gpe.lib.api.GPEManager;
47
import org.gvsig.gpe.lib.api.exceptions.ParserCreationException;
48
import org.gvsig.tools.ToolsLocator;
49
import org.gvsig.tools.dataTypes.CoercionException;
50
import org.gvsig.tools.dataTypes.DataTypesManager;
51
import org.gvsig.tools.dataTypes.impl.DefaultDataTypesManager;
43 52
import org.gvsig.tools.dynobject.DelegatedDynObject;
44 53
import org.gvsig.tools.dynobject.DynStruct;
54
import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException;
55
import org.gvsig.tools.locator.LocatorException;
56
import org.slf4j.Logger;
57
import org.slf4j.LoggerFactory;
45 58

  
46 59
/**
47 60
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
......
59 72

  
60 73
    private DelegatedDynObject parameters;
61 74

  
75
    private static Logger logger = LoggerFactory.getLogger(GPEStoreParameters.class);
76

  
62 77
    public GPEStoreParameters() {
63 78
        this(PARAMETERS_DEFINITION_NAME);
64 79
    }
......
70 85
    public GPEStoreParameters(String parametersDefinitionName, String name) {
71 86
        super();
72 87
        this.parameters = (DelegatedDynObject) FileHelper.newParameters(parametersDefinitionName);
73
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);       
88
        this.setDynValue(DataStoreProviderServices.PROVIDER_PARAMTER_NAME, name);
74 89
    }
75 90

  
76
    protected static void registerParametersDefinition(){ 
91
    protected static void registerParametersDefinition(){
77 92
        DynStruct dynStruct = FileHelper.registerParametersDefinition(
78 93
            GPEStoreParameters.PARAMETERS_DEFINITION_NAME,
79 94
            GPEStoreParameters.class, "GPEParameters.xml");
80
        
95

  
81 96
        dynStruct.addDynFieldObject(ENVELOPE_PARAMETER_NAME).
82 97
        setClassOfValue(Envelope.class).setMandatory(false);
83 98

  
......
107 122

  
108 123
    public void setFile(File file) {
109 124
        this.setDynValue(FILE_PARAMETER_NAME, file);
110
    }	
125
    }
111 126

  
112 127
    public String getFileName() {
113 128
        return this.getFile().getAbsolutePath();
......
136 151
    public void setEnvelope(Envelope envelope) {
137 152
        this.setDynValue(ENVELOPE_PARAMETER_NAME, envelope);
138 153
    }
139
    
154

  
140 155
    public void setDynValue(String name, Object val) {
141 156
    	super.setDynValue(name, val);
142 157
    }
......
145 160
        boolean x = BooleanUtils.isTrue((Boolean) this.getDynValue("useAxisOrderYX"));
146 161
        return x;
147 162
    }
148
    
163

  
149 164
	public EditableFeatureType getDefaultFeatureType() {
150 165
		return (EditableFeatureType) this.getDynValue(FEATURETYPE_PARAMETER_NAME);
151 166
	}
......
153 168
	public void setDefaultFeatureType(FeatureType featureType) {
154 169
		this.setDynValue(FEATURETYPE_PARAMETER_NAME, featureType);
155 170
	}
171

  
172
    public Object getDynValue(String name) throws DynFieldNotFoundException {
173
        if (DataStore.METADATA_CRS.equalsIgnoreCase(name)) {
174
            try {
175
                GPEManager gpeManager=GPELocator.getGPEManager();
176
                String crs=gpeManager.getDefaultProjection(getFile());
177
                DataTypesManager dataTypesManager=ToolsLocator.getDataTypesManager();
178
                IProjection projection=(IProjection) dataTypesManager.coerce(org.cresques.DataTypes.CRS, crs);
179
                if (projection!=null){
180
                    setCRS(projection);
181
                }
182
            } catch (LocatorException  | ParserCreationException | CoercionException e) {
183
                logger.warn("Couldn't get default projection",e);
184
            }
185
        }
186
        return super.getDynValue(name);
187
    }
156 188
}

Also available in: Unified diff