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