Statistics
| Revision:

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

History | View | Annotate | Download (4.34 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.KMLUtilsParser;
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: ElementBinding.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/16 15:54:20  jorpiell
61
 * Add elements support
62
 *
63
 *
64
 */
65
/**
66
 * It parses an element. An element is a tag inside of a 
67
 * metadata tag
68
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
69
 */
70
public class ElementBinding {
71
        /**
72
         * It parses a xml element
73
         * @param parser
74
         * The XML parser
75
         * @param handler
76
         * The GPE parser that contains the content handler and
77
         * the error handler
78
         * @param parentElement
79
         * The parent element
80
         * @return
81
         * A Element
82
         * @throws XmlStreamException
83
         * @throws IOException
84
         */
85
        public  Object parse(IXmlStreamReader parser,GPEDeafultKmlParser handler, Object feature, Object parentElement) throws XmlStreamException, IOException {
86
                boolean endFeature = false;
87
                int currentTag;                
88
                Object element = null;        
89
                Object value = null;
90
                boolean isInitialized = false;
91
                //Used to finish to parse the current element
92
                QName elementRootType = parser.getName();
93

    
94
                String type = getType(elementRootType.getLocalPart());
95

    
96
                QName tag = parser.getName();
97
                currentTag = parser.getEventType();
98

    
99
                while (!endFeature){
100
                        switch(currentTag){
101
                        case IXmlStreamReader.START_ELEMENT:
102
                                if (!(CompareUtils.compareWithNamespace(tag,elementRootType))){
103
                                        if (!isInitialized){
104
                                                element = handler.getContentHandler().startElement(elementRootType.getNamespaceURI(),
105
                                                                KMLUtilsParser.removeBlancSymbol(elementRootType), 
106
                                                                null,
107
                                                                parentElement);
108
                                                isInitialized = true;
109
                                        }
110
                                        handler.getProfile().getElementBinding().parse(parser, handler, feature, element);
111
                                }
112

    
113
                                break;
114
                        case IXmlStreamReader.END_ELEMENT:
115
                                if (CompareUtils.compareWithNamespace(tag,elementRootType)){                                                
116
                                        endFeature = true;
117
                                        if (!isInitialized){
118
                                                element = handler.getContentHandler().startElement(
119
                                                                elementRootType.getNamespaceURI(),
120
                                                                KMLUtilsParser.removeBlancSymbol(elementRootType), 
121
                                                                value,                                                                
122
                                                                parentElement);
123
                                                isInitialized = true;
124
                                        }
125
                                        handler.getContentHandler().endElement(element);
126
                                }
127
                                break;
128
                        case IXmlStreamReader.CHARACTERS:                                        
129
                                value = getValue(type, parser.getText());
130
                                break;
131
                        }
132
                        if (!endFeature){                                        
133
                                currentTag = parser.next();
134
                                tag = parser.getName();
135
                        }
136
                }
137
                return element;                
138
        }
139

    
140
        /**
141
         * This method has to calculate the element type
142
         * @param name
143
         * Element name
144
         * @return
145
         * Element type
146
         */
147
        private  String getType(String name){
148
                return "xs:string";
149
        }
150

    
151
        /**
152
         * This method must return the element value
153
         * @param type
154
         * XS Element type
155
         * @param value
156
         * Element value like a String
157
         * @return
158
         * Element value
159
         */
160
        private  Object getValue(String type, String value){
161
                return value;
162
        }
163

    
164
}