svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / features / StyleMapBinding.java @ 37960
History | View | Annotate | Download (4.91 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 StyleMap tag. Example:
|
75 |
* <p>
|
76 |
* <pre>
|
77 |
* <code>
|
78 |
* <StyleMap id="msn_ylw-pushpin">
|
79 |
<Pair>
|
80 |
<key>normal</key>
|
81 |
<styleUrl>#sn_ylw-pushpin</styleUrl>
|
82 |
</Pair>
|
83 |
<Pair>
|
84 |
<key>highlight</key>
|
85 |
<styleUrl>#sh_ylw-pushpin</styleUrl>
|
86 |
</Pair>
|
87 |
</StyleMap>
|
88 |
* </code>
|
89 |
* </pre>
|
90 |
* </p>
|
91 |
* @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#stylemap
|
92 |
*/
|
93 |
public class StyleMapBinding { |
94 |
|
95 |
/**
|
96 |
* It parses the StyleMap tag
|
97 |
* @param parser
|
98 |
* The XML parser
|
99 |
* @param handler
|
100 |
* The GPE parser that contains the content handler and
|
101 |
* the error handler
|
102 |
* @throws IOException
|
103 |
* @throws XmlStreamException
|
104 |
* @throws XmlStreamException
|
105 |
* @throws IOException
|
106 |
*/
|
107 |
public static Object parse(IXmlStreamReader parser,GPEDefaultKmlParser handler) throws XmlStreamException, IOException{ |
108 |
boolean endFeature = false; |
109 |
boolean endPair = false; |
110 |
int currentTag;
|
111 |
|
112 |
QName tag = parser.getName();
|
113 |
currentTag = parser.getEventType(); |
114 |
|
115 |
XMLAttributesIterator attributesIterator = new XMLAttributesIterator(parser);
|
116 |
|
117 |
String styleId = parser.getAttributeValue(0); |
118 |
|
119 |
// System.out.println("Leyendo STYLEMAP " + styleId);
|
120 |
|
121 |
Object metadata = handler.getContentHandler().startMetadata("STYLEMAP", styleId, attributesIterator); |
122 |
|
123 |
XMLAttributesIterator attIterator = new XMLAttributesIterator(parser);
|
124 |
Object subData = null; |
125 |
|
126 |
while (!endFeature){
|
127 |
switch(currentTag){
|
128 |
case IXmlStreamReader.START_ELEMENT:
|
129 |
if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.PAIR)){
|
130 |
parser.next(); |
131 |
subData = handler.getContentHandler().startMetadata(tag.getLocalPart(), styleId, attIterator); |
132 |
} |
133 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.KEY)){ |
134 |
parser.next(); |
135 |
String key = parser.getText();
|
136 |
Object keyData = handler.getContentHandler().startMetadata(tag.getLocalPart(), key, attIterator);
|
137 |
handler.getContentHandler().addMetadataToMetadata(keyData, subData); |
138 |
|
139 |
|
140 |
} |
141 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.STYLEURL)){ |
142 |
parser.next(); |
143 |
String styleUrl = parser.getText();
|
144 |
Object styleUrlData = handler.getContentHandler().startMetadata(tag.getLocalPart(), styleUrl, attIterator);
|
145 |
handler.getContentHandler().addMetadataToMetadata(styleUrlData, subData); |
146 |
|
147 |
} |
148 |
break;
|
149 |
case IXmlStreamReader.END_ELEMENT:
|
150 |
if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.STYLEMAP)){
|
151 |
endFeature = true;
|
152 |
} |
153 |
else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.PAIR)){ |
154 |
handler.getContentHandler().addMetadataToMetadata(subData, metadata); |
155 |
endPair = true;
|
156 |
} |
157 |
|
158 |
break;
|
159 |
case IXmlStreamReader.CHARACTERS:
|
160 |
break;
|
161 |
} |
162 |
if (!endFeature){
|
163 |
currentTag = parser.next(); |
164 |
tag = parser.getName(); |
165 |
// System.out.println("tag = " + tag);
|
166 |
} |
167 |
} |
168 |
return metadata;
|
169 |
} |
170 |
} |