svn-gvsig-desktop / tags / v1_0_1_RELEASE / libraries / libRemoteServices / src / org / gvsig / remoteClient / gml / GMLReader.java @ 9531
History | View | Annotate | Download (5 KB)
1 | 6722 | jorpiell | package org.gvsig.remoteClient.gml; |
---|---|---|---|
2 | |||
3 | import java.awt.geom.Rectangle2D; |
||
4 | import java.io.BufferedReader; |
||
5 | import java.io.File; |
||
6 | import java.io.FileInputStream; |
||
7 | import java.io.FileNotFoundException; |
||
8 | import java.io.FileReader; |
||
9 | import java.io.IOException; |
||
10 | import java.io.Reader; |
||
11 | import java.util.ArrayList; |
||
12 | import java.util.Hashtable; |
||
13 | import java.util.Properties; |
||
14 | |||
15 | import org.gvsig.remoteClient.gml.factories.FeaturesParserFactory; |
||
16 | import org.gvsig.remoteClient.gml.factories.IGeometriesFactory; |
||
17 | import org.gvsig.remoteClient.gml.factories.XMLParserFactory; |
||
18 | import org.gvsig.remoteClient.gml.schemas.XMLSchemaParser; |
||
19 | import org.gvsig.remoteClient.gml.schemas.XMLSchemasManager; |
||
20 | import org.kxml2.io.KXmlParser; |
||
21 | import org.xmlpull.v1.XmlPullParserException; |
||
22 | |||
23 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
24 | *
|
||
25 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
26 | *
|
||
27 | * This program is free software; you can redistribute it and/or
|
||
28 | * modify it under the terms of the GNU General Public License
|
||
29 | * as published by the Free Software Foundation; either version 2
|
||
30 | * of the License, or (at your option) any later version.
|
||
31 | *
|
||
32 | * This program is distributed in the hope that it will be useful,
|
||
33 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
34 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
35 | * GNU General Public License for more details.
|
||
36 | *
|
||
37 | * You should have received a copy of the GNU General Public License
|
||
38 | * along with this program; if not, write to the Free Software
|
||
39 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
40 | *
|
||
41 | * For more information, contact:
|
||
42 | *
|
||
43 | * Generalitat Valenciana
|
||
44 | * Conselleria d'Infraestructures i Transport
|
||
45 | * Av. Blasco Ib??ez, 50
|
||
46 | * 46010 VALENCIA
|
||
47 | * SPAIN
|
||
48 | *
|
||
49 | * +34 963862235
|
||
50 | * gvsig@gva.es
|
||
51 | * www.gvsig.gva.es
|
||
52 | *
|
||
53 | * or
|
||
54 | *
|
||
55 | * IVER T.I. S.A
|
||
56 | * Salamanca 50
|
||
57 | * 46005 Valencia
|
||
58 | * Spain
|
||
59 | *
|
||
60 | * +34 963163400
|
||
61 | * dac@iver.es
|
||
62 | */
|
||
63 | /* CVS MESSAGES:
|
||
64 | *
|
||
65 | * $Id$
|
||
66 | * $Log$
|
||
67 | 8848 | ppiqueras | * Revision 1.1.2.2 2006-11-17 11:38:03 ppiqueras
|
68 | * Corregidos bugs y a?adida nueva funcionalidad. Del HEAD.
|
||
69 | 8765 | jjdelcerro | *
|
70 | * Revision 1.2 2006/11/06 12:15:11 jorpiell
|
||
71 | * A?adido un constructor con un par?metro booleano que se usar? para abrir gml's sin validar el esquema
|
||
72 | *
|
||
73 | * Revision 1.1 2006/08/10 12:00:49 jorpiell
|
||
74 | 6722 | jorpiell | * Primer commit del driver de Gml
|
75 | *
|
||
76 | *
|
||
77 | */
|
||
78 | /**
|
||
79 | * This class must be used to read any GML 2.x file (2.0, 2.1.1
|
||
80 | * 2.1.2). It is able to parse GML features that have a xml complex
|
||
81 | * type with only one level of complexity. More levels and GML 3.x
|
||
82 | * will be supported in next versions.
|
||
83 | *
|
||
84 | * Name: OpenGIS? Geography Markup Language (GML) Implementation Specification,
|
||
85 | * Version: 2.x
|
||
86 | * Project Document: 01-029 (2.0), 02-099 (2.1.1) and 02-069 (v2.1.2)
|
||
87 | *
|
||
88 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
89 | */
|
||
90 | public class GMLReader { |
||
91 | private XMLSchemasManager schemasManager = null; |
||
92 | private GMLFeaturesParser featuresParser = null; |
||
93 | private File m_File = null; |
||
94 | |||
95 | /**
|
||
96 | * Constructor
|
||
97 | * @param file
|
||
98 | * GML File to read
|
||
99 | * @param factory
|
||
100 | * Geometries factory that is used to create the parsed
|
||
101 | * GML geometries
|
||
102 | * @throws Exception
|
||
103 | * @throws FileNotFoundException
|
||
104 | * When the file is not found
|
||
105 | */
|
||
106 | public GMLReader(File file,IGeometriesFactory factory) throws Exception{ |
||
107 | this.m_File = file;
|
||
108 | initialize(factory); |
||
109 | } |
||
110 | |||
111 | /**
|
||
112 | 8765 | jjdelcerro | * Constructor
|
113 | * @param file
|
||
114 | * GML File to read
|
||
115 | * @param factory
|
||
116 | * Geometries factory that is used to create the parsed
|
||
117 | * GML geometries
|
||
118 | * @param mustValidate
|
||
119 | * To validate or not validate the schemas
|
||
120 | * @throws Exception
|
||
121 | * @throws FileNotFoundException
|
||
122 | * When the file is not found
|
||
123 | */
|
||
124 | public GMLReader(File file,IGeometriesFactory factory,boolean mustValidate) throws Exception{ |
||
125 | this(file,factory);
|
||
126 | } |
||
127 | |||
128 | /**
|
||
129 | 6722 | jorpiell | * Initializes the XMLSchemaParser, tries to parse the GML header
|
130 | * to obtain the GML version and parses all the needed schemas
|
||
131 | * @param factory
|
||
132 | * Geometries factory that is used to create the parsed
|
||
133 | * GML geometries
|
||
134 | * @throws Exception
|
||
135 | */
|
||
136 | private void initialize(IGeometriesFactory factory) throws Exception{ |
||
137 | XMLSchemaParser parser = new XMLParserFactory().createSchemaParser(m_File);
|
||
138 | |||
139 | //Retrieve the header attributes and download and parse the schemas
|
||
140 | schemasManager = new XMLSchemasManager(m_File);
|
||
141 | schemasManager.parse(parser); |
||
142 | |||
143 | //Parse the GML global fields
|
||
144 | featuresParser = new FeaturesParserFactory().createParser(getVersion(),factory,parser);
|
||
145 | } |
||
146 | |||
147 | /**
|
||
148 | * Gets the GML iteartor used to retrieve all the
|
||
149 | * features
|
||
150 | * @param factory
|
||
151 | * Factory to create the geometries
|
||
152 | * @return
|
||
153 | */
|
||
154 | public IGMLFeaturesIterator getFeaturesIterator() throws Exception{ |
||
155 | return featuresParser.getFeaturesReader();
|
||
156 | } |
||
157 | |||
158 | /**
|
||
159 | * @return Returns the version.
|
||
160 | */
|
||
161 | public String getVersion(){ |
||
162 | return schemasManager.getVersion();
|
||
163 | } |
||
164 | |||
165 | /**
|
||
166 | * @return Returns the extent.
|
||
167 | */
|
||
168 | public Rectangle2D getExtent(){ |
||
169 | return featuresParser.getExtent().getExtent();
|
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * @return Returns the SRS
|
||
174 | */
|
||
175 | public String getSRS(){ |
||
176 | return featuresParser.getExtent().getSrs();
|
||
177 | } |
||
178 | } |