Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / v21 / features / DocumentBinding.java @ 19161

History | View | Annotate | Download (4.89 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: DocumentBinding.java 357 2008-01-09 17:50:08Z jpiera $
54
 * $Log$
55
 * Revision 1.2  2007/06/07 14:53:59  jorpiell
56
 * Add the schema support
57
 *
58
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
59
 * Refactoring of some package names
60
 *
61
 * Revision 1.6  2007/05/09 08:36:24  jorpiell
62
 * Add the bbox to the layer
63
 *
64
 * Revision 1.5  2007/05/08 08:22:37  jorpiell
65
 * Add comments to create javadocs
66
 *
67
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
68
 * Writing tests updated
69
 *
70
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
71
 * Tests updating
72
 *
73
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
74
 * Kml writing support added
75
 *
76
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
77
 * Add KML reading support
78
 *
79
 *
80
 */
81
/**
82
 * This class parsers a Document tag. Example:
83
 * <p>
84
 * <pre>
85
 * <code>
86
 * &lt;Document&gt;
87
 * &lt;Placemark&gt;
88
 * &lt;name&gt;CDATA example&lt;/name&gt;
89
 * &lt;description&gt;Description example&lt;/description&gt;
90
 * &lt;Point&gt;
91
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
92
 * &lt;/Point&gt;
93
 * &lt;/Placemark&gt;
94
 * &lt;/Document&gt;
95
 * </code>
96
 * </pre>
97
 * </p>
98
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
99
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#document
100
 */
101
public class DocumentBinding {
102
        
103
        /**
104
         * It parses the Document tag
105
         * @param parser
106
         * The XML parser
107
         * @param handler
108
         * The GPE parser that contains the content handler and
109
         * the error handler
110
         * @return
111
         * A Layer
112
         * @throws XmlPullParserException 
113
         * @throws IOException 
114
         */
115
        public Object parse(XmlPullParser parser,GPEDeafultKmlParser handler) throws XmlPullParserException, IOException {
116
                boolean endFeature = false;
117
                int currentTag;                
118

    
119
                String id = handler.getProfile().getFeatureBinding().getID(parser, handler);
120
                Object layer = handler.getContentHandler().startLayer(id, null, null, null, null, null, null);
121

    
122
                String tag = parser.getName();
123
                currentTag = parser.getEventType();
124

    
125
                while (!endFeature){
126
                        switch(currentTag){
127
                        case KXmlParser.START_TAG:
128
                                if (tag.compareTo(KmlTags.OPEN) == 0){
129
                                        parser.next();
130
                                        String open = parser.getText();                                                
131
                                }else if (tag.compareTo(KmlTags.NAME) == 0){
132
                                        parser.next();
133
                                        handler.getContentHandler().addNameToLayer(parser.getText(),layer);
134
                                }if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
135
                                        parser.next();
136
                                        handler.getContentHandler().addDescriptionToLayer(parser.getText(),layer);
137
                                }else if (tag.compareTo(KmlTags.STYLE) == 0){
138
                                        StyleBinding.parse(parser, handler);
139
                                }else if (tag.compareTo(KmlTags.FOLDER) == 0){
140
                                        handler.getProfile().getFolderBinding().parse(parser, handler, layer);
141
                                }else if (tag.compareTo(KmlTags.PLACEMARK) == 0){
142
                                        Object feature = PlaceMarketBinding.parse(parser, handler);
143
                                        handler.getContentHandler().addFeatureToLayer(feature, layer);
144
                                }else if (tag.compareTo(KmlTags.REGION) == 0){
145
                                        Object bbox = handler.getProfile().getRegionBinding().parse(parser, handler);
146
                                        handler.getContentHandler().addBboxToLayer(bbox, layer);
147
                                }else if (tag.compareTo(KmlTags.LOOKAT) == 0){
148
                                         handler.getProfile().getLookAtBinding().parse(parser, handler);
149
                                }
150
                                 break;
151
                        case KXmlParser.END_TAG:
152
                                if (tag.compareTo(KmlTags.DOCUMENT) == 0){
153
                                        endFeature = true;
154
                                        handler.getContentHandler().endLayer(layer);
155
                                }
156
                                break;
157
                        case KXmlParser.TEXT:                                        
158

    
159
                                break;
160
                        }
161
                        if (!endFeature){                                        
162
                                currentTag = parser.next();
163
                                tag = parser.getName();
164
                        }
165
                }                        
166

    
167
                return layer;
168
        }
169
}