svn-gvsig-desktop / trunk / libraries / libGPE / src / org / gvsig / gpe / parser / GPEParser.java @ 19579
History | View | Annotate | Download (6.07 KB)
1 |
package org.gvsig.gpe.parser; |
---|---|
2 |
import java.io.InputStream; |
3 |
import java.net.URI; |
4 |
|
5 |
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
7 |
*
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
9 |
*
|
10 |
* This program is free software; you can redistribute it and/or
|
11 |
* modify it under the terms of the GNU General Public License
|
12 |
* as published by the Free Software Foundation; either version 2
|
13 |
* of the License, or (at your option) any later version.
|
14 |
*
|
15 |
* This program is distributed in the hope that it will be useful,
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
* GNU General Public License for more details.
|
19 |
*
|
20 |
* You should have received a copy of the GNU General Public License
|
21 |
* along with this program; if not, write to the Free Software
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
23 |
*
|
24 |
* For more information, contact:
|
25 |
*
|
26 |
* Generalitat Valenciana
|
27 |
* Conselleria d'Infraestructures i Transport
|
28 |
* Av. Blasco Ib??ez, 50
|
29 |
* 46010 VALENCIA
|
30 |
* SPAIN
|
31 |
*
|
32 |
* +34 963862235
|
33 |
* gvsig@gva.es
|
34 |
* www.gvsig.gva.es
|
35 |
*
|
36 |
* or
|
37 |
*
|
38 |
* IVER T.I. S.A
|
39 |
* Salamanca 50
|
40 |
* 46005 Valencia
|
41 |
* Spain
|
42 |
*
|
43 |
* +34 963163400
|
44 |
* dac@iver.es
|
45 |
*/
|
46 |
/* CVS MESSAGES:
|
47 |
*
|
48 |
* $Id: GPEParser.java 173 2007-11-06 12:10:57Z jpiera $
|
49 |
* $Log$
|
50 |
* Revision 1.14 2007/06/20 09:35:37 jorpiell
|
51 |
* Add the javadoc comments
|
52 |
*
|
53 |
* Revision 1.13 2007/06/07 14:52:28 jorpiell
|
54 |
* Add the schema support
|
55 |
*
|
56 |
* Revision 1.12 2007/05/09 06:54:07 jorpiell
|
57 |
* Change the File by URI
|
58 |
*
|
59 |
* Revision 1.11 2007/05/07 07:06:26 jorpiell
|
60 |
* Add a constructor with the name and the description fields
|
61 |
*
|
62 |
* Revision 1.10 2007/04/20 12:04:10 csanchez
|
63 |
* Actualizacion protoripo libGPE, A?adidos test para el parser, parseo con XSOM
|
64 |
*
|
65 |
* Revision 1.9 2007/04/19 11:50:20 csanchez
|
66 |
* Actualizacion protoripo libGPE
|
67 |
*
|
68 |
* Revision 1.8 2007/04/19 07:23:20 jorpiell
|
69 |
* Add the add methods to teh contenhandler and change the register mode
|
70 |
*
|
71 |
* Revision 1.7 2007/04/14 16:06:13 jorpiell
|
72 |
* The writer handler has been updated
|
73 |
*
|
74 |
* Revision 1.6 2007/04/13 07:17:54 jorpiell
|
75 |
* Add the writting tests for the simple geometries
|
76 |
*
|
77 |
* Revision 1.5 2007/04/12 17:06:42 jorpiell
|
78 |
* First GML writing tests
|
79 |
*
|
80 |
* Revision 1.4 2007/04/12 10:21:29 jorpiell
|
81 |
* Add the getWriter() method
|
82 |
*
|
83 |
* Revision 1.3 2007/04/11 11:18:15 csanchez
|
84 |
* Actualizacion protoripo libGPE
|
85 |
*
|
86 |
* Revision 1.2 2007/04/11 08:46:21 csanchez
|
87 |
* Actualizacion protoripo libGPE
|
88 |
*
|
89 |
* Revision 1.1 2007/04/11 08:19:32 csanchez
|
90 |
* actualizacion
|
91 |
*
|
92 |
*
|
93 |
*/
|
94 |
/**
|
95 |
* This class has to be inherited by all the classes that
|
96 |
* implements a parser for a geographical format. IT has methods
|
97 |
* to indicate the formats and the versions that is able to
|
98 |
* parse.
|
99 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
100 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
|
101 |
*/
|
102 |
|
103 |
|
104 |
public abstract class GPEParser { |
105 |
private GPEErrorHandler errorHandler;
|
106 |
private GPEContentHandler contentHandler;
|
107 |
private String name = null; |
108 |
private String description = null; |
109 |
private URI mainFile; |
110 |
private InputStream is = null; |
111 |
|
112 |
/**
|
113 |
* All the GPE parser must implement a constructor with this
|
114 |
* two arguments.
|
115 |
* @param name
|
116 |
* Parser name
|
117 |
* @param description
|
118 |
* Parser description
|
119 |
**/
|
120 |
public GPEParser(String name, String description){ |
121 |
this.name = name;
|
122 |
this.description = description;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* Method to parse a file. It cannot to throw
|
127 |
* any exception and it cannot to return any value.
|
128 |
* In a future it could be implemented like a independent
|
129 |
* thread
|
130 |
* @param contents
|
131 |
* Application ContentHandler
|
132 |
* @param errors
|
133 |
* Application ErrorsHandler
|
134 |
* @param uri
|
135 |
* File to open
|
136 |
* @throws Exception
|
137 |
*/
|
138 |
public void parse(GPEContentHandler contents, GPEErrorHandler errors, URI uri) { |
139 |
this.contentHandler = contents;
|
140 |
this.errorHandler = errors;
|
141 |
this.mainFile = uri;
|
142 |
parseURI(); |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Parses the file from a URI
|
147 |
*/
|
148 |
protected abstract void parseURI(); |
149 |
|
150 |
/**
|
151 |
* Method to parse an InputStream. It cannot to throw
|
152 |
* any exception and it cannot to return any value.
|
153 |
* In a future it could be implemented like a independent
|
154 |
* thread
|
155 |
* @param contents
|
156 |
* Application ContentHandler
|
157 |
* @param errors
|
158 |
* Application ErrorsHandler
|
159 |
* @param is
|
160 |
* The input stream
|
161 |
* @throws Exception
|
162 |
*/
|
163 |
public void parse(GPEContentHandler contents, GPEErrorHandler errors, InputStream is) { |
164 |
this.contentHandler = contents;
|
165 |
this.errorHandler = errors;
|
166 |
this.is = is;
|
167 |
parseStream(); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Parses the file from an input stream
|
172 |
*/
|
173 |
protected abstract void parseStream(); |
174 |
|
175 |
/**
|
176 |
* Return if the driver can open the file
|
177 |
* @param uri
|
178 |
* File to open
|
179 |
* @return
|
180 |
* True if the driver is able to open it
|
181 |
*/
|
182 |
public abstract boolean accept(URI uri); |
183 |
|
184 |
/**
|
185 |
* Return an array with all the formats that the driver
|
186 |
* is able to read/write
|
187 |
* @return
|
188 |
*/
|
189 |
public abstract String[] getFormats(); |
190 |
|
191 |
/**
|
192 |
* Return an array with all the versions that the driver
|
193 |
* is able to read/write
|
194 |
* @return
|
195 |
*/
|
196 |
public abstract String[] getVersions(); |
197 |
|
198 |
/**
|
199 |
* @return the contentHandler
|
200 |
*/
|
201 |
public GPEContentHandler getContentHandler() {
|
202 |
return contentHandler;
|
203 |
} |
204 |
|
205 |
|
206 |
/**
|
207 |
* @return the errorHandler
|
208 |
*/
|
209 |
public GPEErrorHandler getErrorHandler() {
|
210 |
return errorHandler;
|
211 |
} |
212 |
|
213 |
/**
|
214 |
* @return the file
|
215 |
*/
|
216 |
public URI getMainFile() { |
217 |
return mainFile;
|
218 |
} |
219 |
|
220 |
/**
|
221 |
* @return the description
|
222 |
*/
|
223 |
public String getDescription() { |
224 |
return description;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* @return the name
|
229 |
*/
|
230 |
public String getName() { |
231 |
return name;
|
232 |
} |
233 |
|
234 |
/**
|
235 |
* @return the is
|
236 |
*/
|
237 |
public InputStream getInputStream() { |
238 |
return is;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* @param is the is to set
|
243 |
*/
|
244 |
protected void setInputStream(InputStream is) { |
245 |
this.is = is;
|
246 |
} |
247 |
|
248 |
/**
|
249 |
* @param errorHandler the errorHandler to set
|
250 |
*/
|
251 |
public void setErrorHandler(GPEErrorHandler errorHandler) { |
252 |
this.errorHandler = errorHandler;
|
253 |
} |
254 |
|
255 |
/**
|
256 |
* @param contentHandler the contentHandler to set
|
257 |
*/
|
258 |
public void setContentHandler(GPEContentHandler contentHandler) { |
259 |
this.contentHandler = contentHandler;
|
260 |
} |
261 |
} |