svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / features / StyleBinding.java @ 37960
History | View | Annotate | Download (7.89 KB)
1 |
package org.gvsig.gpe.kml.parser.v21.features; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import javax.xml.namespace.QName; |
6 |
|
7 |
import org.gvsig.gpe.containers.MetaData; |
8 |
import org.gvsig.gpe.kml.parser.GPEDefaultKmlParser; |
9 |
import org.gvsig.gpe.kml.utils.Kml2_1_Tags; |
10 |
import org.gvsig.gpe.xml.stream.IXmlStreamReader; |
11 |
import org.gvsig.gpe.xml.stream.XmlStreamException; |
12 |
import org.gvsig.gpe.xml.utils.CompareUtils; |
13 |
import org.gvsig.gpe.xml.utils.XMLAttributesIterator; |
14 |
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
16 |
*
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
21 |
* as published by the Free Software Foundation; either version 2
|
22 |
* of the License, or (at your option) any later version.
|
23 |
*
|
24 |
* This program is distributed in the hope that it will be useful,
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27 |
* GNU General Public License for more details.
|
28 |
*
|
29 |
* You should have received a copy of the GNU General Public License
|
30 |
* along with this program; if not, write to the Free Software
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
32 |
*
|
33 |
* For more information, contact:
|
34 |
*
|
35 |
* Generalitat Valenciana
|
36 |
* Conselleria d'Infraestructures i Transport
|
37 |
* Av. Blasco Ib??ez, 50
|
38 |
* 46010 VALENCIA
|
39 |
* SPAIN
|
40 |
*
|
41 |
* +34 963862235
|
42 |
* gvsig@gva.es
|
43 |
* www.gvsig.gva.es
|
44 |
*
|
45 |
* or
|
46 |
*
|
47 |
* IVER T.I. S.A
|
48 |
* Salamanca 50
|
49 |
* 46005 Valencia
|
50 |
* Spain
|
51 |
*
|
52 |
* +34 963163400
|
53 |
* dac@iver.es
|
54 |
*/
|
55 |
/* CVS MESSAGES:
|
56 |
*
|
57 |
* $Id: StyleBinding.java 357 2008-01-09 17:50:08Z jpiera $
|
58 |
* $Log$
|
59 |
* Revision 1.2 2007/06/07 14:53:59 jorpiell
|
60 |
* Add the schema support
|
61 |
*
|
62 |
* Revision 1.1 2007/05/11 07:06:29 jorpiell
|
63 |
* Refactoring of some package names
|
64 |
*
|
65 |
* Revision 1.2 2007/05/08 08:22:37 jorpiell
|
66 |
* Add comments to create javadocs
|
67 |
*
|
68 |
* Revision 1.1 2007/04/13 13:16:21 jorpiell
|
69 |
* Add KML reading support
|
70 |
*
|
71 |
*
|
72 |
*/
|
73 |
/**
|
74 |
* This class parses a Style tag. Example:
|
75 |
* <p>
|
76 |
* <pre>
|
77 |
* <code>
|
78 |
* <Style id="globeIcon">
|
79 |
* <IconStyle>
|
80 |
* <Icon>
|
81 |
* <href>http://maps.google.com/mapfiles/kml/pal3/icon19.png</href>
|
82 |
* </Icon>
|
83 |
* </IconStyle>
|
84 |
* <LineStyle>
|
85 |
* <width>2</width>
|
86 |
* </LineStyle>
|
87 |
* </Style>
|
88 |
* </code>
|
89 |
* </pre>
|
90 |
* </p>
|
91 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
92 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#style
|
93 |
*/
|
94 |
public class StyleBinding { |
95 |
|
96 |
/**
|
97 |
* It parses the Style tag
|
98 |
* @param parser
|
99 |
* The XML parser
|
100 |
* @param handler
|
101 |
* The GPE parser that contains the content handler and
|
102 |
* the error handler
|
103 |
* @throws IOException
|
104 |
* @throws XmlStreamException
|
105 |
* @throws XmlStreamException
|
106 |
* @throws IOException
|
107 |
*/
|
108 |
public static Object parse(IXmlStreamReader parser,GPEDefaultKmlParser handler) throws XmlStreamException, IOException{ |
109 |
boolean endFeature = false; |
110 |
boolean endIconStyle = false; |
111 |
boolean endLineStyle = false; |
112 |
boolean endPolyStyle = false; |
113 |
int currentTag;
|
114 |
|
115 |
QName tag = parser.getName();
|
116 |
currentTag = parser.getEventType(); |
117 |
|
118 |
XMLAttributesIterator attributesIterator = new XMLAttributesIterator(parser);
|
119 |
|
120 |
String styleId = parser.getAttributeValue(0); |
121 |
Object metadata = handler.getContentHandler().startMetadata("STYLE", styleId, attributesIterator); |
122 |
|
123 |
// System.out.println("Leyendo STYLE " + styleId);
|
124 |
|
125 |
XMLAttributesIterator attIterator = new XMLAttributesIterator(parser);
|
126 |
Object subData = null; |
127 |
Object iconData = null; |
128 |
|
129 |
while (!endFeature){
|
130 |
switch(currentTag){
|
131 |
case IXmlStreamReader.START_ELEMENT:
|
132 |
if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.ICON_STYLE)){
|
133 |
// parser.next();
|
134 |
subData = handler.getContentHandler().startMetadata(tag.getLocalPart(), styleId, attIterator); |
135 |
} |
136 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.LINE_STYLE)){ |
137 |
// parser.next();
|
138 |
subData = handler.getContentHandler().startMetadata(tag.getLocalPart(), styleId, attIterator); |
139 |
|
140 |
|
141 |
} |
142 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.POLY_STYLE)){ |
143 |
// parser.next();
|
144 |
subData = handler.getContentHandler().startMetadata(tag.getLocalPart(), styleId, attIterator); |
145 |
|
146 |
} |
147 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.ICON)){ |
148 |
parser.next(); |
149 |
iconData = handler.getContentHandler().startMetadata(tag.getLocalPart(), styleId, attIterator); |
150 |
handler.getContentHandler().addMetadataToMetadata(iconData, subData); |
151 |
|
152 |
} |
153 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.HREF)){ |
154 |
parser.next(); |
155 |
String str = parser.getText();
|
156 |
Object hrefData = handler.getContentHandler().startMetadata(tag.getLocalPart(), str, attIterator);
|
157 |
handler.getContentHandler().addMetadataToMetadata(hrefData, iconData); |
158 |
} |
159 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.SCALE)){ |
160 |
parser.next(); |
161 |
String str = parser.getText();
|
162 |
Object scaleData = handler.getContentHandler().startMetadata(tag.getLocalPart(), str, attIterator);
|
163 |
if (subData != null) |
164 |
handler.getContentHandler().addMetadataToMetadata(scaleData, subData); |
165 |
} |
166 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.POLY_FILL)){ |
167 |
parser.next(); |
168 |
String str = parser.getText();
|
169 |
Object fillData = handler.getContentHandler().startMetadata(tag.getLocalPart(), str, attIterator);
|
170 |
handler.getContentHandler().addMetadataToMetadata(fillData, subData); |
171 |
} |
172 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.POLY_OUTLINE)){ |
173 |
parser.next(); |
174 |
String str = parser.getText();
|
175 |
Object outlineData = handler.getContentHandler().startMetadata(tag.getLocalPart(), str, attIterator);
|
176 |
handler.getContentHandler().addMetadataToMetadata(outlineData, subData); |
177 |
} |
178 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.HEADING)){ |
179 |
parser.next(); |
180 |
String str = parser.getText();
|
181 |
Object headingData = handler.getContentHandler().startMetadata(tag.getLocalPart(), str, attIterator);
|
182 |
handler.getContentHandler().addMetadataToMetadata(headingData, subData); |
183 |
} |
184 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.COLOR)){ |
185 |
// TODO: REVISAR ESTO PARA CUANDO EL COLOR SE ASIGNA AL ICONSTYLE
|
186 |
parser.next(); |
187 |
String color = parser.getText();
|
188 |
Object colorData = handler.getContentHandler().startMetadata(tag.getLocalPart(), color, attIterator);
|
189 |
if (subData != null) |
190 |
handler.getContentHandler().addMetadataToMetadata(colorData, subData); |
191 |
|
192 |
} |
193 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.WIDTH)){ |
194 |
parser.next(); |
195 |
String width = parser.getText();
|
196 |
Object widthData = handler.getContentHandler().startMetadata(tag.getLocalPart(), width, attIterator);
|
197 |
handler.getContentHandler().addMetadataToMetadata(widthData, subData); |
198 |
|
199 |
} |
200 |
break;
|
201 |
case IXmlStreamReader.END_ELEMENT:
|
202 |
if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.STYLE)){
|
203 |
endFeature = true;
|
204 |
} |
205 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.ICON_STYLE)){ |
206 |
handler.getContentHandler().addMetadataToMetadata(subData, metadata); |
207 |
endIconStyle = true;
|
208 |
} |
209 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.LINE_STYLE)){ |
210 |
handler.getContentHandler().addMetadataToMetadata(subData, metadata); |
211 |
endLineStyle = true;
|
212 |
} |
213 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.POLY_STYLE)){ |
214 |
handler.getContentHandler().addMetadataToMetadata(subData, metadata); |
215 |
endPolyStyle = true;
|
216 |
} |
217 |
break;
|
218 |
case IXmlStreamReader.CHARACTERS:
|
219 |
break;
|
220 |
} |
221 |
if (!endFeature){
|
222 |
currentTag = parser.next(); |
223 |
tag = parser.getName(); |
224 |
// System.out.println("tag = " + tag);
|
225 |
} |
226 |
} |
227 |
return metadata;
|
228 |
} |
229 |
} |