svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / wms / wms_1_1_0 / WMSLayer1_1_0.java @ 40559
History | View | Annotate | Download (11.4 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 | |
25 | package org.gvsig.remoteclient.wms.wms_1_1_0; |
||
26 | |||
27 | import java.io.IOException; |
||
28 | import java.util.ArrayList; |
||
29 | import java.util.TreeMap; |
||
30 | |||
31 | import org.kxml2.io.KXmlParser; |
||
32 | import org.xmlpull.v1.XmlPullParserException; |
||
33 | |||
34 | import org.gvsig.compat.CompatLocator; |
||
35 | import org.gvsig.compat.lang.StringUtils; |
||
36 | import org.gvsig.remoteclient.utils.BoundaryBox; |
||
37 | import org.gvsig.remoteclient.utils.CapabilitiesTags; |
||
38 | import org.gvsig.remoteclient.utils.Utilities; |
||
39 | import org.gvsig.remoteclient.wms.WMSDimension; |
||
40 | import org.gvsig.remoteclient.wms.WMSExtent; |
||
41 | |||
42 | |||
43 | /**
|
||
44 | * <p>WMS Layer for WMS 1.1.0</p>
|
||
45 | *
|
||
46 | */
|
||
47 | public class WMSLayer1_1_0 extends org.gvsig.remoteclient.wms.WMSLayer { |
||
48 | private static final StringUtils stringUtils = CompatLocator.getStringUtils(); |
||
49 | |||
50 | /**
|
||
51 | * <p>Extents defined for the layer in the capabilities doc</p>
|
||
52 | */
|
||
53 | private java.util.ArrayList extents = new ArrayList(); |
||
54 | |||
55 | /**
|
||
56 | * <p> gets the extent vector defined in this layer</p>
|
||
57 | * @return
|
||
58 | */
|
||
59 | public ArrayList getExtents() { |
||
60 | return extents;
|
||
61 | } |
||
62 | |||
63 | public WMSExtent getExtent(String name) |
||
64 | { |
||
65 | for(int i = 0; i < extents.size(); i++ ){ |
||
66 | if(((WMSExtent)extents.get(i)).getName().compareTo(name)==0) |
||
67 | { |
||
68 | return (WMSExtent)extents.get(i);
|
||
69 | } |
||
70 | } |
||
71 | return null; |
||
72 | } |
||
73 | |||
74 | /**
|
||
75 | * <p>Adds an extent to the extent vector </p>
|
||
76 | * @param extent
|
||
77 | */
|
||
78 | public void addExtent(org.gvsig.remoteclient.wms.WMSExtent extent) { |
||
79 | extents.add(extent); |
||
80 | } |
||
81 | |||
82 | public ArrayList getDimensions() |
||
83 | { |
||
84 | WMSDimension dimension; |
||
85 | WMSExtent extent; |
||
86 | for(int i = 0; i < dimensions.size(); i++) |
||
87 | { |
||
88 | dimension = (WMSDimension)dimensions.get(i); |
||
89 | extent = getExtent(dimension.getName()); |
||
90 | if(extent != null) |
||
91 | { |
||
92 | ((WMSDimension)dimensions.get(i)).setDimensionExpression( extent.getExtentExpression()); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | WMSDimension pDimension; |
||
97 | WMSDimension myDimension; |
||
98 | ArrayList myDimensions = (ArrayList) this.dimensions.clone(); |
||
99 | ArrayList pDimensions;
|
||
100 | if (parent!=null) |
||
101 | { |
||
102 | pDimensions = parent.getDimensions(); |
||
103 | for (int i= 0; i < pDimensions.size(); i++){ |
||
104 | pDimension = (WMSDimension)pDimensions.get(i); |
||
105 | myDimension = getDimension(pDimension.getName()); |
||
106 | if (myDimension != null){ |
||
107 | pDimensions.remove(pDimension); |
||
108 | } |
||
109 | } |
||
110 | myDimensions.addAll(pDimensions); |
||
111 | } |
||
112 | return myDimensions;
|
||
113 | } |
||
114 | |||
115 | public WMSLayer1_1_0()
|
||
116 | { |
||
117 | children = new ArrayList(); |
||
118 | } |
||
119 | /**
|
||
120 | * <p>Parses the contents of the parser(WMSCapabilities)
|
||
121 | * to extract the information about an WMSLayer</p>
|
||
122 | *
|
||
123 | */
|
||
124 | public void parse(KXmlParser parser, TreeMap layerTreeMap) |
||
125 | throws IOException, XmlPullParserException |
||
126 | { |
||
127 | int currentTag;
|
||
128 | boolean end = false; |
||
129 | String value;
|
||
130 | BoundaryBox bbox; |
||
131 | parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LAYER);
|
||
132 | |||
133 | //First of all set whether the layer is Queryable reading the attribute.
|
||
134 | value = parser.getAttributeValue("", CapabilitiesTags.QUERYABLE);
|
||
135 | if (value != null) |
||
136 | { |
||
137 | if (value.compareTo("0")==0) |
||
138 | setQueryable(false);
|
||
139 | else
|
||
140 | setQueryable(true);
|
||
141 | } |
||
142 | |||
143 | currentTag = parser.nextTag(); |
||
144 | |||
145 | while (!end)
|
||
146 | { |
||
147 | switch(currentTag)
|
||
148 | { |
||
149 | case KXmlParser.START_TAG:
|
||
150 | if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0) |
||
151 | { |
||
152 | WMSLayer1_1_0 lyr = new WMSLayer1_1_0();
|
||
153 | //parser.next();
|
||
154 | lyr.parse(parser, layerTreeMap); |
||
155 | lyr.setParent(this);
|
||
156 | this.children.add(lyr);
|
||
157 | // Jaume
|
||
158 | if (lyr.getName()!=null) |
||
159 | layerTreeMap.put(lyr.getName(), lyr); |
||
160 | } |
||
161 | else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION)==0){ |
||
162 | // TODO comprobar que esto se necesite o se deseche
|
||
163 | parser.skipSubTree(); |
||
164 | } |
||
165 | else if (parser.getName().compareTo(CapabilitiesTags.NAME)==0) |
||
166 | { |
||
167 | value = parser.nextText(); |
||
168 | if (value != null) setName(value); |
||
169 | } |
||
170 | else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0) |
||
171 | { |
||
172 | value = parser.nextText(); |
||
173 | if (value != null) setTitle(value); |
||
174 | } |
||
175 | else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0) |
||
176 | { |
||
177 | value = parser.nextText(); |
||
178 | if (value != null) setAbstract(value); |
||
179 | } |
||
180 | else if (parser.getName().compareTo(CapabilitiesTags.SRS)==0) |
||
181 | { |
||
182 | value = parser.nextText(); |
||
183 | if (value != null){ |
||
184 | String[] mySRSs = stringUtils.split(value, " "); |
||
185 | for (int i = 0; i < mySRSs.length; i++) { |
||
186 | addSrs(mySRSs[i]); |
||
187 | } |
||
188 | |||
189 | } |
||
190 | } |
||
191 | else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0) |
||
192 | { |
||
193 | bbox = new BoundaryBox();
|
||
194 | value = parser.getAttributeValue("",CapabilitiesTags.SRS);
|
||
195 | if (value != null) |
||
196 | bbox.setSrs(value); |
||
197 | value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
||
198 | if ((value != null) && (Utilities.isNumber(value))) |
||
199 | bbox.setXmin(Double.parseDouble(value));
|
||
200 | value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
||
201 | if ((value != null) && (Utilities.isNumber(value))) |
||
202 | bbox.setYmin(Double.parseDouble(value));
|
||
203 | value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
||
204 | if ((value != null) && (Utilities.isNumber(value))) |
||
205 | bbox.setXmax(Double.parseDouble(value));
|
||
206 | value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
||
207 | if ((value != null) && (Utilities.isNumber(value))) |
||
208 | bbox.setYmax(Double.parseDouble(value));
|
||
209 | addBBox(bbox); |
||
210 | addSrs(bbox.getSrs()); |
||
211 | } |
||
212 | else if (parser.getName().compareTo(CapabilitiesTags.LATLONBOUNDINGBOX)==0) |
||
213 | { |
||
214 | bbox = new BoundaryBox();
|
||
215 | bbox.setSrs(CapabilitiesTags.EPSG_4326); |
||
216 | value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
||
217 | if ((value != null) && (Utilities.isNumber(value))) |
||
218 | bbox.setXmin(Double.parseDouble(value));
|
||
219 | value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
||
220 | if ((value != null) && (Utilities.isNumber(value))) |
||
221 | bbox.setYmin(Double.parseDouble(value));
|
||
222 | value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
||
223 | if ((value != null) && (Utilities.isNumber(value))) |
||
224 | bbox.setXmax(Double.parseDouble(value));
|
||
225 | value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
||
226 | if ((value != null) && (Utilities.isNumber(value))) |
||
227 | bbox.setYmax(Double.parseDouble(value));
|
||
228 | addBBox(bbox); |
||
229 | setLatLonBox(bbox); |
||
230 | addSrs(bbox.getSrs()); |
||
231 | } |
||
232 | else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0) |
||
233 | { |
||
234 | value = parser.getAttributeValue("",CapabilitiesTags.MIN);
|
||
235 | if ((value != null) && (Utilities.isNumber(value))) |
||
236 | setScaleMin(Double.parseDouble(value));
|
||
237 | value = parser.getAttributeValue("",CapabilitiesTags.MAX);
|
||
238 | if ((value != null) && (Utilities.isNumber(value))) |
||
239 | setScaleMax(Double.parseDouble(value));
|
||
240 | } |
||
241 | else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0) |
||
242 | { |
||
243 | WMSStyle1_1_0 style = new WMSStyle1_1_0();
|
||
244 | style.parse(parser); |
||
245 | if ((style != null) && (style.getName() != null)) |
||
246 | { |
||
247 | styles.add(style); |
||
248 | } |
||
249 | } |
||
250 | else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0) |
||
251 | { |
||
252 | WMSDimension dim = new WMSDimension();
|
||
253 | dim.parse(parser); |
||
254 | if ((dim != null) && (dim.getName() != null)) |
||
255 | { |
||
256 | addDimension(dim); |
||
257 | } |
||
258 | } |
||
259 | else if (parser.getName().compareTo(CapabilitiesTags.EXTENT)==0) |
||
260 | { |
||
261 | WMSExtent extent = new WMSExtent();
|
||
262 | extent.parse(parser); |
||
263 | if ((extent != null) && (extent.getName() != null)) |
||
264 | { |
||
265 | addExtent(extent); |
||
266 | |||
267 | } |
||
268 | } |
||
269 | break;
|
||
270 | case KXmlParser.END_TAG:
|
||
271 | if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0) |
||
272 | end = true;
|
||
273 | break;
|
||
274 | case KXmlParser.TEXT:
|
||
275 | break;
|
||
276 | } |
||
277 | if (!end)
|
||
278 | currentTag = parser.next(); |
||
279 | } |
||
280 | parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LAYER);
|
||
281 | } |
||
282 | |||
283 | public String toString(){ |
||
284 | return super.toString(); |
||
285 | } |
||
286 | } |