Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / features / PlaceMarketBinding.java @ 18284

History | View | Annotate | Download (5.88 KB)

1
package org.gvsig.gpe.kml.parser.v21.features;
2

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.kml.GPEDeafultKmlParser;
6
import org.gvsig.gpe.kml.KmlTags;
7
import org.kxml2.io.KXmlParser;
8
import org.xmlpull.v1.XmlPullParser;
9
import org.xmlpull.v1.XmlPullParserException;
10

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

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

    
131
                String id = handler.getProfile().getFeatureBinding().getID(parser, handler);
132
                Object feature = handler.getContentHandler().startFeature(id, null, null, null);
133

    
134

    
135
                String tag = parser.getName();
136
                currentTag = parser.getEventType();
137

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

    
181
                                break;
182
                        }
183
                        if (!endFeature){                                        
184
                                currentTag = parser.next();
185
                                tag = parser.getName();
186
                        }
187
                }                        
188

    
189
                return feature;
190
        }
191
}