Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / bindings / PlaceMarketBinding.java @ 11485

History | View | Annotate | Download (5.06 KB)

1
package org.gvsig.gpe.kml.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.bindings.geometries.LineStringTypeBinding;
8
import org.gvsig.gpe.kml.bindings.geometries.PointTypeBinding;
9
import org.gvsig.gpe.kml.bindings.geometries.PolygonTypeBinding;
10
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException;
11
import org.kxml2.io.KXmlParser;
12
import org.xmlpull.v1.XmlPullParser;
13
import org.xmlpull.v1.XmlPullParserException;
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: PlaceMarketBinding.java 11485 2007-05-08 08:22:37Z jorpiell $
58
 * $Log$
59
 * Revision 1.4  2007-05-08 08:22:37  jorpiell
60
 * Add comments to create javadocs
61
 *
62
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
63
 * Tests updating
64
 *
65
 * Revision 1.2  2007/04/13 13:16:21  jorpiell
66
 * Add KML reading support
67
 *
68
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
69
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
70
 *
71
 * Revision 1.1  2007/02/28 11:48:31  csanchez
72
 * *** empty log message ***
73
 *
74
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
75
 * A?adidos los proyectos de kml y gml antiguos
76
 *
77
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
78
 * A?adido el driver de KML
79
 *
80
 *
81
 */
82
/**
83
 * This class parses a PlaceMark tag. Example:
84
 * <p>
85
 * <pre>
86
 * <code>
87
 * &lt;Placemark&gt;
88
 * &lt;name&gt;CDATA example&lt;/name&gt;
89
 * &lt;description&gt;Description example&lt;/description&gt;
90
 * &lt;Point&gt;
91
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
92
 * &lt;/Point&gt;
93
 * &lt;/Placemark&gt;
94
 * </code>
95
 * </pre>
96
 * </p>
97
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
98
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#placemark
99
 */
100
public class PlaceMarketBinding {
101

    
102
        /**
103
         * It parses the PlaceMark tag
104
         * @param parser
105
         * The XML parser
106
         * @param handler
107
         * The GPE parser that contains the content handler and
108
         * the error handler
109
         * @return
110
         * A Feature
111
         * @throws IOException 
112
         * @throws XmlPullParserException 
113
         * @throws XmlPullParserException 
114
         * @throws IOException 
115
         */
116
        public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException{
117
                boolean endFeature = false;
118
                int currentTag;                
119

    
120
                String id = FeatureBinding.getID(parser, handler);
121
                Object feature = handler.getContentHandler().startFeature(id, null, null);
122

    
123

    
124
                String tag = parser.getName();
125
                currentTag = parser.getEventType();
126

    
127
                while (!endFeature){
128
                        switch(currentTag){
129
                        case KXmlParser.START_TAG:
130
                                if (tag.compareTo(KmlTags.NAME) == 0){
131
                                        parser.next();
132
                                        handler.getContentHandler().addNameToFeature(parser.getText(), feature);
133
                                }else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
134
                                        parser.next();
135
                                        String description = parser.getText();
136
                                }else if (tag.compareTo(KmlTags.VISIBILITY) == 0){
137
                                        parser.next();
138
                                        String visibility = parser.getText();
139
                                }else if (tag.compareTo(KmlTags.LOOKAT) == 0){
140
                                        LookAtBinding.parse(parser, handler);
141
                                }else if (tag.compareTo(KmlTags.STYLEURL) == 0){
142
                                        parser.next();
143
                                        String styleURL = parser.getText();
144
                                }else if (tag.compareTo(KmlTags.POINT) == 0){
145
                                        Object point = PointTypeBinding.parse(parser, handler);
146
                                        handler.getContentHandler().addGeometryToFeature(point, feature);
147
                                }else if (tag.compareTo(KmlTags.LINESTRING) == 0){
148
                                        Object lineString = LineStringTypeBinding.parse(parser, handler);
149
                                        handler.getContentHandler().addGeometryToFeature(lineString, feature);
150
                                }else if (tag.compareTo(KmlTags.POLYGON) == 0){
151
                                        Object polygon = PolygonTypeBinding.parse(parser, handler);
152
                                        handler.getContentHandler().addGeometryToFeature(polygon, feature);
153
                                }
154
                                break;
155
                        case KXmlParser.END_TAG:
156
                                if (tag.compareTo(KmlTags.PLACEMARK) == 0){                                                
157
                                        endFeature = true;
158
                                        handler.getContentHandler().endFeature(feature);
159
                                }
160
                                break;
161
                        case KXmlParser.TEXT:                                        
162

    
163
                                break;
164
                        }
165
                        if (!endFeature){                                        
166
                                currentTag = parser.next();
167
                                tag = parser.getName();
168
                        }
169
                }                        
170

    
171
                return feature;
172
        }
173
}