Statistics
| Revision:

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

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

    
107
        /**
108
         * It parses the LineQName tag
109
         * @param parser
110
         * The XML parser
111
         * @param handler
112
         * The GPE parser that contains the content handler and
113
         * the error handler
114
         * @return
115
         * A line string
116
         * @throws IOException 
117
         * @throws XmlStreamException 
118
         * @throws XmlStreamException
119
         * @throws IOException
120
         */
121
        public Object parse(IXmlStreamReader parser,GPEDefaultKmlParser handler) throws XmlStreamException, IOException {
122
                boolean endFeature = false;
123
                int currentTag;
124
                Object lineString = null;
125

    
126
                String id = handler.getProfile().getGeometryBinding().getID(parser, handler);
127

    
128
                QName tag = parser.getName();
129
                currentTag = parser.getEventType();
130

    
131
                while (!endFeature){
132
                        switch(currentTag){
133
                        case IXmlStreamReader.START_ELEMENT:
134
                                if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.COORDINATES)){
135
                                        CoordinatesTypeIterator coordinatesIterator = handler.getProfile().getCoordinatesTypeBinding();
136
                                        coordinatesIterator.initialize(parser, handler, Kml2_1_Tags.LINESTRING);
137
                                        lineString = handler.getContentHandler().startLineString(id,
138
                                                        coordinatesIterator,                                                                
139
                                                        Kml2_1_Tags.DEFAULT_SRS);        
140
                                        return lineString;
141
                                }
142
                                break;
143
                        case IXmlStreamReader.END_ELEMENT:
144
                                if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.LINESTRING)){                                                
145
                                        endFeature = true;
146
                                        handler.getContentHandler().endLineString(lineString);
147
                                }
148
                                break;
149
                        case IXmlStreamReader.CHARACTERS:                                        
150

    
151
                                break;
152
                        }
153
                        if (!endFeature){                                        
154
                                currentTag = parser.next();
155
                                tag = parser.getName();
156
                        }
157
                }                        
158
                return lineString;        
159
        }
160
}