Statistics
| Revision:

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

History | View | Annotate | Download (5.95 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.MultiGeometryBinding;
10
import org.gvsig.gpe.kml.reader.bindings.geometries.PointTypeBinding;
11
import org.gvsig.gpe.kml.reader.bindings.geometries.PolygonTypeBinding;
12
import org.gvsig.gpe.kml.reader.bindings.geometries.RegionBinding;
13
import org.kxml2.io.KXmlParser;
14
import org.xmlpull.v1.XmlPullParser;
15
import org.xmlpull.v1.XmlPullParserException;
16

    
17
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
18
 *
19
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
20
 *
21
 * This program is free software; you can redistribute it and/or
22
 * modify it under the terms of the GNU General Public License
23
 * as published by the Free Software Foundation; either version 2
24
 * of the License, or (at your option) any later version.
25
 *
26
 * This program is distributed in the hope that it will be useful,
27
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29
 * GNU General Public License for more details.
30
 *
31
 * You should have received a copy of the GNU General Public License
32
 * along with this program; if not, write to the Free Software
33
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
34
 *
35
 * For more information, contact:
36
 *
37
 *  Generalitat Valenciana
38
 *   Conselleria d'Infraestructures i Transport
39
 *   Av. Blasco Ib??ez, 50
40
 *   46010 VALENCIA
41
 *   SPAIN
42
 *
43
 *      +34 963862235
44
 *   gvsig@gva.es
45
 *      www.gvsig.gva.es
46
 *
47
 *    or
48
 *
49
 *   IVER T.I. S.A
50
 *   Salamanca 50
51
 *   46005 Valencia
52
 *   Spain
53
 *
54
 *   +34 963163400
55
 *   dac@iver.es
56
 */
57
/* CVS MESSAGES:
58
 *
59
 * $Id: PlaceMarketBinding.java 11700 2007-05-16 15:54:36Z jorpiell $
60
 * $Log$
61
 * Revision 1.3  2007-05-16 15:54:20  jorpiell
62
 * Add elements support
63
 *
64
 * Revision 1.2  2007/05/15 12:37:45  jorpiell
65
 * Add multyGeometries
66
 *
67
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
68
 * Refactoring of some package names
69
 *
70
 * Revision 1.5  2007/05/09 08:36:24  jorpiell
71
 * Add the bbox to the layer
72
 *
73
 * Revision 1.4  2007/05/08 08:22:37  jorpiell
74
 * Add comments to create javadocs
75
 *
76
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
77
 * Tests updating
78
 *
79
 * Revision 1.2  2007/04/13 13:16:21  jorpiell
80
 * Add KML reading support
81
 *
82
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
83
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
84
 *
85
 * Revision 1.1  2007/02/28 11:48:31  csanchez
86
 * *** empty log message ***
87
 *
88
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
89
 * A?adidos los proyectos de kml y gml antiguos
90
 *
91
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
92
 * A?adido el driver de KML
93
 *
94
 *
95
 */
96
/**
97
 * This class parses a PlaceMark tag. Example:
98
 * <p>
99
 * <pre>
100
 * <code>
101
 * &lt;Placemark&gt;
102
 * &lt;name&gt;CDATA example&lt;/name&gt;
103
 * &lt;description&gt;Description example&lt;/description&gt;
104
 * &lt;Point&gt;
105
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
106
 * &lt;/Point&gt;
107
 * &lt;/Placemark&gt;
108
 * </code>
109
 * </pre>
110
 * </p>
111
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
112
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#placemark
113
 */
114
public class PlaceMarketBinding {
115

    
116
        /**
117
         * It parses the PlaceMark tag
118
         * @param parser
119
         * The XML parser
120
         * @param handler
121
         * The GPE parser that contains the content handler and
122
         * the error handler
123
         * @return
124
         * A Feature
125
         * @throws IOException 
126
         * @throws XmlPullParserException 
127
         * @throws XmlPullParserException 
128
         * @throws IOException 
129
         */
130
        public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException{
131
                boolean endFeature = false;
132
                int currentTag;                
133

    
134
                String id = FeatureBinding.getID(parser, handler);
135
                Object feature = handler.getContentHandler().startFeature(id, null, null);
136

    
137

    
138
                String tag = parser.getName();
139
                currentTag = parser.getEventType();
140

    
141
                while (!endFeature){
142
                        switch(currentTag){
143
                        case KXmlParser.START_TAG:
144
                                if (tag.compareTo(KmlTags.NAME) == 0){
145
                                        parser.next();
146
                                        handler.getContentHandler().addNameToFeature(parser.getText(), feature);
147
                                }else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
148
                                        parser.next();
149
                                        String description = parser.getText();
150
                                }else if (tag.compareTo(KmlTags.VISIBILITY) == 0){
151
                                        parser.next();
152
                                        String visibility = parser.getText();
153
                                }else if (tag.compareTo(KmlTags.LOOKAT) == 0){
154
                                        LookAtBinding.parse(parser, handler);
155
                                }else if (tag.compareTo(KmlTags.STYLEURL) == 0){
156
                                        parser.next();
157
                                        String styleURL = parser.getText();
158
                                }else if (tag.compareTo(KmlTags.POINT) == 0){
159
                                        Object point = PointTypeBinding.parse(parser, handler);
160
                                        handler.getContentHandler().addGeometryToFeature(point, feature);
161
                                }else if (tag.compareTo(KmlTags.LINESTRING) == 0){
162
                                        Object lineString = LineStringTypeBinding.parse(parser, handler);
163
                                        handler.getContentHandler().addGeometryToFeature(lineString, feature);
164
                                }else if (tag.compareTo(KmlTags.POLYGON) == 0){
165
                                        Object polygon = PolygonTypeBinding.parse(parser, handler);
166
                                        handler.getContentHandler().addGeometryToFeature(polygon, feature);
167
                                }else if (tag.compareTo(KmlTags.MULTIGEOMETRY) == 0){
168
                                        Object multiGeometry = MultiGeometryBinding.parse(parser, handler);
169
                                        handler.getContentHandler().addGeometryToFeature(multiGeometry, feature);
170
                                }else if (tag.compareTo(KmlTags.REGION) == 0){
171
                                        Object bbox = RegionBinding.parse(parser, handler);
172
                                }else if (tag.compareTo(KmlTags.METADATA) == 0){
173
                                        MetadataBinding.parse(parser, handler, feature);
174
                                }
175
                                break;
176
                        case KXmlParser.END_TAG:
177
                                if (tag.compareTo(KmlTags.PLACEMARK) == 0){                                                
178
                                        endFeature = true;
179
                                        handler.getContentHandler().endFeature(feature);
180
                                }
181
                                break;
182
                        case KXmlParser.TEXT:                                        
183

    
184
                                break;
185
                        }
186
                        if (!endFeature){                                        
187
                                currentTag = parser.next();
188
                                tag = parser.getName();
189
                        }
190
                }                        
191

    
192
                return feature;
193
        }
194
}