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 @ 40769
History | View | Annotate | Download (3.67 KB)
1 |
/**
|
---|---|
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 |
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 |
/**
|
33 |
* Thas class is used to parse a schema XSD
|
34 |
*
|
35 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
36 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
|
37 |
*
|
38 |
*/
|
39 |
public class XMLSchemaParser extends EncodingXMLParser { |
40 |
private String targetNameSpace = null; |
41 |
private String schema = ""; |
42 |
private String encoding = "UTF-8"; |
43 |
private String nameSpace = ""; |
44 |
private String version = null; |
45 |
|
46 |
|
47 |
public XMLSchemaParser(){
|
48 |
super();
|
49 |
} |
50 |
|
51 |
public XMLSchemaParser(String schema){ |
52 |
super();
|
53 |
//schema instace is named with the string in "schema"
|
54 |
this.schema = schema;
|
55 |
} |
56 |
|
57 |
/**
|
58 |
* It gets the schema from a tag. The schema is separated
|
59 |
* of the tag name by ":".
|
60 |
* @param tag
|
61 |
*/
|
62 |
public void setSchemaFromMainTag(String tag){ |
63 |
//set the name string of the namespace.
|
64 |
int pos = tag.indexOf(":"); |
65 |
if (pos > 0){ |
66 |
this.schema = tag.substring(0,pos); |
67 |
}else{
|
68 |
this.schema = ""; |
69 |
} |
70 |
} |
71 |
|
72 |
/**
|
73 |
* @return Returns the schema.
|
74 |
*/
|
75 |
public String getSchema() { |
76 |
return schema;
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* @param schema The schema to set.
|
81 |
*/
|
82 |
public void setSchema(String schema) { |
83 |
this.schema = schema;
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* Returns a SCHEMA:TAG
|
88 |
* @param tag
|
89 |
* @return SCHEMA:TAG
|
90 |
*/
|
91 |
private String getTag(String tag){ |
92 |
//get the tag without the namespace
|
93 |
if (tag == null){ |
94 |
return null; |
95 |
} |
96 |
if ((schema == null) || (schema.equals(""))){ |
97 |
return tag;
|
98 |
} |
99 |
return schema + ":" + tag; |
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
* @see org.xmlpull.v1.XmlPullParser#require(int, java.lang.String, java.lang.String)
|
105 |
*/
|
106 |
public void require(int type, String namespace, String name) |
107 |
throws XmlPullParserException, IOException{ |
108 |
super.require(type,namespace,getTag(name));
|
109 |
} |
110 |
|
111 |
/*
|
112 |
* (non-Javadoc)
|
113 |
* @see org.xmlpull.v1.XmlPullParser#getName()
|
114 |
*/
|
115 |
public String getName(){ |
116 |
try{
|
117 |
String name = super.getName(); |
118 |
if ((schema != null) || (!(schema.equals("")))){ |
119 |
return name.substring(name.indexOf(":") + 1,name.length()); |
120 |
} |
121 |
return name;
|
122 |
}catch (NullPointerException e){ |
123 |
return ""; |
124 |
} |
125 |
} |
126 |
|
127 |
/*
|
128 |
* (non-Javadoc)
|
129 |
* @see org.xmlpull.v1.XmlPullParser#getName()
|
130 |
*/
|
131 |
public String getNameSpace(){ |
132 |
try{
|
133 |
String name = super.getName(); |
134 |
if ((name!=null)&&(CompatLocator.getStringUtils().split(name,":").length > 1)){ |
135 |
return CompatLocator.getStringUtils().split(name, ":")[0]; |
136 |
} |
137 |
return ""; |
138 |
}catch (NullPointerException e){ |
139 |
return ""; |
140 |
} |
141 |
} |
142 |
|
143 |
|
144 |
public String getversion() { |
145 |
if (version == null){ |
146 |
//return the default GML version
|
147 |
return "99.99.99"; |
148 |
} |
149 |
return version;
|
150 |
} |
151 |
public String getTargetNamespace() { |
152 |
return targetNameSpace;
|
153 |
} |
154 |
} |