root / trunk / libraries / libRemoteServices / src / org / gvsig / remoteClient / wms / wms_1_3_0 / WMSLayer1_3_0.java @ 3775
History | View | Annotate | Download (9.54 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 |
else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0) |
91 |
{ |
92 |
bbox = new BoundaryBox();
|
93 |
value = parser.getAttributeValue("",CapabilitiesTags.CRS);
|
94 |
if (value != null) |
95 |
bbox.setSrs(value); |
96 |
value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
97 |
if ((value != null) && (Utilities.isNumber(value))) |
98 |
bbox.setXmin(Double.parseDouble(value));
|
99 |
value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
100 |
if ((value != null) && (Utilities.isNumber(value))) |
101 |
bbox.setYmin(Double.parseDouble(value));
|
102 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
103 |
if ((value != null) && (Utilities.isNumber(value))) |
104 |
bbox.setXmax(Double.parseDouble(value));
|
105 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
106 |
if ((value != null) && (Utilities.isNumber(value))) |
107 |
bbox.setYmax(Double.parseDouble(value));
|
108 |
|
109 |
//X and Y spatial resolution in the units if that CRS.
|
110 |
value = parser.getAttributeValue("",CapabilitiesTags.RESX);
|
111 |
if ((value != null) && (Utilities.isNumber(value))) |
112 |
//bbox.setYmax(Double.parseDouble(value));
|
113 |
value = parser.getAttributeValue("",CapabilitiesTags.RESY);
|
114 |
if ((value != null) && (Utilities.isNumber(value))) |
115 |
//bbox.setYmax(Double.parseDouble(value));
|
116 |
|
117 |
addBBox(bbox); |
118 |
} |
119 |
else if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX)==0) |
120 |
{ |
121 |
//minimum bounding rectangle in decimal degrees of the area covered by the layer.
|
122 |
bbox = parseEXGeographicBBTag(parser); |
123 |
addBBox(bbox); |
124 |
setLatLonBox(bbox); |
125 |
} |
126 |
else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0) |
127 |
{ |
128 |
value = parser.getAttributeValue("",CapabilitiesTags.MIN);
|
129 |
if ((value != null) && (Utilities.isNumber(value))) |
130 |
setScaleMin(Double.parseDouble(value));
|
131 |
value = parser.getAttributeValue("",CapabilitiesTags.MAX);
|
132 |
if ((value != null) && (Utilities.isNumber(value))) |
133 |
setScaleMax(Double.parseDouble(value));
|
134 |
} |
135 |
else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0) |
136 |
{ |
137 |
WMSStyle1_3_0 style = new WMSStyle1_3_0();
|
138 |
style.parse(parser); |
139 |
if ((style != null) && (style.getName() != null)) |
140 |
{ |
141 |
styles.add(style); |
142 |
} |
143 |
} |
144 |
else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0) |
145 |
{ |
146 |
WMSDimension dim = new WMSDimension();
|
147 |
dim.parse(parser); |
148 |
if ((dim != null) && (dim.getName() != null)) |
149 |
{ |
150 |
addDimension(dim); |
151 |
} |
152 |
} |
153 |
else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST)==0) |
154 |
{ |
155 |
parseKeywordList(parser); |
156 |
} |
157 |
break;
|
158 |
case KXmlParser.END_TAG:
|
159 |
if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0) |
160 |
end = true;
|
161 |
break;
|
162 |
case KXmlParser.TEXT:
|
163 |
break;
|
164 |
} |
165 |
currentTag = parser.next(); |
166 |
} |
167 |
} |
168 |
|
169 |
|
170 |
/**
|
171 |
* <p>Parses the EX_GeographicBoundingBox </p>
|
172 |
*/
|
173 |
private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException |
174 |
{ |
175 |
int currentTag;
|
176 |
boolean end = false; |
177 |
BoundaryBox bbox = new BoundaryBox ();
|
178 |
String value;
|
179 |
|
180 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
|
181 |
currentTag = parser.next(); |
182 |
|
183 |
while (!end)
|
184 |
{ |
185 |
switch(currentTag)
|
186 |
{ |
187 |
case KXmlParser.START_TAG:
|
188 |
if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE)==0) |
189 |
{ |
190 |
value = parser.nextText(); |
191 |
if ((value != null) && (Utilities.isNumber(value))) |
192 |
bbox.setXmin(Double.parseDouble(value));
|
193 |
} |
194 |
else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE)==0) |
195 |
{ |
196 |
value = parser.nextText(); |
197 |
if ((value != null) && (Utilities.isNumber(value))) |
198 |
bbox.setXmax(Double.parseDouble(value));
|
199 |
} |
200 |
else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE)==0) |
201 |
{ |
202 |
value = parser.nextText(); |
203 |
if ((value != null) && (Utilities.isNumber(value))) |
204 |
bbox.setYmax(Double.parseDouble(value));
|
205 |
} |
206 |
else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE)==0) |
207 |
{ |
208 |
value = parser.nextText(); |
209 |
if ((value != null) && (Utilities.isNumber(value))) |
210 |
bbox.setYmin(Double.parseDouble(value));
|
211 |
} |
212 |
break;
|
213 |
case KXmlParser.END_TAG:
|
214 |
if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX) == 0) |
215 |
end = true;
|
216 |
break;
|
217 |
case KXmlParser.TEXT:
|
218 |
break;
|
219 |
} |
220 |
if (!end)
|
221 |
currentTag = parser.next(); |
222 |
} |
223 |
parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
|
224 |
|
225 |
//TODO:
|
226 |
bbox.setSrs("EPSG:4326");
|
227 |
return bbox;
|
228 |
} |
229 |
|
230 |
public String toString(){ |
231 |
return super.toString(); |
232 |
} |
233 |
} |