root / trunk / libraries / libGPE-GML / src / org / gvsig / gpe / gml / GPEGmlParser.java @ 12418
History | View | Annotate | Download (6.9 KB)
1 |
package org.gvsig.gpe.gml; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.FileInputStream; |
5 |
import java.io.FileNotFoundException; |
6 |
import java.io.IOException; |
7 |
import java.io.InputStream; |
8 |
import java.net.URI; |
9 |
|
10 |
import org.gvsig.gpe.gml.bindings.FeatureCollectionBinding; |
11 |
import org.gvsig.gpe.xml.GPEXmlParser; |
12 |
import org.kxml2.io.KXmlParser; |
13 |
import org.xmlpull.v1.XmlPullParser; |
14 |
import org.xmlpull.v1.XmlPullParserException; |
15 |
|
16 |
import com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration; |
17 |
|
18 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
19 |
*
|
20 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
21 |
*
|
22 |
* This program is free software; you can redistribute it and/or
|
23 |
* modify it under the terms of the GNU General Public License
|
24 |
* as published by the Free Software Foundation; either version 2
|
25 |
* of the License, or (at your option) any later version.
|
26 |
*
|
27 |
* This program is distributed in the hope that it will be useful,
|
28 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
29 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
30 |
* GNU General Public License for more details.
|
31 |
*
|
32 |
* You should have received a copy of the GNU General Public License
|
33 |
* along with this program; if not, write to the Free Software
|
34 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
35 |
*
|
36 |
* For more information, contact:
|
37 |
*
|
38 |
* Generalitat Valenciana
|
39 |
* Conselleria d'Infraestructures i Transport
|
40 |
* Av. Blasco Ib??ez, 50
|
41 |
* 46010 VALENCIA
|
42 |
* SPAIN
|
43 |
*
|
44 |
* +34 963862235
|
45 |
* gvsig@gva.es
|
46 |
* www.gvsig.gva.es
|
47 |
*
|
48 |
* or
|
49 |
*
|
50 |
* IVER T.I. S.A
|
51 |
* Salamanca 50
|
52 |
* 46005 Valencia
|
53 |
* Spain
|
54 |
*
|
55 |
* +34 963163400
|
56 |
* dac@iver.es
|
57 |
*/
|
58 |
/* CVS MESSAGES:
|
59 |
*
|
60 |
* $Id: GPEGmlParser.java 12418 2007-06-29 12:19:48Z jorpiell $
|
61 |
* $Log$
|
62 |
* Revision 1.15 2007-06-29 12:19:34 jorpiell
|
63 |
* The schema validation is made independently of the concrete writer
|
64 |
*
|
65 |
* Revision 1.14 2007/06/07 14:53:30 jorpiell
|
66 |
* Add the schema support
|
67 |
*
|
68 |
* Revision 1.13 2007/05/24 07:29:47 csanchez
|
69 |
* A?adidos Alias GML2
|
70 |
*
|
71 |
* Revision 1.12 2007/05/17 11:20:51 jorpiell
|
72 |
* Add the layer methods
|
73 |
*
|
74 |
* Revision 1.11 2007/05/16 12:34:55 csanchez
|
75 |
* GPEParser Prototipo final de lectura
|
76 |
*
|
77 |
* Revision 1.10 2007/05/14 11:23:12 jorpiell
|
78 |
* ProjectionFactory updated
|
79 |
*
|
80 |
* Revision 1.9 2007/05/14 09:52:26 jorpiell
|
81 |
* Tupes separator tag updated
|
82 |
*
|
83 |
* Revision 1.8 2007/05/09 06:54:25 jorpiell
|
84 |
* Change the File by URI
|
85 |
*
|
86 |
* Revision 1.7 2007/05/07 07:06:46 jorpiell
|
87 |
* Add a constructor with the name and the description fields
|
88 |
*
|
89 |
* Revision 1.6 2007/04/25 11:08:38 csanchez
|
90 |
* Parseo correcto con XSOM de esquemas, EntityResolver para los imports
|
91 |
*
|
92 |
* Revision 1.5 2007/04/20 12:04:10 csanchez
|
93 |
* Actualizacion protoripo libGPE, A?adidos test para el parser, parseo con XSOM
|
94 |
*
|
95 |
* Revision 1.4 2007/04/19 11:51:43 csanchez
|
96 |
* Actualizacion protoripo libGPE
|
97 |
*
|
98 |
* Revision 1.1 2007/04/18 12:54:45 csanchez
|
99 |
* Actualizacion protoripo libGPE
|
100 |
*
|
101 |
*
|
102 |
*/
|
103 |
/**
|
104 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
|
105 |
**/
|
106 |
|
107 |
public class GPEGmlParser extends GPEXmlParser{ |
108 |
private XmlPullParser fileParser = null; |
109 |
|
110 |
|
111 |
/*********************
|
112 |
* <GPEGmlParser>
|
113 |
* Constructor Method
|
114 |
*********************/
|
115 |
public GPEGmlParser(String name, String description) { |
116 |
super(name, description);
|
117 |
} |
118 |
|
119 |
/**************************************************************
|
120 |
* <getFormats>
|
121 |
* Returns the file extensions that are accepted to GML Parser
|
122 |
* @return String[] Accepted Extensions
|
123 |
**************************************************************/
|
124 |
public String[] getFormats() { |
125 |
String[] formats = new String[2]; |
126 |
formats[0] = "GML"; |
127 |
formats[1] = "XML"; |
128 |
return formats;
|
129 |
} |
130 |
|
131 |
/************************************************************************
|
132 |
* <accept>
|
133 |
* Returns true if the file is a gml file and the parser has to parse it
|
134 |
* @param URI uri
|
135 |
* @return boolean
|
136 |
************************************************************************/
|
137 |
public boolean accept(URI uri) { |
138 |
if ((uri.getPath().toUpperCase().endsWith("GML")) |
139 |
|| (uri.getPath().toUpperCase().endsWith("XML"))) {
|
140 |
return true; |
141 |
} |
142 |
return false; |
143 |
} |
144 |
|
145 |
/**********************************************
|
146 |
* <getVersions>
|
147 |
* Returns the gml versions that are supported
|
148 |
* @return String[] Accepted Versions
|
149 |
**********************************************/
|
150 |
public String[] getVersions() { |
151 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
152 |
return null; |
153 |
} |
154 |
|
155 |
/*************************************
|
156 |
* <createInputStream>
|
157 |
* Creates an InputStream from a file.
|
158 |
* @param File file
|
159 |
* @return FileInputStream
|
160 |
*************************************/
|
161 |
protected InputStream createInputStream(File file) throws FileNotFoundException { |
162 |
return new FileInputStream(file); |
163 |
} |
164 |
|
165 |
/****************************
|
166 |
* <initParse>
|
167 |
* Starts to parse the file.
|
168 |
****************************/
|
169 |
protected void initParse() { |
170 |
//First, it gets the file parser.
|
171 |
fileParser = getParser(); |
172 |
try {
|
173 |
//If the file is empty
|
174 |
if (getParser().getEventType() == XmlPullParser.END_DOCUMENT){
|
175 |
return;
|
176 |
} |
177 |
//Initialize the layer
|
178 |
//recursiveParser();
|
179 |
FeatureCollectionBinding.parse(getParser(), this);
|
180 |
} catch (Exception e) { |
181 |
getErrorHandler().addError(e); |
182 |
e.printStackTrace(); |
183 |
} |
184 |
} |
185 |
|
186 |
public String getTag(){ |
187 |
// Getting tag name
|
188 |
return fileParser.getName();
|
189 |
} |
190 |
|
191 |
public String getTagNamespace(){ |
192 |
String fullTag = getTag();
|
193 |
// Gramma must be revised too if there are schema
|
194 |
// If there are namespaces before the ":" we keep tagName and nameSpace
|
195 |
int pos2 = fullTag.indexOf(":"); |
196 |
if (pos2 > 0){ |
197 |
return fullTag.substring(0,fullTag.indexOf(":")); |
198 |
} |
199 |
else
|
200 |
{ |
201 |
return ""; |
202 |
} |
203 |
|
204 |
} |
205 |
|
206 |
public String getTagName(){ |
207 |
String fullTag = getTag();
|
208 |
// Gramma must be revised too if there are schema
|
209 |
// If there are namespaces before the ":" we keep tagName and nameSpace
|
210 |
int pos2 = fullTag.indexOf(":"); |
211 |
if (pos2 > 0){ |
212 |
return fullTag.substring(fullTag.indexOf(":") + 1,fullTag.length()); |
213 |
} |
214 |
else
|
215 |
{ |
216 |
return fullTag;
|
217 |
} |
218 |
} |
219 |
|
220 |
public XmlPullParser getFileParser(){
|
221 |
return fileParser;
|
222 |
} |
223 |
|
224 |
/************************************************
|
225 |
* <getNext>
|
226 |
* Gets the next tag or text token from the file.
|
227 |
* without white spaces.
|
228 |
************************************************/
|
229 |
public void getNext(){ |
230 |
//Get next tag --> next():Method from KXML library to get next tag
|
231 |
try {
|
232 |
fileParser.next(); |
233 |
if((fileParser.getEventType() == KXmlParser.TEXT)&&(fileParser.isWhitespace())){
|
234 |
getNext(); |
235 |
} |
236 |
} catch (XmlPullParserException e) {
|
237 |
// TODO Bloque catch generado autom?ticamente
|
238 |
System.out.println("Error en XmlPullParser al intentar obtener la siguiente etiqueta: "+e.getMessage()); |
239 |
} catch (IOException e) { |
240 |
// TODO Bloque catch generado autom?ticamente
|
241 |
System.out.println("Error al leer la siguiente etiqueta en XmlPullParser: "+e.getMessage()); |
242 |
} |
243 |
} |
244 |
|
245 |
|
246 |
public boolean accept(File file) { |
247 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
248 |
return false; |
249 |
} |
250 |
} |