root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / wms / wms_1_3_0 / WMSLayer1_3_0.java @ 3755
History | View | Annotate | Download (9.52 KB)
1 |
|
---|---|
2 |
package org.gvsig.remoteClient.wms.wms_1_3_0; |
3 |
|
4 |
import java.io.IOException; |
5 |
import java.util.ArrayList; |
6 |
import java.util.TreeMap; |
7 |
|
8 |
import org.gvsig.remoteClient.utils.BoundaryBox; |
9 |
import org.gvsig.remoteClient.utils.CapabilitiesTags; |
10 |
import org.gvsig.remoteClient.utils.Utilities; |
11 |
import org.gvsig.remoteClient.wms.WMSDimension; |
12 |
import org.kxml2.io.KXmlParser; |
13 |
import org.xmlpull.v1.XmlPullParserException; |
14 |
|
15 |
|
16 |
/**
|
17 |
* <p>WMS Layer for WMS 1.3.0</p>
|
18 |
*
|
19 |
*/
|
20 |
public class WMSLayer1_3_0 extends org.gvsig.remoteClient.wms.WMSLayer { |
21 |
|
22 |
|
23 |
public WMSLayer1_3_0()
|
24 |
{ |
25 |
children = new ArrayList(); |
26 |
} |
27 |
/**
|
28 |
* <p>Parses the contents of the parser(WMSCapabilities)
|
29 |
* to extract the information about an WMSLayer</p>
|
30 |
*
|
31 |
*/
|
32 |
public void parse(KXmlParser parser, TreeMap layerTreeMap) |
33 |
throws IOException, XmlPullParserException |
34 |
{ |
35 |
int currentTag;
|
36 |
boolean end = false; |
37 |
String value;
|
38 |
BoundaryBox bbox; |
39 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LAYER);
|
40 |
|
41 |
readLayerAttributes( parser ); |
42 |
|
43 |
currentTag = parser.nextTag(); |
44 |
|
45 |
while (!end)
|
46 |
{ |
47 |
switch(currentTag)
|
48 |
{ |
49 |
case KXmlParser.START_TAG:
|
50 |
if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0) |
51 |
{ |
52 |
WMSLayer1_3_0 lyr = new WMSLayer1_3_0();
|
53 |
//parser.next();
|
54 |
lyr.parse(parser, layerTreeMap); |
55 |
lyr.setParent(this);
|
56 |
getChildren().add(lyr); |
57 |
// Jaume
|
58 |
if (lyr.getName()!=null) |
59 |
layerTreeMap.put(lyr.getName(), lyr); |
60 |
} |
61 |
else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION)==0){ |
62 |
// TODO comprobar que esto se necesite o se deseche
|
63 |
parser.skipSubTree(); |
64 |
} |
65 |
else if (parser.getName().compareTo(CapabilitiesTags.NAME)==0) |
66 |
{ |
67 |
value = parser.nextText(); |
68 |
if (value != null) setName(value); |
69 |
} |
70 |
else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0) |
71 |
{ |
72 |
value = parser.nextText(); |
73 |
if (value != null) setTitle(value); |
74 |
} |
75 |
else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0) |
76 |
{ |
77 |
value = parser.nextText(); |
78 |
if (value != null) setAbstract(value); |
79 |
} |
80 |
else if (parser.getName().compareTo(CapabilitiesTags.CRS)==0) |
81 |
{ |
82 |
value = parser.nextText(); |
83 |
if (value != null){ |
84 |
String[] srs = value.split(" "); |
85 |
for (int i = 0; i < srs.length; i++) { |
86 |
addSrs(srs[i]); |
87 |
} |
88 |
|
89 |
} |
90 |
} |
91 |
else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0) |
92 |
{ |
93 |
bbox = new BoundaryBox();
|
94 |
value = parser.getAttributeValue("",CapabilitiesTags.CRS);
|
95 |
if (value != null) |
96 |
bbox.setSrs(value); |
97 |
value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
98 |
if ((value != null) && (Utilities.isNumber(value))) |
99 |
bbox.setXmin(Double.parseDouble(value));
|
100 |
value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
101 |
if ((value != null) && (Utilities.isNumber(value))) |
102 |
bbox.setYmin(Double.parseDouble(value));
|
103 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
104 |
if ((value != null) && (Utilities.isNumber(value))) |
105 |
bbox.setXmax(Double.parseDouble(value));
|
106 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
107 |
if ((value != null) && (Utilities.isNumber(value))) |
108 |
bbox.setYmax(Double.parseDouble(value));
|
109 |
|
110 |
//X and Y spatial resolution in the units if that CRS.
|
111 |
value = parser.getAttributeValue("",CapabilitiesTags.RESX);
|
112 |
if ((value != null) && (Utilities.isNumber(value))) |
113 |
//bbox.setYmax(Double.parseDouble(value));
|
114 |
value = parser.getAttributeValue("",CapabilitiesTags.RESY);
|
115 |
if ((value != null) && (Utilities.isNumber(value))) |
116 |
//bbox.setYmax(Double.parseDouble(value));
|
117 |
|
118 |
addBBox(bbox); |
119 |
} |
120 |
else if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX)==0) |
121 |
{ |
122 |
//minimum bounding rectangle in decimal degrees of the area covered by the layer.
|
123 |
bbox = parseEXGeographicBBTag(parser); |
124 |
addBBox(bbox); |
125 |
setLatLonBox(bbox); |
126 |
} |
127 |
else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0) |
128 |
{ |
129 |
value = parser.getAttributeValue("",CapabilitiesTags.MIN);
|
130 |
if ((value != null) && (Utilities.isNumber(value))) |
131 |
setScaleMin(Double.parseDouble(value));
|
132 |
value = parser.getAttributeValue("",CapabilitiesTags.MAX);
|
133 |
if ((value != null) && (Utilities.isNumber(value))) |
134 |
setScaleMax(Double.parseDouble(value));
|
135 |
} |
136 |
else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0) |
137 |
{ |
138 |
WMSStyle1_3_0 style = new WMSStyle1_3_0();
|
139 |
style.parse(parser); |
140 |
if ((style != null) && (style.getName() != null)) |
141 |
{ |
142 |
styles.add(style); |
143 |
} |
144 |
} |
145 |
else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0) |
146 |
{ |
147 |
WMSDimension dim = new WMSDimension();
|
148 |
dim.parse(parser); |
149 |
if ((dim != null) && (dim.getName() != null)) |
150 |
{ |
151 |
addDimension(dim); |
152 |
} |
153 |
} |
154 |
else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST)==0) |
155 |
{ |
156 |
parseKeywordList(parser); |
157 |
} |
158 |
break;
|
159 |
case KXmlParser.END_TAG:
|
160 |
if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0) |
161 |
end = true;
|
162 |
break;
|
163 |
case KXmlParser.TEXT:
|
164 |
break;
|
165 |
} |
166 |
currentTag = parser.next(); |
167 |
} |
168 |
} |
169 |
|
170 |
|
171 |
/**
|
172 |
* <p>Parses the EX_GeographicBoundingBox </p>
|
173 |
*/
|
174 |
private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException |
175 |
{ |
176 |
int currentTag;
|
177 |
boolean end = false; |
178 |
BoundaryBox bbox = new BoundaryBox ();
|
179 |
String value;
|
180 |
|
181 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
|
182 |
currentTag = parser.next(); |
183 |
|
184 |
while (!end)
|
185 |
{ |
186 |
switch(currentTag)
|
187 |
{ |
188 |
case KXmlParser.START_TAG:
|
189 |
if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE)==0) |
190 |
{ |
191 |
value = parser.nextText(); |
192 |
if ((value != null) && (Utilities.isNumber(value))) |
193 |
bbox.setXmin(Double.parseDouble(value));
|
194 |
} |
195 |
else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE)==0) |
196 |
{ |
197 |
value = parser.nextText(); |
198 |
if ((value != null) && (Utilities.isNumber(value))) |
199 |
bbox.setXmax(Double.parseDouble(value));
|
200 |
} |
201 |
else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE)==0) |
202 |
{ |
203 |
value = parser.nextText(); |
204 |
if ((value != null) && (Utilities.isNumber(value))) |
205 |
bbox.setYmax(Double.parseDouble(value));
|
206 |
} |
207 |
else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE)==0) |
208 |
{ |
209 |
value = parser.nextText(); |
210 |
if ((value != null) && (Utilities.isNumber(value))) |
211 |
bbox.setYmin(Double.parseDouble(value));
|
212 |
} |
213 |
break;
|
214 |
case KXmlParser.END_TAG:
|
215 |
if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX) == 0) |
216 |
end = true;
|
217 |
break;
|
218 |
case KXmlParser.TEXT:
|
219 |
break;
|
220 |
} |
221 |
if (!end)
|
222 |
currentTag = parser.next(); |
223 |
} |
224 |
parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
|
225 |
bbox.setSrs("CRS:84");
|
226 |
return bbox;
|
227 |
} |
228 |
|
229 |
public String toString(){ |
230 |
return super.toString(); |
231 |
} |
232 |
} |