Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / bindings / DocumentBinding.java @ 11485

History | View | Annotate | Download (4.27 KB)

1 11205 jorpiell
package org.gvsig.gpe.kml.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.kxml2.io.KXmlParser;
9
import org.xmlpull.v1.XmlPullParser;
10
import org.xmlpull.v1.XmlPullParserException;
11
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id$
55
 * $Log$
56 11485 jorpiell
 * Revision 1.5  2007-05-08 08:22:37  jorpiell
57
 * Add comments to create javadocs
58
 *
59
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
60 11435 jorpiell
 * Writing tests updated
61
 *
62
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
63 11300 jorpiell
 * Tests updating
64
 *
65
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
66 11211 jorpiell
 * Kml writing support added
67
 *
68
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
69 11205 jorpiell
 * Add KML reading support
70
 *
71
 *
72
 */
73
/**
74 11485 jorpiell
 * This class parsers a Document tag. Example:
75
 * <p>
76
 * <pre>
77
 * <code>
78
 * &lt;Document&gt;
79
 * &lt;Placemark&gt;
80
 * &lt;name&gt;CDATA example&lt;/name&gt;
81
 * &lt;description&gt;Description example&lt;/description&gt;
82
 * &lt;Point&gt;
83
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
84
 * &lt;/Point&gt;
85
 * &lt;/Placemark&gt;
86
 * &lt;/Document&gt;
87
 * </code>
88
 * </pre>
89
 * </p>
90 11205 jorpiell
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
91 11485 jorpiell
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#document
92 11205 jorpiell
 */
93
public class DocumentBinding {
94
95 11300 jorpiell
        /**
96 11485 jorpiell
         * It parses the Document tag
97 11300 jorpiell
         * @param parser
98 11485 jorpiell
         * The XML parser
99 11300 jorpiell
         * @param handler
100 11485 jorpiell
         * The GPE parser that contains the content handler and
101
         * the error handler
102 11300 jorpiell
         * @return
103 11485 jorpiell
         * A Layer
104
         * @throws XmlPullParserException
105
         * @throws IOException
106 11300 jorpiell
         */
107 11485 jorpiell
        public static Object parse(XmlPullParser parser,GPEKmlParser handler) throws XmlPullParserException, IOException {
108 11205 jorpiell
                boolean endFeature = false;
109
                int currentTag;
110 11485 jorpiell
111
                String id = FeatureBinding.getID(parser, handler);
112 11300 jorpiell
                Object layer = handler.getContentHandler().startLayer(id, null, null, null, null, null);
113 11485 jorpiell
114
                String tag = parser.getName();
115
                currentTag = parser.getEventType();
116
117
                while (!endFeature){
118
                        switch(currentTag){
119
                        case KXmlParser.START_TAG:
120
                                if (tag.compareTo(KmlTags.OPEN) == 0){
121
                                        parser.next();
122
                                        String open = parser.getText();
123
                                }else if (tag.compareTo(KmlTags.NAME) == 0){
124
                                        parser.next();
125
                                        handler.getContentHandler().addNameToLayer(parser.getText(),layer);
126
                                }if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
127
                                        parser.next();
128
                                        handler.getContentHandler().addDescriptionToLayer(parser.getText(),layer);
129
                                }else if (tag.compareTo(KmlTags.STYLE) == 0){
130
                                        StyleBinding.parse(parser, handler);
131
                                }else if (tag.compareTo(KmlTags.FOLDER) == 0){
132
                                        FolderBinding.parse(parser, handler, layer);
133
                                }else if (tag.compareTo(KmlTags.PLACEMARK) == 0){
134
                                        Object feature = PlaceMarketBinding.parse(parser, handler);
135
                                        handler.getContentHandler().addFeatureToLayer(feature, layer);
136 11205 jorpiell
                                }
137 11485 jorpiell
                                break;
138
                        case KXmlParser.END_TAG:
139
                                if (tag.compareTo(KmlTags.DOCUMENT) == 0){
140
                                        endFeature = true;
141
                                        handler.getContentHandler().endLayer(layer);
142 11205 jorpiell
                                }
143 11485 jorpiell
                                break;
144
                        case KXmlParser.TEXT:
145
146
                                break;
147
                        }
148
                        if (!endFeature){
149
                                currentTag = parser.next();
150
                                tag = parser.getName();
151
                        }
152
                }
153
154 11300 jorpiell
                return layer;
155 11205 jorpiell
        }
156
}