svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / reader / bindings / PlaceMarketBinding.java @ 11573
History | View | Annotate | Download (5.42 KB)
1 |
package org.gvsig.gpe.kml.reader.bindings; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
6 |
import org.gvsig.gpe.kml.KmlTags; |
7 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
8 |
import org.gvsig.gpe.kml.reader.bindings.geometries.LineStringTypeBinding; |
9 |
import org.gvsig.gpe.kml.reader.bindings.geometries.PointTypeBinding; |
10 |
import org.gvsig.gpe.kml.reader.bindings.geometries.PolygonTypeBinding; |
11 |
import org.gvsig.gpe.kml.reader.bindings.geometries.RegionBinding; |
12 |
import org.kxml2.io.KXmlParser; |
13 |
import org.xmlpull.v1.XmlPullParser; |
14 |
import org.xmlpull.v1.XmlPullParserException; |
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: PlaceMarketBinding.java 11573 2007-05-11 07:06:29Z jorpiell $
|
59 |
* $Log$
|
60 |
* Revision 1.1 2007-05-11 07:06:29 jorpiell
|
61 |
* Refactoring of some package names
|
62 |
*
|
63 |
* Revision 1.5 2007/05/09 08:36:24 jorpiell
|
64 |
* Add the bbox to the layer
|
65 |
*
|
66 |
* Revision 1.4 2007/05/08 08:22:37 jorpiell
|
67 |
* Add comments to create javadocs
|
68 |
*
|
69 |
* Revision 1.3 2007/04/20 08:38:59 jorpiell
|
70 |
* Tests updating
|
71 |
*
|
72 |
* Revision 1.2 2007/04/13 13:16:21 jorpiell
|
73 |
* Add KML reading support
|
74 |
*
|
75 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell
|
76 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML
|
77 |
*
|
78 |
* Revision 1.1 2007/02/28 11:48:31 csanchez
|
79 |
* *** empty log message ***
|
80 |
*
|
81 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell
|
82 |
* A?adidos los proyectos de kml y gml antiguos
|
83 |
*
|
84 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell
|
85 |
* A?adido el driver de KML
|
86 |
*
|
87 |
*
|
88 |
*/
|
89 |
/**
|
90 |
* This class parses a PlaceMark tag. Example:
|
91 |
* <p>
|
92 |
* <pre>
|
93 |
* <code>
|
94 |
* <Placemark>
|
95 |
* <name>CDATA example</name>
|
96 |
* <description>Description example</description>
|
97 |
* <Point>
|
98 |
* <oordinates>102.595626,14.996729</coordinates>
|
99 |
* </Point>
|
100 |
* </Placemark>
|
101 |
* </code>
|
102 |
* </pre>
|
103 |
* </p>
|
104 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
105 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#placemark
|
106 |
*/
|
107 |
public class PlaceMarketBinding { |
108 |
|
109 |
/**
|
110 |
* It parses the PlaceMark tag
|
111 |
* @param parser
|
112 |
* The XML parser
|
113 |
* @param handler
|
114 |
* The GPE parser that contains the content handler and
|
115 |
* the error handler
|
116 |
* @return
|
117 |
* A Feature
|
118 |
* @throws IOException
|
119 |
* @throws XmlPullParserException
|
120 |
* @throws XmlPullParserException
|
121 |
* @throws IOException
|
122 |
*/
|
123 |
public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException{ |
124 |
boolean endFeature = false; |
125 |
int currentTag;
|
126 |
|
127 |
String id = FeatureBinding.getID(parser, handler);
|
128 |
Object feature = handler.getContentHandler().startFeature(id, null, null); |
129 |
|
130 |
|
131 |
String tag = parser.getName();
|
132 |
currentTag = parser.getEventType(); |
133 |
|
134 |
while (!endFeature){
|
135 |
switch(currentTag){
|
136 |
case KXmlParser.START_TAG:
|
137 |
if (tag.compareTo(KmlTags.NAME) == 0){ |
138 |
parser.next(); |
139 |
handler.getContentHandler().addNameToFeature(parser.getText(), feature); |
140 |
}else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){ |
141 |
parser.next(); |
142 |
String description = parser.getText();
|
143 |
}else if (tag.compareTo(KmlTags.VISIBILITY) == 0){ |
144 |
parser.next(); |
145 |
String visibility = parser.getText();
|
146 |
}else if (tag.compareTo(KmlTags.LOOKAT) == 0){ |
147 |
LookAtBinding.parse(parser, handler); |
148 |
}else if (tag.compareTo(KmlTags.STYLEURL) == 0){ |
149 |
parser.next(); |
150 |
String styleURL = parser.getText();
|
151 |
}else if (tag.compareTo(KmlTags.POINT) == 0){ |
152 |
Object point = PointTypeBinding.parse(parser, handler);
|
153 |
handler.getContentHandler().addGeometryToFeature(point, feature); |
154 |
}else if (tag.compareTo(KmlTags.LINESTRING) == 0){ |
155 |
Object lineString = LineStringTypeBinding.parse(parser, handler);
|
156 |
handler.getContentHandler().addGeometryToFeature(lineString, feature); |
157 |
}else if (tag.compareTo(KmlTags.POLYGON) == 0){ |
158 |
Object polygon = PolygonTypeBinding.parse(parser, handler);
|
159 |
handler.getContentHandler().addGeometryToFeature(polygon, feature); |
160 |
}else if (tag.compareTo(KmlTags.REGION) == 0){ |
161 |
Object bbox = RegionBinding.parse(parser, handler);
|
162 |
} |
163 |
break;
|
164 |
case KXmlParser.END_TAG:
|
165 |
if (tag.compareTo(KmlTags.PLACEMARK) == 0){ |
166 |
endFeature = true;
|
167 |
handler.getContentHandler().endFeature(feature); |
168 |
} |
169 |
break;
|
170 |
case KXmlParser.TEXT:
|
171 |
|
172 |
break;
|
173 |
} |
174 |
if (!endFeature){
|
175 |
currentTag = parser.next(); |
176 |
tag = parser.getName(); |
177 |
} |
178 |
} |
179 |
|
180 |
return feature;
|
181 |
} |
182 |
} |