svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wfs / wfs_1_1_0 / WFSFeature1_1_0.java @ 40769
History | View | Annotate | Download (8.66 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.wfs_1_1_0; |
25 | |||
26 | import java.io.IOException; |
||
27 | |||
28 | import org.kxml2.io.KXmlParser; |
||
29 | import org.xmlpull.v1.XmlPullParserException; |
||
30 | |||
31 | import org.gvsig.compat.CompatLocator; |
||
32 | import org.gvsig.compat.lang.StringUtils; |
||
33 | import org.gvsig.remoteclient.utils.BoundaryBox; |
||
34 | import org.gvsig.remoteclient.utils.CapabilitiesTags; |
||
35 | import org.gvsig.remoteclient.utils.Utilities; |
||
36 | import org.gvsig.remoteclient.wfs.WFSFeature; |
||
37 | import org.gvsig.remoteclient.wfs.WFSServiceInformation; |
||
38 | import org.gvsig.remoteclient.wfs.schema.GMLTags; |
||
39 | import org.gvsig.remoteclient.wfs.schema.XMLNameSpace; |
||
40 | |||
41 | /**
|
||
42 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
43 | */
|
||
44 | public class WFSFeature1_1_0 extends WFSFeature{ |
||
45 | |||
46 | private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
||
47 | |||
48 | public WFSFeature1_1_0(WFSServiceInformation serviceInformation) {
|
||
49 | super(serviceInformation);
|
||
50 | } |
||
51 | |||
52 | WFSFeature1_1_0(WFSServiceInformation serviceInformation, String name) {
|
||
53 | super(serviceInformation, name);
|
||
54 | } |
||
55 | |||
56 | /**
|
||
57 | * <p>Parses the contents of the parser(WMSCapabilities)
|
||
58 | * to extract the information about an WMSLayer</p>
|
||
59 | * @throws IOException
|
||
60 | * @throws XmlPullParserException
|
||
61 | *
|
||
62 | */
|
||
63 | public void parse(KXmlParser parser) throws XmlPullParserException, IOException{ |
||
64 | int currentTag;
|
||
65 | boolean end = false; |
||
66 | |||
67 | parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.WFS_FEATURETYPE);
|
||
68 | |||
69 | for (int i=0 ; i<parser.getAttributeCount() ; i++){ |
||
70 | String[] attName = stringUtils.split(parser.getAttributeName(i), ":"); |
||
71 | if (attName.length == 2){ |
||
72 | if (attName[0].compareTo(GMLTags.XML_NAMESPACE)==0){ |
||
73 | XMLNameSpace nameSpace = new XMLNameSpace(attName[1],parser.getAttributeValue(i)); |
||
74 | this.setNamespace(nameSpace);
|
||
75 | } |
||
76 | } |
||
77 | } |
||
78 | |||
79 | currentTag = parser.next(); |
||
80 | while (!end)
|
||
81 | { |
||
82 | switch(currentTag)
|
||
83 | { |
||
84 | case KXmlParser.START_TAG:
|
||
85 | if (parser.getName().compareToIgnoreCase(CapabilitiesTags.NAME)==0) |
||
86 | { |
||
87 | this.setName(parser.nextText());
|
||
88 | }else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.TITLE)==0){ |
||
89 | this.setTitle(parser.nextText());
|
||
90 | }else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.WFS_KEYWORDS)==0){ |
||
91 | parser.nextTag(); |
||
92 | while (parser.getName().compareTo(CapabilitiesTags.KEYWORD)==0){ |
||
93 | parser.next(); |
||
94 | String keyword = parser.getText();
|
||
95 | if ((keyword != null) || (!(keyword.equals("")))){ |
||
96 | this.addKeyword(keyword);
|
||
97 | } |
||
98 | //Keyword end tag
|
||
99 | parser.nextTag(); |
||
100 | //Keyword start tag?
|
||
101 | parser.nextTag(); |
||
102 | } |
||
103 | |||
104 | |||
105 | } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.KEYWORD)==0){ |
||
106 | this.addKeyword(parser.nextText());
|
||
107 | } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.SRS)==0 |
||
108 | || parser.getName().compareToIgnoreCase(CapabilitiesTags.OTHERSRS)==0){
|
||
109 | String value = parser.nextText();
|
||
110 | if (value != null){ |
||
111 | String[] mySRSs = stringUtils.split(value, " "); |
||
112 | for (int i = 0; i < mySRSs.length; i++) { |
||
113 | this.addSRS(mySRSs[i]);
|
||
114 | } |
||
115 | |||
116 | } |
||
117 | } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.DEAFAULTSRS)==0){ |
||
118 | String value = parser.nextText();
|
||
119 | setDefaultSRS(value.trim()); |
||
120 | } else if (parser.getName().compareToIgnoreCase(CapabilitiesTags.LATLONGBOUNDINGBOX)==0){ |
||
121 | BoundaryBox bbox = new BoundaryBox();
|
||
122 | bbox.setSrs(CapabilitiesTags.EPSG_4326); |
||
123 | String value = parser.getAttributeValue("",CapabilitiesTags.MINX); |
||
124 | if ((value != null) && (Utilities.isNumber(value))) |
||
125 | bbox.setXmin(Double.parseDouble(value));
|
||
126 | value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
||
127 | if ((value != null) && (Utilities.isNumber(value))) |
||
128 | bbox.setYmin(Double.parseDouble(value));
|
||
129 | value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
||
130 | if ((value != null) && (Utilities.isNumber(value))) |
||
131 | bbox.setXmax(Double.parseDouble(value));
|
||
132 | value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
||
133 | if ((value != null) && (Utilities.isNumber(value))) |
||
134 | bbox.setYmax(Double.parseDouble(value));
|
||
135 | this.addBBox(bbox);
|
||
136 | this.setLatLonBbox(bbox);
|
||
137 | } else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0){ |
||
138 | BoundaryBox bbox = new BoundaryBox();
|
||
139 | String value = parser.getAttributeValue("",CapabilitiesTags.SRS); |
||
140 | if (value != null) |
||
141 | bbox.setSrs(value); |
||
142 | value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
||
143 | if ((value != null) && (Utilities.isNumber(value))) |
||
144 | bbox.setXmin(Double.parseDouble(value));
|
||
145 | value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
||
146 | if ((value != null) && (Utilities.isNumber(value))) |
||
147 | bbox.setYmin(Double.parseDouble(value));
|
||
148 | value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
||
149 | if ((value != null) && (Utilities.isNumber(value))) |
||
150 | bbox.setXmax(Double.parseDouble(value));
|
||
151 | value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
||
152 | if ((value != null) && (Utilities.isNumber(value))) |
||
153 | bbox.setYmax(Double.parseDouble(value));
|
||
154 | if (bbox.getSrs() != null){ |
||
155 | this.addBBox(bbox);
|
||
156 | this.addSRS(bbox.getSrs());
|
||
157 | } |
||
158 | } else if (CapabilitiesTags.WGS84BOUNDINGBOX.equals(parser.getName())){ |
||
159 | String lowerCorner = null; |
||
160 | String upperCorner = null; |
||
161 | parser.next(); |
||
162 | String tagName = parser.getName();
|
||
163 | while(!CapabilitiesTags.WGS84BOUNDINGBOX.equals(tagName)){
|
||
164 | if ((CapabilitiesTags.LOWERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){
|
||
165 | parser.next(); |
||
166 | lowerCorner = parser.getText(); |
||
167 | }else if ((CapabilitiesTags.UPPERCORNER.equals(tagName)) && (KXmlParser.START_TAG == currentTag)){ |
||
168 | parser.next(); |
||
169 | upperCorner = parser.getText(); |
||
170 | } |
||
171 | currentTag = parser.next(); |
||
172 | tagName = parser.getName(); |
||
173 | } |
||
174 | if ((lowerCorner != null) && (upperCorner != null)){ |
||
175 | BoundaryBox bbox = new BoundaryBox();
|
||
176 | bbox.setSrs("EPSG:4326");
|
||
177 | String[] lowerCoordinates = stringUtils.split(lowerCorner, "[! \t\r\n]"); |
||
178 | if (lowerCoordinates.length >= 2){ |
||
179 | try{
|
||
180 | bbox.setXmin(Double.valueOf(lowerCoordinates[0]).doubleValue()); |
||
181 | bbox.setYmin(Double.valueOf(lowerCoordinates[1]).doubleValue()); |
||
182 | }catch(NumberFormatException e){ |
||
183 | //Is not a number
|
||
184 | } |
||
185 | } |
||
186 | String[] upperCoordinates = stringUtils.split(upperCorner, "[! \t\r\n]"); |
||
187 | if (upperCoordinates.length >= 2){ |
||
188 | try{
|
||
189 | bbox.setXmax(Double.valueOf(upperCoordinates[0]).doubleValue()); |
||
190 | bbox.setYmax(Double.valueOf(upperCoordinates[1]).doubleValue()); |
||
191 | }catch(NumberFormatException e){ |
||
192 | //Is not a number
|
||
193 | } |
||
194 | } |
||
195 | bbox = BoundaryBox.clipGeodeticBBox(bbox); |
||
196 | this.addBBox(bbox);
|
||
197 | this.setLatLonBbox(bbox);
|
||
198 | } |
||
199 | } |
||
200 | |||
201 | break;
|
||
202 | case KXmlParser.END_TAG:
|
||
203 | if (parser.getName().compareTo(CapabilitiesTags.WFS_FEATURETYPE) == 0) |
||
204 | end = true;
|
||
205 | break;
|
||
206 | case KXmlParser.TEXT:
|
||
207 | break;
|
||
208 | } |
||
209 | if (!end){
|
||
210 | currentTag = parser.next(); |
||
211 | } |
||
212 | } |
||
213 | } |
||
214 | } |