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