Statistics
| Revision:

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

History | View | Annotate | Download (5.19 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.GPEDeafultKmlParser;
8
import org.gvsig.gpe.kml.utils.KmlTags;
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

    
13
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
14
 *
15
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation; either version 2
20
 * of the License, or (at your option) any later version.
21
 *
22
 * This program is distributed in the hope that it will be useful,
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
 * GNU General Public License for more details.
26
 *
27
 * You should have received a copy of the GNU General Public License
28
 * along with this program; if not, write to the Free Software
29
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
30
 *
31
 * For more information, contact:
32
 *
33
 *  Generalitat Valenciana
34
 *   Conselleria d'Infraestructures i Transport
35
 *   Av. Blasco Ib??ez, 50
36
 *   46010 VALENCIA
37
 *   SPAIN
38
 *
39
 *      +34 963862235
40
 *   gvsig@gva.es
41
 *      www.gvsig.gva.es
42
 *
43
 *    or
44
 *
45
 *   IVER T.I. S.A
46
 *   Salamanca 50
47
 *   46005 Valencia
48
 *   Spain
49
 *
50
 *   +34 963163400
51
 *   dac@iver.es
52
 */
53
/* CVS MESSAGES:
54
 *
55
 * $Id: DocumentBinding.java 357 2008-01-09 17:50:08Z jpiera $
56
 * $Log$
57
 * Revision 1.2  2007/06/07 14:53:59  jorpiell
58
 * Add the schema support
59
 *
60
 * Revision 1.1  2007/05/11 07:06:29  jorpiell
61
 * Refactoring of some package names
62
 *
63
 * Revision 1.6  2007/05/09 08:36:24  jorpiell
64
 * Add the bbox to the layer
65
 *
66
 * Revision 1.5  2007/05/08 08:22:37  jorpiell
67
 * Add comments to create javadocs
68
 *
69
 * Revision 1.4  2007/05/02 11:46:50  jorpiell
70
 * Writing tests updated
71
 *
72
 * Revision 1.3  2007/04/20 08:38:59  jorpiell
73
 * Tests updating
74
 *
75
 * Revision 1.2  2007/04/14 16:08:07  jorpiell
76
 * Kml writing support added
77
 *
78
 * Revision 1.1  2007/04/13 13:16:21  jorpiell
79
 * Add KML reading support
80
 *
81
 *
82
 */
83
/**
84
 * This class parsers a Document tag. Example:
85
 * <p>
86
 * <pre>
87
 * <code>
88
 * &lt;Document&gt;
89
 * &lt;Placemark&gt;
90
 * &lt;name&gt;CDATA example&lt;/name&gt;
91
 * &lt;description&gt;Description example&lt;/description&gt;
92
 * &lt;Point&gt;
93
 * &lt;oordinates&gt;102.595626,14.996729&lt;/coordinates&gt;
94
 * &lt;/Point&gt;
95
 * &lt;/Placemark&gt;
96
 * &lt;/Document&gt;
97
 * </code>
98
 * </pre>
99
 * </p>
100
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
101
 * @see http://code.google.com/apis/kml/documentation/kml_tags_21.html#document
102
 */
103
public class DocumentBinding {
104
        
105
        /**
106
         * It parses the Document tag
107
         * @param parser
108
         * The XML parser
109
         * @param handler
110
         * The GPE parser that contains the content handler and
111
         * the error handler
112
         * @return
113
         * A Layer
114
         * @throws XmlStreamException 
115
         * @throws IOException 
116
         */
117
        public Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler) throws XmlStreamException, IOException {
118
                boolean endFeature = false;
119
                int currentTag;                
120

    
121
                String id = handler.getProfile().getFeatureBinding().getID(parser, handler);
122
                Object layer = handler.getContentHandler().startLayer(id, parser.getName().getNamespaceURI(), null, null, null, null, null);
123

    
124
                QName tag = parser.getName();
125
                currentTag = parser.getEventType();
126

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

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

    
169
                return layer;
170
        }
171
}