Revision 21951 trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/parser/GPEDefaultGmlParser.java
GPEDefaultGmlParser.java | ||
---|---|---|
103 | 103 |
*/ |
104 | 104 |
|
105 | 105 |
public abstract class GPEDefaultGmlParser extends GPEXmlParser { |
106 |
private IXmlStreamReader fileParser = null;
|
|
107 |
private IBindingProfile profile = null;
|
|
106 |
private IXmlStreamReader fileParser = null;
|
|
107 |
private IBindingProfile profile = null;
|
|
108 | 108 |
|
109 |
/***********************************************************************************************
|
|
110 |
* <GPEGmlParser> Constructor Method
|
|
111 |
**********************************************************************************************/
|
|
112 |
public GPEDefaultGmlParser() {
|
|
113 |
super();
|
|
114 |
}
|
|
109 |
/***********************************************************************************************
|
|
110 |
* <GPEGmlParser> Constructor Method
|
|
111 |
**********************************************************************************************/
|
|
112 |
public GPEDefaultGmlParser() {
|
|
113 |
super();
|
|
114 |
}
|
|
115 | 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 |
}
|
|
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 | 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 |
}
|
|
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 | 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 |
}
|
|
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 | 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 |
} |
|
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 |
} |
|
168 | 174 |
|
169 |
public IXmlStreamReader getFileParser() {
|
|
170 |
return fileParser;
|
|
171 |
}
|
|
175 |
public IXmlStreamReader getFileParser() {
|
|
176 |
return fileParser;
|
|
177 |
}
|
|
172 | 178 |
|
173 |
/***********************************************************************************************
|
|
174 |
* <getNext> Gets the next tag or text token from the file. without white spaces.
|
|
175 |
**********************************************************************************************/
|
|
176 |
public void getNext() {
|
|
177 |
// Get next tag --> next():Method from KXML library to get next tag
|
|
178 |
try {
|
|
179 |
fileParser.next();
|
|
180 |
if ((fileParser.getEventType() == IXmlStreamReader.CHARACTERS)
|
|
181 |
&& (fileParser.isWhitespace())) {
|
|
182 |
getNext();
|
|
183 |
}
|
|
184 |
} catch (XmlStreamException e) {
|
|
185 |
// TODO Bloque catch generado autom?ticamente
|
|
186 |
System.out.println("Error en XmlPullParser al intentar obtener la siguiente etiqueta: "
|
|
187 |
+ e.getMessage());
|
|
188 |
} catch (IOException e) {
|
|
189 |
// TODO Bloque catch generado autom?ticamente
|
|
190 |
System.out.println("Error al leer la siguiente etiqueta en XmlPullParser: "
|
|
191 |
+ e.getMessage());
|
|
192 |
}
|
|
193 |
}
|
|
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 |
}
|
|
194 | 200 |
|
195 |
/**
|
|
196 |
* @param profile the profile to set
|
|
197 |
*/
|
|
198 |
protected void setProfile(IBindingProfile profile) {
|
|
199 |
this.profile = profile;
|
|
200 |
}
|
|
201 |
/**
|
|
202 |
* @param profile the profile to set
|
|
203 |
*/
|
|
204 |
protected void setProfile(IBindingProfile profile) {
|
|
205 |
this.profile = profile;
|
|
206 |
}
|
|
201 | 207 |
|
202 |
/**
|
|
203 |
* @return the profile
|
|
204 |
*/
|
|
205 |
public IBindingProfile getProfile() {
|
|
206 |
return profile;
|
|
207 |
}
|
|
208 |
/**
|
|
209 |
* @return the profile
|
|
210 |
*/
|
|
211 |
public IBindingProfile getProfile() {
|
|
212 |
return profile;
|
|
213 |
}
|
|
208 | 214 |
} |
Also available in: Unified diff