svn-gvsig-desktop / tags / v1_0_2_Build_897 / libraries / libRemoteServices / src / org / gvsig / remoteClient / wms / wms_1_3_0 / WMSLayer1_3_0.java @ 10444
History | View | Annotate | Download (10.6 KB)
1 | 3660 | ldiaz | |
---|---|---|---|
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 | 4314 | ldiaz | public ArrayList getDimensions() |
24 | { |
||
25 | WMSDimension pDimension; |
||
26 | WMSDimension myDimension; |
||
27 | 4318 | jaume | ArrayList myDimensions = (ArrayList) this.dimensions.clone(); |
28 | 4314 | ldiaz | ArrayList pDimensions;
|
29 | |||
30 | if (parent!=null) |
||
31 | { |
||
32 | pDimensions = parent.getDimensions(); |
||
33 | for (int i= 0; i < pDimensions.size(); i++){ |
||
34 | pDimension = (WMSDimension)pDimensions.get(i); |
||
35 | myDimension = getDimension(pDimension.getName()); |
||
36 | if (myDimension != null){ |
||
37 | pDimensions.remove(pDimension); |
||
38 | } |
||
39 | } |
||
40 | myDimensions.addAll(pDimensions); |
||
41 | } |
||
42 | 4318 | jaume | return myDimensions;
|
43 | 4314 | ldiaz | } |
44 | |||
45 | 3660 | ldiaz | public WMSLayer1_3_0()
|
46 | { |
||
47 | children = new ArrayList(); |
||
48 | } |
||
49 | /**
|
||
50 | * <p>Parses the contents of the parser(WMSCapabilities)
|
||
51 | * to extract the information about an WMSLayer</p>
|
||
52 | *
|
||
53 | */
|
||
54 | public void parse(KXmlParser parser, TreeMap layerTreeMap) |
||
55 | throws IOException, XmlPullParserException |
||
56 | { |
||
57 | int currentTag;
|
||
58 | boolean end = false; |
||
59 | String value;
|
||
60 | BoundaryBox bbox; |
||
61 | parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.LAYER);
|
||
62 | |||
63 | 3750 | ldiaz | readLayerAttributes( parser ); |
64 | 3660 | ldiaz | |
65 | currentTag = parser.nextTag(); |
||
66 | |||
67 | while (!end)
|
||
68 | { |
||
69 | switch(currentTag)
|
||
70 | { |
||
71 | case KXmlParser.START_TAG:
|
||
72 | if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0) |
||
73 | { |
||
74 | WMSLayer1_3_0 lyr = new WMSLayer1_3_0();
|
||
75 | //parser.next();
|
||
76 | lyr.parse(parser, layerTreeMap); |
||
77 | lyr.setParent(this);
|
||
78 | 4222 | jaume | this.children.add(lyr);
|
79 | 3660 | ldiaz | // Jaume
|
80 | if (lyr.getName()!=null) |
||
81 | layerTreeMap.put(lyr.getName(), lyr); |
||
82 | } |
||
83 | else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION)==0){ |
||
84 | // TODO comprobar que esto se necesite o se deseche
|
||
85 | parser.skipSubTree(); |
||
86 | } |
||
87 | else if (parser.getName().compareTo(CapabilitiesTags.NAME)==0) |
||
88 | { |
||
89 | value = parser.nextText(); |
||
90 | if (value != null) setName(value); |
||
91 | } |
||
92 | else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0) |
||
93 | { |
||
94 | value = parser.nextText(); |
||
95 | if (value != null) setTitle(value); |
||
96 | } |
||
97 | else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0) |
||
98 | { |
||
99 | value = parser.nextText(); |
||
100 | if (value != null) setAbstract(value); |
||
101 | } |
||
102 | 3665 | ldiaz | else if (parser.getName().compareTo(CapabilitiesTags.CRS)==0) |
103 | 3660 | ldiaz | { |
104 | 4222 | jaume | //TODO:
|
105 | //comentar esto y a?adir solo los SRS o CRS que incluyan un extent...
|
||
106 | 3660 | ldiaz | value = parser.nextText(); |
107 | if (value != null){ |
||
108 | 5157 | jaume | String[] mySRSs = value.split(" "); |
109 | for (int i = 0; i < mySRSs.length; i++) { |
||
110 | addSrs(mySRSs[i]); |
||
111 | 3775 | ldiaz | } |
112 | 3660 | ldiaz | } |
113 | } |
||
114 | else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0) |
||
115 | { |
||
116 | bbox = new BoundaryBox();
|
||
117 | 3687 | ldiaz | value = parser.getAttributeValue("",CapabilitiesTags.CRS);
|
118 | 3660 | ldiaz | if (value != null) |
119 | bbox.setSrs(value); |
||
120 | value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
||
121 | if ((value != null) && (Utilities.isNumber(value))) |
||
122 | bbox.setXmin(Double.parseDouble(value));
|
||
123 | value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
||
124 | if ((value != null) && (Utilities.isNumber(value))) |
||
125 | bbox.setYmin(Double.parseDouble(value));
|
||
126 | value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
||
127 | if ((value != null) && (Utilities.isNumber(value))) |
||
128 | bbox.setXmax(Double.parseDouble(value));
|
||
129 | value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
||
130 | if ((value != null) && (Utilities.isNumber(value))) |
||
131 | bbox.setYmax(Double.parseDouble(value));
|
||
132 | 3750 | ldiaz | |
133 | //X and Y spatial resolution in the units if that CRS.
|
||
134 | 3824 | ldiaz | //value = parser.getAttributeValue("",CapabilitiesTags.RESX);
|
135 | //if ((value != null) && (Utilities.isNumber(value)))
|
||
136 | 3750 | ldiaz | //bbox.setYmax(Double.parseDouble(value));
|
137 | 3824 | ldiaz | //value = parser.getAttributeValue("",CapabilitiesTags.RESY);
|
138 | //if ((value != null) && (Utilities.isNumber(value)))
|
||
139 | 3750 | ldiaz | //bbox.setYmax(Double.parseDouble(value));
|
140 | |||
141 | 3660 | ldiaz | addBBox(bbox); |
142 | 4222 | jaume | addSrs(bbox.getSrs()); |
143 | 3660 | ldiaz | } |
144 | 3750 | ldiaz | else if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX)==0) |
145 | 3660 | ldiaz | { |
146 | 3750 | ldiaz | //minimum bounding rectangle in decimal degrees of the area covered by the layer.
|
147 | bbox = parseEXGeographicBBTag(parser); |
||
148 | 3660 | ldiaz | addBBox(bbox); |
149 | setLatLonBox(bbox); |
||
150 | 4222 | jaume | addSrs(bbox.getSrs()); |
151 | 3660 | ldiaz | } |
152 | else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0) |
||
153 | { |
||
154 | value = parser.getAttributeValue("",CapabilitiesTags.MIN);
|
||
155 | if ((value != null) && (Utilities.isNumber(value))) |
||
156 | setScaleMin(Double.parseDouble(value));
|
||
157 | value = parser.getAttributeValue("",CapabilitiesTags.MAX);
|
||
158 | if ((value != null) && (Utilities.isNumber(value))) |
||
159 | setScaleMax(Double.parseDouble(value));
|
||
160 | } |
||
161 | else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0) |
||
162 | { |
||
163 | WMSStyle1_3_0 style = new WMSStyle1_3_0();
|
||
164 | style.parse(parser); |
||
165 | if ((style != null) && (style.getName() != null)) |
||
166 | { |
||
167 | styles.add(style); |
||
168 | } |
||
169 | } |
||
170 | else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0) |
||
171 | { |
||
172 | WMSDimension dim = new WMSDimension();
|
||
173 | dim.parse(parser); |
||
174 | if ((dim != null) && (dim.getName() != null)) |
||
175 | { |
||
176 | addDimension(dim); |
||
177 | 4314 | ldiaz | |
178 | 3660 | ldiaz | } |
179 | 4314 | ldiaz | } |
180 | 3750 | ldiaz | else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST)==0) |
181 | { |
||
182 | 3755 | ldiaz | parseKeywordList(parser); |
183 | 3750 | ldiaz | } |
184 | 3660 | ldiaz | break;
|
185 | case KXmlParser.END_TAG:
|
||
186 | if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0) |
||
187 | end = true;
|
||
188 | break;
|
||
189 | case KXmlParser.TEXT:
|
||
190 | break;
|
||
191 | } |
||
192 | 4222 | jaume | if (!end)
|
193 | currentTag = parser.next(); |
||
194 | 3660 | ldiaz | } |
195 | 4222 | jaume | parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LAYER);
|
196 | 3660 | ldiaz | } |
197 | 3755 | ldiaz | |
198 | 3660 | ldiaz | |
199 | 3750 | ldiaz | /**
|
200 | * <p>Parses the EX_GeographicBoundingBox </p>
|
||
201 | */
|
||
202 | private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException |
||
203 | { |
||
204 | int currentTag;
|
||
205 | boolean end = false; |
||
206 | BoundaryBox bbox = new BoundaryBox ();
|
||
207 | String value;
|
||
208 | |||
209 | parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
|
||
210 | currentTag = parser.next(); |
||
211 | |||
212 | while (!end)
|
||
213 | { |
||
214 | switch(currentTag)
|
||
215 | { |
||
216 | case KXmlParser.START_TAG:
|
||
217 | if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE)==0) |
||
218 | { |
||
219 | value = parser.nextText(); |
||
220 | if ((value != null) && (Utilities.isNumber(value))) |
||
221 | bbox.setXmin(Double.parseDouble(value));
|
||
222 | } |
||
223 | else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE)==0) |
||
224 | { |
||
225 | value = parser.nextText(); |
||
226 | if ((value != null) && (Utilities.isNumber(value))) |
||
227 | bbox.setXmax(Double.parseDouble(value));
|
||
228 | } |
||
229 | else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE)==0) |
||
230 | { |
||
231 | value = parser.nextText(); |
||
232 | if ((value != null) && (Utilities.isNumber(value))) |
||
233 | bbox.setYmax(Double.parseDouble(value));
|
||
234 | } |
||
235 | else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE)==0) |
||
236 | { |
||
237 | value = parser.nextText(); |
||
238 | if ((value != null) && (Utilities.isNumber(value))) |
||
239 | bbox.setYmin(Double.parseDouble(value));
|
||
240 | } |
||
241 | break;
|
||
242 | case KXmlParser.END_TAG:
|
||
243 | if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX) == 0) |
||
244 | end = true;
|
||
245 | break;
|
||
246 | case KXmlParser.TEXT:
|
||
247 | break;
|
||
248 | } |
||
249 | if (!end)
|
||
250 | currentTag = parser.next(); |
||
251 | } |
||
252 | parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
|
||
253 | 3775 | ldiaz | |
254 | //TODO:
|
||
255 | 4222 | jaume | bbox.setSrs("CRS:84");
|
256 | 3750 | ldiaz | return bbox;
|
257 | } |
||
258 | |||
259 | 3660 | ldiaz | public String toString(){ |
260 | return super.toString(); |
||
261 | } |
||
262 | } |