Statistics
| Revision:

root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / bindings / DocumentBinding.java @ 11205

History | View | Annotate | Download (3.19 KB)

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

    
3
import java.io.IOException;
4

    
5
import org.gvsig.gpe.kml.GPEKmlParser;
6
import org.gvsig.gpe.kml.KmlTags;
7
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException;
8
import org.kxml2.io.KXmlParser;
9
import org.xmlpull.v1.XmlPullParser;
10
import org.xmlpull.v1.XmlPullParserException;
11

    
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52
/* CVS MESSAGES:
53
 *
54
 * $Id: DocumentBinding.java 11205 2007-04-13 13:16:21Z jorpiell $
55
 * $Log$
56
 * Revision 1.1  2007-04-13 13:16:21  jorpiell
57
 * Add KML reading support
58
 *
59
 *
60
 */
61
/**
62
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
63
 */
64
public class DocumentBinding {
65
        
66
        public static void parse(XmlPullParser parser,GPEKmlParser handler) throws KmlBodyParseException {
67
                boolean endFeature = false;
68
                int currentTag;                
69
                
70
                Object layer = handler.getContentHandler().startLayer(null, null, null, null, null, null);
71
                
72
                try {
73
                        String tag = parser.getName();
74
                        currentTag = parser.getEventType();
75
                        
76
                        while (!endFeature){
77
                                switch(currentTag){
78
                                case KXmlParser.START_TAG:
79
                                        if (tag.compareTo(KmlTags.OPEN) == 0){
80
                                                parser.next();
81
                                                String open = parser.getText();                                                
82
                                        }else if (tag.compareTo(KmlTags.NAME) == 0){
83
                                                parser.next();
84
                                                handler.getContentHandler().addNameToLayer(layer, parser.getText());
85
                                        }if (tag.compareTo(KmlTags.DESCRIPTION) == 0){
86
                                                parser.next();
87
                                                handler.getContentHandler().addDescriptionToLayer(layer, parser.getText());
88
                                        }else if (tag.compareTo(KmlTags.STYLE) == 0){
89
                                                StyleBinding.parse(parser, handler);
90
                                        }else if (tag.compareTo(KmlTags.FOLDER) == 0){
91
                                                FolderBinding.parse(parser, handler);
92
                                        }
93
                                        break;
94
                                case KXmlParser.END_TAG:
95
                                        if (tag.compareTo(KmlTags.DOCUMENT) == 0){
96
                                                endFeature = true;
97
                                                handler.getContentHandler().endLayer(layer);
98
                                        }
99
                                        break;
100
                                case KXmlParser.TEXT:                                        
101
                                        
102
                                        break;
103
                                }
104
                                if (!endFeature){                                        
105
                                        currentTag = parser.next();
106
                                        tag = parser.getName();
107
                                }
108
                        }                        
109
                } catch (XmlPullParserException e) {
110
                        throw new KmlBodyParseException(e);
111
                } catch (IOException e) {
112
                        throw new KmlBodyParseException(e);
113
                }                
114
        }
115
}