Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / geometries / PointTypeBinding.java @ 37960

History | View | Annotate | Download (4.51 KB)

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

    
3
import java.io.IOException;
4

    
5
import javax.xml.namespace.QName;
6

    
7
import org.gvsig.gpe.kml.parser.GPEDefaultKmlParser;
8
import org.gvsig.gpe.kml.parser.v21.coordinates.CoordinatesTypeIterator;
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

    
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:PointTypeBinding.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.5  2007/05/08 08:22:37  jorpiell
66
 * Add comments to create javadocs
67
 *
68
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
69
 * Writing tests updated
70
 *
71
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
72
 * Tests updating
73
 *
74
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
75
 * Kml writing support added
76
 *
77
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
78
 * Add KML reading support
79
 *
80
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
81
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
82
 *
83
 * Revision 1.1  2007/02/28 11:48:31  csanchez
84
 * *** empty log message ***
85
 *
86
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
87
 * A?adidos los proyectos de kml y gml antiguos
88
 *
89
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
90
 * A?adido el driver de KML
91
 *
92
 *
93
 */
94
/**
95
 * It parses a Point tag. Example:
96
 * <p>
97
 * <pre>
98
 * <code>
99
 * &lt;Point gid="P6776"&gt;
100
 * &lt;coord&gt;&lt;X&gt;50.0&lt;/X&gt;&lt;Y&gt;50.0&lt;/Y&gt;&lt;/coord&gt;
101
 * &lt;/Point&gt;
102
 * </code>
103
 * </pre>
104
 * </p> 
105
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
106
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#point
107
 */
108
public class PointTypeBinding{
109

    
110
        /**
111
         * It parses the Point tag
112
         * @param parser
113
         * The XML parser
114
         * @param handler
115
         * The GPE parser that contains the content handler and
116
         * the error handler
117
         * @return
118
         * A point
119
         * @throws IOException 
120
         * @throws XmlStreamException 
121
         * @throws XmlStreamException 
122
         * @throws IOException 
123
         */
124
        public Object parse(IXmlStreamReader parser,GPEDefaultKmlParser handler) throws XmlStreamException, IOException {
125
                boolean endFeature = false;
126
                int currentTag;
127
                Object point = null;                        
128
                
129
                String id = handler.getProfile().getGeometryBinding().getID(parser, handler);
130
                
131
                
132
                        QName tag = parser.getName();
133
                        currentTag = parser.getEventType();
134
                        
135
                        while (!endFeature){
136
                                switch(currentTag){
137
                                case IXmlStreamReader.START_ELEMENT:
138
                                        if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.COORDINATES)){
139
                                                CoordinatesTypeIterator coordinatesIteartor = handler.getProfile().getCoordinatesTypeBinding();
140
                                                coordinatesIteartor.initialize(parser, handler, Kml2_1_Tags.POINT);
141
                                                point = handler.getContentHandler().startPoint(id,
142
                                                                coordinatesIteartor,
143
                                                                        Kml2_1_Tags.DEFAULT_SRS);
144
                                                return point;
145
                                        }
146
                                        break;
147
                                case IXmlStreamReader.END_ELEMENT:
148
                                        if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.POINT)){                                                
149
                                                endFeature = true;
150
                                                handler.getContentHandler().endPoint(point);
151
                                        }
152
                                        break;
153
                                case IXmlStreamReader.CHARACTERS:                                        
154
                                        
155
                                        break;
156
                                }
157
                                if (!endFeature){                                        
158
                                        currentTag = parser.next();
159
                                        tag = parser.getName();
160
                                }
161
                        }                        
162
                
163
                return point;        
164
        }
165

    
166

    
167

    
168
}