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