Statistics
| Revision:

root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / KmlParserV2_1.java @ 19962

History | View | Annotate | Download (4.34 KB)

1 18284 jpiera
package org.gvsig.gpe.kml.parser;
2
3
import java.io.IOException;
4
5 19953 jpiera
import javax.xml.namespace.QName;
6
7 18284 jpiera
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException;
8 19583 jpiera
import org.gvsig.gpe.kml.utils.KmlTags;
9 19953 jpiera
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
10 19592 groldan
import org.gvsig.gpe.xml.stream.XmlStreamException;
11 19953 jpiera
import org.gvsig.gpe.xml.utils.CompareUtils;
12 18284 jpiera
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: KmlParserV2_1.java 366 2008-01-10 09:09:38Z jpiera $
57
 * $Log$
58
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
59
 * Refactoring of some package names
60
 *
61
 * Revision 1.3  2007/05/08 09:28:17  jorpiell
62
 * Add comments to create javadocs
63
 *
64
 * Revision 1.2  2007/05/02 11:46:50  jorpiell
65
 * Writing tests updated
66
 *
67
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
68
 * Kml writing support added
69
 *
70
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
71
 * Add KML reading support
72
 *
73
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
74
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
75
 *
76
 * Revision 1.1  2007/02/28 11:48:31  csanchez
77
 * *** empty log message ***
78
 *
79
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
80
 * A?adidos los proyectos de kml y gml antiguos
81
 *
82
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
83
 * A?adido el driver de KML
84
 *
85
 *
86
 */
87
/**
88
 * This is a parser for KML 2.1
89
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
90
 */
91
public class KmlParserV2_1 extends AbstractKmlParser{
92 19162 jpiera
        private Object layer = null;
93
94 19592 groldan
        public KmlParserV2_1(IXmlStreamReader parser, GPEDeafultKmlParser handler) {
95 18284 jpiera
                super(parser, handler);
96
        }
97
98
        /*
99
         *  (non-Javadoc)
100
         * @see org.gvsig.remoteClient.gmlEngine.IFeaturesParser#getVersion()
101
         */
102
        public String getVersion() {
103
                return "2.1";
104
        }
105
106
        /*
107
         * (non-Javadoc)
108
         * @see org.gvsig.gpe.kml.versions.AbstractKmlParser#initParse()
109
         */
110
        public void initParse() throws KmlBodyParseException {
111
                boolean endFeature = false;
112
                int currentTag;
113
114
                try {
115 19953 jpiera
                        QName tag = getParser().getName();
116 18284 jpiera
                        currentTag = getParser().getEventType();
117
118
                        while (!endFeature){
119
                                switch(currentTag){
120 19710 groldan
                                case IXmlStreamReader.START_ELEMENT:
121 19953 jpiera
                                        if (CompareUtils.compareWithNamespace(tag,KmlTags.DOCUMENT)){
122 18284 jpiera
                                                 getHandler().getProfile().getDocumentBinding().parse(getParser(), getHandler());
123 19953 jpiera
                                        }else if (CompareUtils.compareWithNamespace(tag,KmlTags.FOLDER)){
124 19162 jpiera
                                                 getHandler().getProfile().getFolderBinding().parse(getParser(), getHandler(), null);
125 19953 jpiera
                                        }else if (CompareUtils.compareWithNamespace(tag,KmlTags.PLACEMARK)){
126 19162 jpiera
                                                if (layer == null){
127 19962 jpiera
                                                        layer = getHandler().getContentHandler().startLayer(null, KmlTags.NAMESPACE_21, null, null, KmlTags.DEFAULT_SRS, null, null);
128 19162 jpiera
                                                }
129
                                                Object feature = getHandler().getProfile().getPlaceMarketBinding().parse(getParser(), getHandler());
130
                                                getHandler().getContentHandler().addFeatureToLayer(feature, layer);
131 18284 jpiera
                                        }
132
                                        break;
133 19592 groldan
                                case IXmlStreamReader.END_DOCUMENT:
134 18284 jpiera
                                        endFeature = true;
135
136
                                        break;
137
                                }
138
                                if (!endFeature){
139
                                        currentTag = getParser().next();
140
                                        tag = getParser().getName();
141
                                }
142
                        }
143 19162 jpiera
                        if (layer != null){
144
                                getHandler().getContentHandler().endLayer(layer);
145
                        }
146 19592 groldan
                } catch (XmlStreamException e) {
147 18284 jpiera
                        throw new KmlBodyParseException (e);
148
                } catch (IOException e) {
149
                        throw new KmlBodyParseException (e);
150
                }
151
        }
152
153
}