Statistics
| Revision:

root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / kml / bindings / PlaceMarketBinding.java @ 18333

History | View | Annotate | Download (5.35 KB)

1
package org.gvsig.remoteClient.kml.bindings;
2

    
3
import java.io.IOException;
4
import java.util.LinkedHashMap;
5

    
6
import org.gvsig.remoteClient.gml.engine.readers.IReaderFile;
7
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
8
import org.gvsig.remoteClient.kml.KmlAttributesMap;
9
import org.gvsig.remoteClient.kml.KmlFeaturesIterator;
10
import org.gvsig.remoteClient.kml.KmlTags;
11
import org.gvsig.remoteClient.kml.bindings.geomatries.LineStringTypeBinding;
12
import org.gvsig.remoteClient.kml.bindings.geomatries.PointTypeBinding;
13
import org.gvsig.remoteClient.kml.bindings.geomatries.PolygonTypeBinding;
14
import org.gvsig.remoteClient.kml.exceptions.KmlException;
15
import org.gvsig.remoteClient.kml.exceptions.KmlBodyParseException;
16
import org.kxml2.io.KXmlParser;
17
import org.xmlpull.v1.XmlPullParserException;
18

    
19
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
20
 *
21
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
22
 *
23
 * This program is free software; you can redistribute it and/or
24
 * modify it under the terms of the GNU General Public License
25
 * as published by the Free Software Foundation; either version 2
26
 * of the License, or (at your option) any later version.
27
 *
28
 * This program is distributed in the hope that it will be useful,
29
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
 * GNU General Public License for more details.
32
 *
33
 * You should have received a copy of the GNU General Public License
34
 * along with this program; if not, write to the Free Software
35
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
36
 *
37
 * For more information, contact:
38
 *
39
 *  Generalitat Valenciana
40
 *   Conselleria d'Infraestructures i Transport
41
 *   Av. Blasco Ib??ez, 50
42
 *   46010 VALENCIA
43
 *   SPAIN
44
 *
45
 *      +34 963862235
46
 *   gvsig@gva.es
47
 *      www.gvsig.gva.es
48
 *
49
 *    or
50
 *
51
 *   IVER T.I. S.A
52
 *   Salamanca 50
53
 *   46005 Valencia
54
 *   Spain
55
 *
56
 *   +34 963163400
57
 *   dac@iver.es
58
 */
59
/* CVS MESSAGES:
60
 *
61
 * $Id: PlaceMarketBinding.java 18333 2008-01-28 13:24:27Z jpiera $
62
 * $Log$
63
 * Revision 1.1  2007-02-12 13:49:18  jorpiell
64
 * A?adido el driver de KML
65
 *
66
 *
67
 */
68
/**
69
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
70
 */
71
public class PlaceMarketBinding extends AbstractComplexBinding{
72

    
73
        public PlaceMarketBinding(IGeometriesFactory gFactory) {
74
                super(gFactory);                
75
        }
76

    
77
        public Object parse(IReaderFile reader) throws KmlException {
78
                boolean endFeature = false;
79
                int currentTag;
80
                Object feature = null;
81
                        
82
                try {
83
                        String tag = reader.getName();
84
                        currentTag = reader.getEventType();
85
                        
86
                        while (!endFeature){
87
                                switch(currentTag){
88
                                case KXmlParser.START_TAG:
89
                                        if (tag.compareTo(KmlTags.PLACEMARK) == 0){
90
                                                feature = parsePlaceMarketBody(reader);
91
                                                endFeature = true;
92
                                        }
93
                                        break;
94
                                case KXmlParser.END_TAG:
95
                                        if (tag.compareTo(KmlTags.PLACEMARK) == 0){                                                
96
                                                endFeature = true;
97
                                        }
98
                                        break;
99
                                case KXmlParser.TEXT:                                        
100
                                        
101
                                        break;
102
                                }
103
                                if (!endFeature){                                        
104
                                        currentTag = reader.next();
105
                                        tag = reader.getName();
106
                                }
107
                        }                        
108
                } catch (XmlPullParserException e) {
109
                        throw new KmlBodyParseException(e);
110
                } catch (IOException e) {
111
                        throw new KmlBodyParseException(e);
112
                }
113
                return feature;
114
        }
115

    
116
        private Object parsePlaceMarketBody(IReaderFile reader) throws KmlBodyParseException {
117
                boolean endFeature = false;
118
                int currentTag;
119
                Object geometry = null;
120
                
121
                //We have to add the default values for this feature
122
                KmlAttributesMap values = new KmlAttributesMap();        
123
                values.put(KmlTags.FOLDER_NAME,KmlFeaturesIterator.getCurrentFolder());
124
                values.put(KmlTags.NAME,"");
125
                values.put(KmlTags.DESCRIPTION,"");
126
                values.put(KmlTags.VISIBILITY,"");
127
                values.put(KmlTags.LOOKAT,new LinkedHashMap());
128
                
129
                
130
                try {
131
                        currentTag = reader.next();
132
                        String tag = reader.getName();                        
133
                        
134
                        while (!endFeature){
135
                                switch(currentTag){
136
                                case KXmlParser.START_TAG:                                        
137
                                        if (tag.compareTo(KmlTags.NAME) == 0){
138
                                                reader.next();
139
                                                values.put(KmlTags.NAME,reader.getText());
140
                                        }else if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
141
                                                reader.next();
142
                                                values.put(KmlTags.DESCRIPTION,reader.getText());
143
                                        }else if (tag.compareTo(KmlTags.VISIBILITY) == 0){
144
                                                reader.next();
145
                                                values.put(KmlTags.VISIBILITY,reader.getText());
146
                                        }else if (tag.compareTo(KmlTags.LOOKAT) == 0){
147
                                                LinkedHashMap lootAtParams = (LinkedHashMap)new LookAtBinding(getGFactory()).parse(reader);
148
                                                values.put(KmlTags.LOOKAT,lootAtParams);
149
                                        }else if (tag.compareTo(KmlTags.STYLEURL) == 0){
150
                                                
151
                                        }else if (tag.compareTo(KmlTags.POINT) == 0){
152
                                                geometry = new PointTypeBinding(getGFactory()).parse(reader);
153
                                        }else if (tag.compareTo(KmlTags.LINESTRING) == 0){
154
                                                geometry = new LineStringTypeBinding(getGFactory()).parse(reader);
155
                                        }else if (tag.compareTo(KmlTags.POLYGON) == 0){
156
                                                geometry = new PolygonTypeBinding(getGFactory()).parse(reader);
157
                                        }
158
                                        break;
159
                                case KXmlParser.END_TAG:
160
                                        if (tag.compareTo(KmlTags.PLACEMARK) == 0){
161
                                                endFeature = true;
162
                                        }
163
                                        break;
164
                                case KXmlParser.TEXT:                                        
165
                                        
166
                                        break;
167
                                }
168
                                if (!endFeature){                                        
169
                                        currentTag = reader.next();
170
                                        tag = reader.getName();
171
                                }
172
                        }                        
173
                } catch (XmlPullParserException e) {
174
                        throw new KmlBodyParseException(e);
175
                } catch (IOException e) {
176
                        throw new KmlBodyParseException(e);
177
                }        
178
                return getGFactory().createSimpleFeature("KMLFeature",null,values,geometry);
179
        }
180
}