Statistics
| Revision:

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

History | View | Annotate | Download (3.78 KB)

1
package org.gvsig.remoteClient.kml;
2

    
3
import java.io.IOException;
4

    
5
import org.gvsig.exceptions.BaseException;
6
import org.gvsig.remoteClient.gml.engine.AbstractFeaturesIterator;
7
import org.gvsig.remoteClient.gml.engine.readers.IReaderFile;
8
import org.gvsig.remoteClient.gml.exceptions.GMLException;
9
import org.gvsig.remoteClient.gml.factories.IGeometriesFactory;
10
import org.gvsig.remoteClient.kml.bindings.FolderBinding;
11
import org.gvsig.remoteClient.kml.bindings.PlaceMarketBinding;
12
import org.gvsig.remoteClient.kml.exceptions.KmlBodyParseException;
13
import org.kxml2.io.KXmlParser;
14
import org.xmlpull.v1.XmlPullParserException;
15

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

    
75
        /*
76
         *  (non-Javadoc)
77
         * @see org.gvsig.remoteClient.gmlEngine.IFeaturesIterator#hasNext()
78
         */
79
        public boolean hasNext() throws GMLException {
80
                boolean endFile = false;
81
                int currentTag;
82
                boolean isFolder = false;
83
                
84
                try {
85
                        String tag = reader.getName();
86
                        currentTag = reader.getEventType();
87
                        
88
                        while (!endFile){
89
                                switch(currentTag){
90
                                case KXmlParser.START_TAG:
91
                                        if (tag.compareTo(KmlTags.PLACEMARK) == 0){
92
                                                return true;
93
                                        }else if(tag.compareTo(KmlTags.FOLDER) == 0){
94
                                                currentFolder = (String)new FolderBinding(getGFactory()).parse(reader);
95
                                                tag = reader.getName();
96
                                        }
97
                                        break;
98
                                case KXmlParser.END_TAG:
99
                                        if (tag.compareTo(KmlTags.ROOT) == 0){
100
                                                endFile = true;
101
                                        }
102
                                        break;
103
                                case KXmlParser.TEXT:                                        
104
                                        break;
105
                                }
106
                                if (!endFile){                                        
107
                                        if (!isFolder){
108
                                                currentTag = reader.next();
109
                                                tag = reader.getName();
110
                                        }else{
111
                                                isFolder = false;
112
                                        }
113
                                }
114
                        }                        
115
                } catch (XmlPullParserException e) {
116
                        throw new KmlBodyParseException(e);
117
                } catch (IOException e) {
118
                        throw new KmlBodyParseException(e);
119
                }
120
                return false;
121
        }
122

    
123
        /*
124
         *  (non-Javadoc)
125
         * @see org.gvsig.remoteClient.gmlEngine.IFeaturesIterator#next()
126
         */
127
        public Object next() throws GMLException {
128
                String tag = reader.getName();
129
                                                
130
                if (tag.compareTo(KmlTags.PLACEMARK) == 0){
131
                        return new PlaceMarketBinding(gFactory).parse(reader);
132
                }
133
                return null;
134
        }
135

    
136
        /**
137
         * @return Returns the currentFolder.
138
         */
139
        public static String getCurrentFolder() {
140
                if (currentFolder == null){
141
                        return KmlTags.DEFAULT_LEGEND;
142
                }
143
                return currentFolder;
144
        }
145
}