Statistics
| Revision:

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

History | View | Annotate | Download (5.47 KB)

1
package org.gvsig.gpe.kml.parser.v21.features;
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.utils.Kml2_1_Tags;
9
import org.gvsig.gpe.xml.stream.IXmlStreamReader;
10
import org.gvsig.gpe.xml.stream.XmlStreamException;
11
import org.gvsig.gpe.xml.utils.CompareUtils;
12
import org.gvsig.gpe.xml.utils.XMLAttributesIterator;
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: FolderBinding.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.6  2007/05/09 08:36:24  jorpiell
65
 * Add the bbox to the layer
66
 *
67
 * Revision 1.5  2007/05/08 08:22:37  jorpiell
68
 * Add comments to create javadocs
69
 *
70
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
71
 * Writing tests updated
72
 *
73
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
74
 * Tests updating
75
 *
76
 * Revision 1.2  2007/04/13 13:16:21  jorpiell
77
 * Add KML reading support
78
 *
79
 * Revision 1.1  2007/03/07 08:19:10  jorpiell
80
 * Pasadas las clases de KML de libGPE-GML a libGPE-KML
81
 *
82
 * Revision 1.1  2007/02/28 11:48:31  csanchez
83
 * *** empty log message ***
84
 *
85
 * Revision 1.1  2007/02/20 10:53:20  jorpiell
86
 * A?adidos los proyectos de kml y gml antiguos
87
 *
88
 * Revision 1.1  2007/02/12 13:49:18  jorpiell
89
 * A?adido el driver de KML
90
 *
91
 *
92
 */
93
/**
94
 * This class parses a Folder tag. Example:
95
 * <p>
96
 * <pre>
97
 * <code>
98
 * &lt;Folder&gt;
99
 * &lt;Placemark&gt;
100
 * &lt;name&gt;CDATA example&lt;/name&gt;
101
 * &lt;description&gt;Description example&lt;/description&gt;
102
 * &lt;Point&gt;
103
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
104
 * &lt;/Point&gt;
105
 * &lt;/Placemark&gt;
106
 * &lt;/Folder&gt;
107
 * </code>
108
 * </pre>
109
 * </p>
110
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
111
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#folder
112
 */
113
public class FolderBinding {
114

    
115
        /**
116
         * It parses the Folder tag
117
         * @param parser
118
         * The XML parser
119
         * @param handler
120
         * The GPE parser that contains the content handler and
121
         * the error handler
122
         * @return
123
         * A Layer
124
         * @throws IOException 
125
         * @throws XmlStreamException 
126
         */
127
        public Object parse(IXmlStreamReader parser,GPEDefaultKmlParser handler, Object parentLayer) throws XmlStreamException, IOException  {
128
                boolean endFeature = false;
129
                int currentTag;                        
130

    
131
                XMLAttributesIterator attributesIterator = new XMLAttributesIterator(parser);   
132
                
133
                String id = handler.getProfile().getFeatureBinding().getID(parser, handler);
134
                Object layer = handler.getContentHandler().startLayer(id, parser.getName().getNamespaceURI(), null, null, null, attributesIterator, parentLayer, null);
135

    
136
                parser.next();
137
                QName tag = parser.getName();
138
                currentTag = parser.getEventType();
139

    
140
                while (!endFeature){
141
                        switch(currentTag){
142
                        case IXmlStreamReader.START_ELEMENT:
143
                                if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.NAME)){
144
                                        parser.next();
145
                                        handler.getContentHandler().addNameToLayer(parser.getText(),layer);
146
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.DESCRIPTION)){
147
                                        parser.next();
148
                                        handler.getContentHandler().addDescriptionToLayer(parser.getText(),layer);
149
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.LOOKAT)){
150
                                         handler.getProfile().getLookAtBinding().parse(parser, handler);
151
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.PLACEMARK)){
152
                                        Object feature = PlaceMarketBinding.parse(parser, handler);
153
                                        handler.getContentHandler().addFeatureToLayer(feature, layer);
154
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.FOLDER)){
155
                                         handler.getProfile().getFolderBinding().parse(parser, handler, layer);
156
                                }else if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.REGION)){
157
                                        Object bbox =  handler.getProfile().getRegionBinding().parse(parser, handler);
158
                                        handler.getContentHandler().addBboxToLayer(bbox, layer);
159
                                }
160
                                break;
161
                        case IXmlStreamReader.END_ELEMENT:
162
                                if (CompareUtils.compareWithOutNamespace(tag,Kml2_1_Tags.FOLDER)){
163
                                        endFeature = true;
164
                                        handler.getContentHandler().endLayer(layer);
165
                                }
166
                                break;
167
                        case IXmlStreamReader.CHARACTERS:                                        
168

    
169
                                break;
170
                        }
171
                        if (!endFeature){                                        
172
                                currentTag = parser.next();
173
                                tag = parser.getName();
174
                        }
175
                }                        
176

    
177
                return layer;
178
        }
179

    
180
}