root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / KmlFeaturesIterator.java @ 10637
History | View | Annotate | Download (3.94 KB)
1 |
package org.gvsig.gpe.kml; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import org.gvsig.exceptions.BaseException; |
6 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
7 |
import org.gvsig.gpe.kml.bindings.FolderBinding; |
8 |
import org.gvsig.gpe.kml.bindings.PlaceMarketBinding; |
9 |
import org.gvsig.gpe.kml.engine.AbstractFeaturesIterator; |
10 |
import org.gvsig.gpe.kml.engine.IReaderFile; |
11 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
12 |
import org.kxml2.io.KXmlParser; |
13 |
import org.xmlpull.v1.XmlPullParserException; |
14 |
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
16 |
*
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
18 |
*
|
19 |
* This program is free software; you can redistribute it and/or
|
20 |
* modify it under the terms of the GNU General Public License
|
21 |
* as published by the Free Software Foundation; either version 2
|
22 |
* of the License, or (at your option) any later version.
|
23 |
*
|
24 |
* This program is distributed in the hope that it will be useful,
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
27 |
* GNU General Public License for more details.
|
28 |
*
|
29 |
* You should have received a copy of the GNU General Public License
|
30 |
* along with this program; if not, write to the Free Software
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
32 |
*
|
33 |
* For more information, contact:
|
34 |
*
|
35 |
* Generalitat Valenciana
|
36 |
* Conselleria d'Infraestructures i Transport
|
37 |
* Av. Blasco Ib??ez, 50
|
38 |
* 46010 VALENCIA
|
39 |
* SPAIN
|
40 |
*
|
41 |
* +34 963862235
|
42 |
* gvsig@gva.es
|
43 |
* www.gvsig.gva.es
|
44 |
*
|
45 |
* or
|
46 |
*
|
47 |
* IVER T.I. S.A
|
48 |
* Salamanca 50
|
49 |
* 46005 Valencia
|
50 |
* Spain
|
51 |
*
|
52 |
* +34 963163400
|
53 |
* dac@iver.es
|
54 |
*/
|
55 |
/* CVS MESSAGES:
|
56 |
*
|
57 |
* $Id: KmlFeaturesIterator.java 10637 2007-03-07 08:19:11Z jorpiell $
|
58 |
* $Log$
|
59 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell
|
60 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML
|
61 |
*
|
62 |
* Revision 1.1 2007/02/28 11:48:31 csanchez
|
63 |
* *** empty log message ***
|
64 |
*
|
65 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell
|
66 |
* A?adidos los proyectos de kml y gml antiguos
|
67 |
*
|
68 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell
|
69 |
* A?adido el driver de KML
|
70 |
*
|
71 |
*
|
72 |
*/
|
73 |
/**
|
74 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
75 |
*/
|
76 |
public class KmlFeaturesIterator extends AbstractFeaturesIterator{ |
77 |
private static String currentFolder = null; |
78 |
|
79 |
public KmlFeaturesIterator(IReaderFile reader, IGeometriesFactory factory) {
|
80 |
super(reader, factory);
|
81 |
} |
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesIterator#hasNext()
|
86 |
*/
|
87 |
public boolean hasNext() throws BaseException { |
88 |
boolean endFile = false; |
89 |
int currentTag;
|
90 |
boolean isFolder = false; |
91 |
|
92 |
try {
|
93 |
String tag = reader.getName();
|
94 |
currentTag = reader.getEventType(); |
95 |
|
96 |
while (!endFile){
|
97 |
switch(currentTag){
|
98 |
case KXmlParser.START_TAG:
|
99 |
if (tag.compareTo(KmlTags.PLACEMARK) == 0){ |
100 |
return true; |
101 |
}else if(tag.compareTo(KmlTags.FOLDER) == 0){ |
102 |
currentFolder = (String)new FolderBinding(getGFactory()).parse(reader); |
103 |
tag = reader.getName(); |
104 |
} |
105 |
break;
|
106 |
case KXmlParser.END_TAG:
|
107 |
if (tag.compareTo(KmlTags.ROOT) == 0){ |
108 |
endFile = true;
|
109 |
} |
110 |
break;
|
111 |
case KXmlParser.TEXT:
|
112 |
break;
|
113 |
} |
114 |
if (!endFile){
|
115 |
if (!isFolder){
|
116 |
currentTag = reader.next(); |
117 |
tag = reader.getName(); |
118 |
}else{
|
119 |
isFolder = false;
|
120 |
} |
121 |
} |
122 |
} |
123 |
} catch (XmlPullParserException e) {
|
124 |
throw new KmlBodyParseException(e); |
125 |
} catch (IOException e) { |
126 |
throw new KmlBodyParseException(e); |
127 |
} |
128 |
return false; |
129 |
} |
130 |
|
131 |
/*
|
132 |
* (non-Javadoc)
|
133 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesIterator#next()
|
134 |
*/
|
135 |
public Object next() throws BaseException { |
136 |
String tag = reader.getName();
|
137 |
|
138 |
if (tag.compareTo(KmlTags.PLACEMARK) == 0){ |
139 |
return new PlaceMarketBinding(gFactory).parse(reader); |
140 |
} |
141 |
return null; |
142 |
} |
143 |
|
144 |
/**
|
145 |
* @return Returns the currentFolder.
|
146 |
*/
|
147 |
public static String getCurrentFolder() { |
148 |
if (currentFolder == null){ |
149 |
return KmlTags.DEFAULT_LEGEND;
|
150 |
} |
151 |
return currentFolder;
|
152 |
} |
153 |
} |