Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libRemoteServices / src / org / gvsig / remoteclient / wfs / schema / XMLSchemaParser.java @ 34026

History | View | Annotate | Download (4.8 KB)

1
package org.gvsig.remoteclient.wfs.schema;
2

    
3
import java.io.IOException;
4

    
5
import org.xmlpull.v1.XmlPullParserException;
6

    
7
import org.gvsig.remoteclient.utils.EncodingXMLParser;
8

    
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id: XMLSchemaParser.java 18271 2008-01-24 09:06:43Z jpiera $
52
 * $Log$
53
 * Revision 1.7  2007-01-15 13:11:00  csanchez
54
 * Sistema de Warnings y Excepciones adaptado a BasicException
55
 *
56
 * Revision 1.6  2006/12/29 17:15:48  jorpiell
57
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
58
 *
59
 * Revision 1.5  2006/12/22 11:25:44  csanchez
60
 * Nuevo parser GML 2.x para gml's sin esquema
61
 *
62
 * Revision 1.4  2006/10/10 12:52:28  jorpiell
63
 * Soporte para features complejas.
64
 *
65
 * Revision 1.3  2006/10/02 08:33:49  jorpiell
66
 * Cambios del 10 copiados al head
67
 *
68
 * Revision 1.1.2.1  2006/09/19 12:23:15  jorpiell
69
 * Ya no se depende de geotools
70
 *
71
 * Revision 1.2  2006/09/18 12:08:55  jorpiell
72
 * Se han hecho algunas modificaciones que necesitaba el WFS
73
 *
74
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
75
 * Primer commit del driver de Gml
76
 *
77
 * Revision 1.1  2006/05/16 14:12:56  jorpiell
78
 * A?adido el parseador de Esquemas
79
 * 
80
 * 
81
 */
82
/**
83
 * Thas class is used to parse a schema XSD
84
 * 
85
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
86
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
87
 * 
88
 */
89
public class XMLSchemaParser extends EncodingXMLParser {
90
        private String targetNameSpace = null;
91
        private String schema = "";
92
        private String encoding = "UTF-8";        
93
        private String nameSpace = "";
94
        private String version = null;
95
        
96
        
97
        public XMLSchemaParser(){
98
                super();                
99
        }
100
        
101
        public XMLSchemaParser(String schema){
102
                super();
103
                //schema instace is named with the string in "schema"
104
                this.schema = schema;                
105
        }
106
        
107
        /**
108
         * It gets the schema from a tag. The schema is separated
109
         * of the tag name by ":".
110
         * @param tag
111
         */
112
        public void setSchemaFromMainTag(String tag){
113
                //set the name string of the namespace.
114
                int pos = tag.indexOf(":");
115
                if (pos > 0){
116
                        this.schema = tag.substring(0,pos);
117
                }else{
118
                        this.schema = "";
119
                }
120
        }        
121

    
122
        /**
123
         * @return Returns the schema.
124
         */
125
        public String getSchema() {
126
                return schema;
127
        }
128

    
129
        /**
130
         * @param schema The schema to set.
131
         */
132
        public void setSchema(String schema) {
133
                this.schema = schema;
134
        }        
135
        
136
        /**
137
         * Returns a SCHEMA:TAG
138
         * @param tag
139
         * @return SCHEMA:TAG
140
         */
141
        private String getTag(String tag){
142
                //get the tag without the namespace
143
                if (tag == null){
144
                        return null;
145
                }
146
                if ((schema == null) || (schema.equals(""))){
147
                        return tag;
148
                }
149
                return schema + ":" + tag;
150
        }
151
        
152
        /*
153
         *  (non-Javadoc)
154
         * @see org.xmlpull.v1.XmlPullParser#require(int, java.lang.String, java.lang.String)
155
         */
156
        public void require(int type, String namespace, String name)
157
                throws XmlPullParserException, IOException{
158
                super.require(type,namespace,getTag(name));
159
        }
160
        
161
        /*
162
         *  (non-Javadoc)
163
         * @see org.xmlpull.v1.XmlPullParser#getName()
164
         */
165
        public String getName(){
166
                try{
167
                String name = super.getName();
168
                if ((schema != null) || (!(schema.equals("")))){
169
                        return name.substring(name.indexOf(":") + 1,name.length());
170
                }
171
                return name;
172
                }catch (NullPointerException e){
173
                        return "";
174
                }
175
        }
176
        
177
        /*
178
         *  (non-Javadoc)
179
         * @see org.xmlpull.v1.XmlPullParser#getName()
180
         */
181
        public String getNameSpace(){
182
                try{
183
                String name = super.getName();
184
                if ((name!=null)&&(name.split(":").length > 1)){
185
                        return name.split(":")[0];
186
                }
187
                return "";
188
                }catch (NullPointerException e){
189
                        return "";
190
                }
191
        }        
192
        
193

    
194
        public String getversion() {
195
                if (version == null){
196
                        //return the default GML version
197
                        return "99.99.99";
198
                }
199
                return version;                
200
        }
201
        public String getTargetNamespace() {
202
                return targetNameSpace;                
203
        }
204
}