Statistics
| Revision:

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

History | View | Annotate | Download (4.47 KB)

1
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: FolderBinding.java 11485 2007-05-08 08:22:37Z jorpiell $
55
 * $Log$
56
 * 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
 * Writing tests updated
61
 *
62
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
63
 * Tests updating
64
 *
65
 * Revision 1.2  2007/04/13 13:16:21  jorpiell
66
 * Add KML reading support
67
 *
68
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
69
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
70
 *
71
 * Revision 1.1  2007/02/28 11:48:31  csanchez
72
 * *** empty log message ***
73
 *
74
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
75
 * A?adidos los proyectos de kml y gml antiguos
76
 *
77
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
78
 * A?adido el driver de KML
79
 *
80
 *
81
 */
82
/**
83
 * This class parses a Folder tag. Example:
84
 * <p>
85
 * <pre>
86
 * <code>
87
 * &lt;Folder&gt;
88
 * &lt;Placemark&gt;
89
 * &lt;name&gt;CDATA example&lt;/name&gt;
90
 * &lt;description&gt;Description example&lt;/description&gt;
91
 * &lt;Point&gt;
92
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
93
 * &lt;/Point&gt;
94
 * &lt;/Placemark&gt;
95
 * &lt;/Folder&gt;
96
 * </code>
97
 * </pre>
98
 * </p>
99
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
100
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#folder
101
 */
102
public class FolderBinding {
103

    
104
        /**
105
         * It parses the Folder tag
106
         * @param parser
107
         * The XML parser
108
         * @param handler
109
         * The GPE parser that contains the content handler and
110
         * the error handler
111
         * @return
112
         * A Layer
113
         * @throws IOException 
114
         * @throws XmlPullParserException 
115
         */
116
        public static Object parse(XmlPullParser parser,GPEKmlParser handler, Object parentLayer) throws XmlPullParserException, IOException  {
117
                boolean endFeature = false;
118
                int currentTag;                        
119

    
120
                String id = FeatureBinding.getID(parser, handler);
121
                Object layer = handler.getContentHandler().startLayer(id, null, null, null, parentLayer, null);
122

    
123

    
124
                parser.next();
125
                String tag = parser.getName();
126
                currentTag = parser.getEventType();
127

    
128
                while (!endFeature){
129
                        switch(currentTag){
130
                        case KXmlParser.START_TAG:
131
                                if (tag.compareTo(KmlTags.NAME) == 0){
132
                                        parser.next();
133
                                        handler.getContentHandler().addNameToLayer(parser.getText(),layer);
134
                                }else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
135
                                        parser.next();
136
                                        handler.getContentHandler().addDescriptionToLayer(parser.getText(),layer);
137
                                }else if (tag.compareTo(KmlTags.LOOKAT) == 0){
138
                                        LookAtBinding.parse(parser, handler);
139
                                }else if (tag.compareTo(KmlTags.PLACEMARK) == 0){
140
                                        Object feature = PlaceMarketBinding.parse(parser, handler);
141
                                        handler.getContentHandler().addFeatureToLayer(feature, layer);
142
                                }else if (tag.compareTo(KmlTags.FOLDER) == 0){
143
                                        FolderBinding.parse(parser, handler, layer);
144
                                }
145
                                break;
146
                        case KXmlParser.END_TAG:
147
                                if (tag.compareTo(KmlTags.FOLDER) == 0){
148
                                        endFeature = true;
149
                                        handler.getContentHandler().endLayer(layer);
150
                                }
151
                                break;
152
                        case KXmlParser.TEXT:                                        
153

    
154
                                break;
155
                        }
156
                        if (!endFeature){                                        
157
                                currentTag = parser.next();
158
                                tag = parser.getName();
159
                        }
160
                }                        
161

    
162
                return layer;
163
        }
164

    
165
}