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