Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wfs / schema / XMLSchemaParser.java @ 40559

History | View | Annotate | Download (5.83 KB)

1 40559 jjdelcerro
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24 40435 jjdelcerro
package org.gvsig.remoteclient.wfs.schema;
25
26
import java.io.IOException;
27
28
import org.gvsig.compat.CompatLocator;
29
import org.gvsig.remoteclient.utils.EncodingXMLParser;
30
import org.xmlpull.v1.XmlPullParserException;
31
32
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
33
 *
34
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
35
 *
36
 * This program is free software; you can redistribute it and/or
37
 * modify it under the terms of the GNU General Public License
38
 * as published by the Free Software Foundation; either version 2
39
 * of the License, or (at your option) any later version.
40
 *
41
 * This program is distributed in the hope that it will be useful,
42
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44
 * GNU General Public License for more details.
45
 *
46
 * You should have received a copy of the GNU General Public License
47
 * along with this program; if not, write to the Free Software
48
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
49
 *
50
 * For more information, contact:
51
 *
52
 *  Generalitat Valenciana
53
 *   Conselleria d'Infraestructures i Transport
54
 *   Av. Blasco Ib??ez, 50
55
 *   46010 VALENCIA
56
 *   SPAIN
57
 *
58
 *      +34 963862235
59
 *   gvsig@gva.es
60
 *      www.gvsig.gva.es
61
 *
62
 *    or
63
 *
64
 *   IVER T.I. S.A
65
 *   Salamanca 50
66
 *   46005 Valencia
67
 *   Spain
68
 *
69
 *   +34 963163400
70
 *   dac@iver.es
71
 */
72
/* CVS MESSAGES:
73
 *
74
 * $Id: XMLSchemaParser.java 18271 2008-01-24 09:06:43Z jpiera $
75
 * $Log$
76
 * Revision 1.7  2007-01-15 13:11:00  csanchez
77
 * Sistema de Warnings y Excepciones adaptado a BasicException
78
 *
79
 * Revision 1.6  2006/12/29 17:15:48  jorpiell
80
 * Se tienen en cuenta los simpleTypes y los choices, adem?s de los atributos multiples
81
 *
82
 * Revision 1.5  2006/12/22 11:25:44  csanchez
83
 * Nuevo parser GML 2.x para gml's sin esquema
84
 *
85
 * Revision 1.4  2006/10/10 12:52:28  jorpiell
86
 * Soporte para features complejas.
87
 *
88
 * Revision 1.3  2006/10/02 08:33:49  jorpiell
89
 * Cambios del 10 copiados al head
90
 *
91
 * Revision 1.1.2.1  2006/09/19 12:23:15  jorpiell
92
 * Ya no se depende de geotools
93
 *
94
 * Revision 1.2  2006/09/18 12:08:55  jorpiell
95
 * Se han hecho algunas modificaciones que necesitaba el WFS
96
 *
97
 * Revision 1.1  2006/08/10 12:00:49  jorpiell
98
 * Primer commit del driver de Gml
99
 *
100
 * Revision 1.1  2006/05/16 14:12:56  jorpiell
101
 * A?adido el parseador de Esquemas
102
 *
103
 *
104
 */
105
/**
106
 * Thas class is used to parse a schema XSD
107
 *
108
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
109
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
110
 *
111
 */
112
public class XMLSchemaParser extends EncodingXMLParser {
113
        private String targetNameSpace = null;
114
        private String schema = "";
115
        private String encoding = "UTF-8";
116
        private String nameSpace = "";
117
        private String version = null;
118
119
120
        public XMLSchemaParser(){
121
                super();
122
        }
123
124
        public XMLSchemaParser(String schema){
125
                super();
126
                //schema instace is named with the string in "schema"
127
                this.schema = schema;
128
        }
129
130
        /**
131
         * It gets the schema from a tag. The schema is separated
132
         * of the tag name by ":".
133
         * @param tag
134
         */
135
        public void setSchemaFromMainTag(String tag){
136
                //set the name string of the namespace.
137
                int pos = tag.indexOf(":");
138
                if (pos > 0){
139
                        this.schema = tag.substring(0,pos);
140
                }else{
141
                        this.schema = "";
142
                }
143
        }
144
145
        /**
146
         * @return Returns the schema.
147
         */
148
        public String getSchema() {
149
                return schema;
150
        }
151
152
        /**
153
         * @param schema The schema to set.
154
         */
155
        public void setSchema(String schema) {
156
                this.schema = schema;
157
        }
158
159
        /**
160
         * Returns a SCHEMA:TAG
161
         * @param tag
162
         * @return SCHEMA:TAG
163
         */
164
        private String getTag(String tag){
165
                //get the tag without the namespace
166
                if (tag == null){
167
                        return null;
168
                }
169
                if ((schema == null) || (schema.equals(""))){
170
                        return tag;
171
                }
172
                return schema + ":" + tag;
173
        }
174
175
        /*
176
         *  (non-Javadoc)
177
         * @see org.xmlpull.v1.XmlPullParser#require(int, java.lang.String, java.lang.String)
178
         */
179
        public void require(int type, String namespace, String name)
180
                throws XmlPullParserException, IOException{
181
                super.require(type,namespace,getTag(name));
182
        }
183
184
        /*
185
         *  (non-Javadoc)
186
         * @see org.xmlpull.v1.XmlPullParser#getName()
187
         */
188
        public String getName(){
189
                try{
190
                String name = super.getName();
191
                if ((schema != null) || (!(schema.equals("")))){
192
                        return name.substring(name.indexOf(":") + 1,name.length());
193
                }
194
                return name;
195
                }catch (NullPointerException e){
196
                        return "";
197
                }
198
        }
199
200
        /*
201
         *  (non-Javadoc)
202
         * @see org.xmlpull.v1.XmlPullParser#getName()
203
         */
204
        public String getNameSpace(){
205
                try{
206
                String name = super.getName();
207
                if ((name!=null)&&(CompatLocator.getStringUtils().split(name,":").length > 1)){
208
                        return CompatLocator.getStringUtils().split(name, ":")[0];
209
                }
210
                return "";
211
                }catch (NullPointerException e){
212
                        return "";
213
                }
214
        }
215
216
217
        public String getversion() {
218
                if (version == null){
219
                        //return the default GML version
220
                        return "99.99.99";
221
                }
222
                return version;
223
        }
224
        public String getTargetNamespace() {
225
                return targetNameSpace;
226
        }
227
}