28 |
28 |
import java.util.ArrayList;
|
29 |
29 |
import java.util.TreeMap;
|
30 |
30 |
|
31 |
|
import org.kxml2.io.KXmlParser;
|
32 |
|
import org.xmlpull.v1.XmlPullParserException;
|
33 |
|
|
|
31 |
import org.cresques.cts.IProjection;
|
34 |
32 |
import org.gvsig.compat.CompatLocator;
|
35 |
33 |
import org.gvsig.compat.lang.StringUtils;
|
|
34 |
import org.gvsig.fmap.crs.CRSFactory;
|
36 |
35 |
import org.gvsig.remoteclient.utils.BoundaryBox;
|
37 |
36 |
import org.gvsig.remoteclient.utils.CapabilitiesTags;
|
38 |
37 |
import org.gvsig.remoteclient.utils.Utilities;
|
39 |
38 |
import org.gvsig.remoteclient.wms.WMSDimension;
|
|
39 |
import org.kxml2.io.KXmlParser;
|
|
40 |
import org.xmlpull.v1.XmlPullParserException;
|
40 |
41 |
|
41 |
42 |
|
42 |
43 |
/**
|
... | ... | |
47 |
48 |
|
48 |
49 |
private static final StringUtils stringUtils = CompatLocator.getStringUtils();
|
49 |
50 |
|
50 |
|
public ArrayList getDimensions()
|
51 |
|
{
|
|
51 |
|
|
52 |
public ArrayList getDimensions() {
|
52 |
53 |
WMSDimension pDimension;
|
53 |
54 |
WMSDimension myDimension;
|
54 |
55 |
ArrayList myDimensions = (ArrayList) this.dimensions.clone();
|
55 |
56 |
ArrayList pDimensions;
|
56 |
57 |
|
57 |
|
if (parent!=null)
|
58 |
|
{
|
|
58 |
if (parent != null) {
|
59 |
59 |
pDimensions = parent.getDimensions();
|
60 |
|
for (int i= 0; i < pDimensions.size(); i++){
|
|
60 |
for (int i= 0; i < pDimensions.size(); i++) {
|
61 |
61 |
pDimension = (WMSDimension)pDimensions.get(i);
|
62 |
62 |
myDimension = getDimension(pDimension.getName());
|
63 |
63 |
if (myDimension != null){
|
... | ... | |
69 |
69 |
return myDimensions;
|
70 |
70 |
}
|
71 |
71 |
|
72 |
|
public WMSLayer1_3_0()
|
73 |
|
{
|
|
72 |
public WMSLayer1_3_0() {
|
74 |
73 |
children = new ArrayList();
|
75 |
74 |
}
|
76 |
75 |
/**
|
... | ... | |
78 |
77 |
* to extract the information about an WMSLayer</p>
|
79 |
78 |
*
|
80 |
79 |
*/
|
81 |
|
public void parse(KXmlParser parser, TreeMap layerTreeMap)
|
82 |
|
throws IOException, XmlPullParserException
|
83 |
|
{
|
|
80 |
public void parse(KXmlParser parser, TreeMap layerTreeMap) throws IOException, XmlPullParserException {
|
84 |
81 |
int currentTag;
|
85 |
82 |
boolean end = false;
|
86 |
83 |
String value;
|
... | ... | |
91 |
88 |
|
92 |
89 |
currentTag = parser.nextTag();
|
93 |
90 |
|
94 |
|
while (!end)
|
95 |
|
{
|
96 |
|
switch(currentTag)
|
97 |
|
{
|
98 |
|
case KXmlParser.START_TAG:
|
99 |
|
if (parser.getName().compareTo(CapabilitiesTags.LAYER)==0)
|
100 |
|
{
|
101 |
|
WMSLayer1_3_0 lyr = new WMSLayer1_3_0();
|
102 |
|
//parser.next();
|
103 |
|
lyr.parse(parser, layerTreeMap);
|
104 |
|
lyr.setParent(this);
|
105 |
|
this.children.add(lyr);
|
106 |
|
// Jaume
|
107 |
|
if (lyr.getName()!=null)
|
108 |
|
layerTreeMap.put(lyr.getName(), lyr);
|
109 |
|
}
|
110 |
|
else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION)==0){
|
111 |
|
// TODO comprobar que esto se necesite o se deseche
|
112 |
|
parser.skipSubTree();
|
113 |
|
}
|
114 |
|
else if (parser.getName().compareTo(CapabilitiesTags.NAME)==0)
|
115 |
|
{
|
116 |
|
value = parser.nextText();
|
117 |
|
if (value != null) setName(value);
|
118 |
|
}
|
119 |
|
else if (parser.getName().compareTo(CapabilitiesTags.TITLE)==0)
|
120 |
|
{
|
121 |
|
value = parser.nextText();
|
122 |
|
if (value != null) setTitle(value);
|
123 |
|
}
|
124 |
|
else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT)==0)
|
125 |
|
{
|
126 |
|
value = parser.nextText();
|
127 |
|
if (value != null) setAbstract(value);
|
128 |
|
}
|
129 |
|
else if (parser.getName().compareTo(CapabilitiesTags.CRS)==0)
|
130 |
|
{
|
131 |
|
value = parser.nextText();
|
132 |
|
if (value != null){
|
133 |
|
String[] mySRSs = stringUtils.split(value, " ");
|
134 |
|
for (int i = 0; i < mySRSs.length; i++) {
|
135 |
|
addSrs(mySRSs[i]);
|
136 |
|
}
|
137 |
|
}
|
138 |
|
}
|
139 |
|
else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX)==0)
|
140 |
|
{
|
141 |
|
bbox = new BoundaryBox();
|
142 |
|
value = parser.getAttributeValue("",CapabilitiesTags.CRS);
|
143 |
|
if (value != null)
|
144 |
|
bbox.setSrs(value);
|
145 |
|
value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
146 |
|
if ((value != null) && (Utilities.isNumber(value)))
|
147 |
|
bbox.setXmin(Double.parseDouble(value));
|
148 |
|
value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
149 |
|
if ((value != null) && (Utilities.isNumber(value)))
|
150 |
|
bbox.setYmin(Double.parseDouble(value));
|
151 |
|
value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
152 |
|
if ((value != null) && (Utilities.isNumber(value)))
|
153 |
|
bbox.setXmax(Double.parseDouble(value));
|
154 |
|
value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
155 |
|
if ((value != null) && (Utilities.isNumber(value)))
|
156 |
|
bbox.setYmax(Double.parseDouble(value));
|
157 |
|
|
158 |
|
//X and Y spatial resolution in the units if that CRS.
|
159 |
|
//value = parser.getAttributeValue("",CapabilitiesTags.RESX);
|
160 |
|
//if ((value != null) && (Utilities.isNumber(value)))
|
161 |
|
//bbox.setYmax(Double.parseDouble(value));
|
162 |
|
//value = parser.getAttributeValue("",CapabilitiesTags.RESY);
|
163 |
|
//if ((value != null) && (Utilities.isNumber(value)))
|
164 |
|
//bbox.setYmax(Double.parseDouble(value));
|
165 |
|
|
166 |
|
addBBox(bbox);
|
167 |
|
addSrs(bbox.getSrs());
|
168 |
|
}
|
169 |
|
else if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX)==0)
|
170 |
|
{
|
171 |
|
//minimum bounding rectangle in decimal degrees of the area covered by the layer.
|
172 |
|
bbox = parseEXGeographicBBTag(parser);
|
173 |
|
addBBox(bbox);
|
174 |
|
setLatLonBox(bbox);
|
175 |
|
addSrs(bbox.getSrs());
|
176 |
|
}
|
177 |
|
else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT)==0)
|
178 |
|
{
|
179 |
|
value = parser.getAttributeValue("",CapabilitiesTags.MIN);
|
180 |
|
if ((value != null) && (Utilities.isNumber(value)))
|
181 |
|
setScaleMin(Double.parseDouble(value));
|
182 |
|
value = parser.getAttributeValue("",CapabilitiesTags.MAX);
|
183 |
|
if ((value != null) && (Utilities.isNumber(value)))
|
184 |
|
setScaleMax(Double.parseDouble(value));
|
185 |
|
}
|
186 |
|
else if (parser.getName().compareTo(CapabilitiesTags.STYLE)==0)
|
187 |
|
{
|
188 |
|
WMSStyle1_3_0 style = new WMSStyle1_3_0();
|
189 |
|
style.parse(parser);
|
190 |
|
if ((style != null) && (style.getName() != null))
|
191 |
|
{
|
192 |
|
styles.add(style);
|
193 |
|
}
|
194 |
|
}
|
195 |
|
else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION)==0)
|
196 |
|
{
|
197 |
|
WMSDimension dim = new WMSDimension();
|
198 |
|
dim.parse(parser);
|
199 |
|
if ((dim != null) && (dim.getName() != null))
|
200 |
|
{
|
201 |
|
addDimension(dim);
|
202 |
|
|
203 |
|
}
|
204 |
|
}
|
205 |
|
else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST)==0)
|
206 |
|
{
|
207 |
|
parseKeywordList(parser);
|
208 |
|
}
|
209 |
|
break;
|
210 |
|
case KXmlParser.END_TAG:
|
211 |
|
if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0)
|
212 |
|
end = true;
|
213 |
|
break;
|
214 |
|
case KXmlParser.TEXT:
|
215 |
|
break;
|
216 |
|
}
|
217 |
|
if (!end)
|
218 |
|
currentTag = parser.next();
|
|
91 |
while (!end) {
|
|
92 |
switch(currentTag) {
|
|
93 |
case KXmlParser.START_TAG:
|
|
94 |
if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0) {
|
|
95 |
WMSLayer1_3_0 lyr = new WMSLayer1_3_0();
|
|
96 |
//parser.next();
|
|
97 |
lyr.parse(parser, layerTreeMap);
|
|
98 |
lyr.setParent(this);
|
|
99 |
this.children.add(lyr);
|
|
100 |
// Jaume
|
|
101 |
if (lyr.getName()!=null)
|
|
102 |
layerTreeMap.put(lyr.getName(), lyr);
|
|
103 |
} else if (parser.getName().compareTo(CapabilitiesTags.ATTRIBUTION) == 0) {
|
|
104 |
// TODO comprobar que esto se necesite o se deseche
|
|
105 |
parser.skipSubTree();
|
|
106 |
} else if (parser.getName().compareTo(CapabilitiesTags.NAME) == 0) {
|
|
107 |
value = parser.nextText();
|
|
108 |
if (value != null) setName(value);
|
|
109 |
} else if (parser.getName().compareTo(CapabilitiesTags.TITLE) == 0) {
|
|
110 |
value = parser.nextText();
|
|
111 |
if (value != null) setTitle(value);
|
|
112 |
} else if (parser.getName().compareTo(CapabilitiesTags.ABSTRACT) == 0) {
|
|
113 |
value = parser.nextText();
|
|
114 |
if (value != null) setAbstract(value);
|
|
115 |
} else if (parser.getName().compareTo(CapabilitiesTags.CRS) == 0) {
|
|
116 |
value = parser.nextText();
|
|
117 |
if (value != null) {
|
|
118 |
String[] mySRSs = stringUtils.split(value, " ");
|
|
119 |
for (int i = 0; i < mySRSs.length; i++) {
|
|
120 |
addSrs(mySRSs[i]);
|
|
121 |
}
|
|
122 |
}
|
|
123 |
} else if (parser.getName().compareTo(CapabilitiesTags.BOUNDINGBOX) == 0) {
|
|
124 |
bbox = new BoundaryBox();
|
|
125 |
value = parser.getAttributeValue("",CapabilitiesTags.CRS);
|
|
126 |
if (value != null)
|
|
127 |
bbox.setSrs(value);
|
|
128 |
value = parser.getAttributeValue("",CapabilitiesTags.MINX);
|
|
129 |
if ((value != null) && (Utilities.isNumber(value)))
|
|
130 |
bbox.setXmin(Double.parseDouble(value));
|
|
131 |
value = parser.getAttributeValue("",CapabilitiesTags.MINY);
|
|
132 |
if ((value != null) && (Utilities.isNumber(value)))
|
|
133 |
bbox.setYmin(Double.parseDouble(value));
|
|
134 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXX);
|
|
135 |
if ((value != null) && (Utilities.isNumber(value)))
|
|
136 |
bbox.setXmax(Double.parseDouble(value));
|
|
137 |
value = parser.getAttributeValue("",CapabilitiesTags.MAXY);
|
|
138 |
if ((value != null) && (Utilities.isNumber(value)))
|
|
139 |
bbox.setYmax(Double.parseDouble(value));
|
|
140 |
|
|
141 |
bbox = changeAxis(bbox.getSrs(), bbox);
|
|
142 |
addBBox(bbox);
|
|
143 |
addSrs(bbox.getSrs());
|
|
144 |
} else if (parser.getName().compareTo(CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX) == 0) {
|
|
145 |
//minimum bounding rectangle in decimal degrees of the area covered by the layer.
|
|
146 |
bbox = parseEXGeographicBBTag(parser);
|
|
147 |
addBBox(bbox);
|
|
148 |
setLatLonBox(bbox);
|
|
149 |
addSrs(bbox.getSrs());
|
|
150 |
} else if (parser.getName().compareTo(CapabilitiesTags.SCALEHINT) == 0) {
|
|
151 |
value = parser.getAttributeValue("",CapabilitiesTags.MIN);
|
|
152 |
if ((value != null) && (Utilities.isNumber(value)))
|
|
153 |
setScaleMin(Double.parseDouble(value));
|
|
154 |
value = parser.getAttributeValue("",CapabilitiesTags.MAX);
|
|
155 |
if ((value != null) && (Utilities.isNumber(value)))
|
|
156 |
setScaleMax(Double.parseDouble(value));
|
|
157 |
} else if (parser.getName().compareTo(CapabilitiesTags.STYLE) == 0) {
|
|
158 |
WMSStyle1_3_0 style = new WMSStyle1_3_0();
|
|
159 |
style.parse(parser);
|
|
160 |
if ((style != null) && (style.getName() != null)) {
|
|
161 |
styles.add(style);
|
|
162 |
}
|
|
163 |
} else if (parser.getName().compareTo(CapabilitiesTags.DIMENSION) == 0) {
|
|
164 |
WMSDimension dim = new WMSDimension();
|
|
165 |
dim.parse(parser);
|
|
166 |
if ((dim != null) && (dim.getName() != null)) {
|
|
167 |
addDimension(dim);
|
|
168 |
|
|
169 |
}
|
|
170 |
} else if (parser.getName().compareTo(CapabilitiesTags.KEYWORDLIST) == 0) {
|
|
171 |
parseKeywordList(parser);
|
|
172 |
}
|
|
173 |
break;
|
|
174 |
case KXmlParser.END_TAG:
|
|
175 |
if (parser.getName().compareTo(CapabilitiesTags.LAYER) == 0)
|
|
176 |
end = true;
|
|
177 |
break;
|
|
178 |
case KXmlParser.TEXT:
|
|
179 |
break;
|
|
180 |
}
|
|
181 |
if (!end)
|
|
182 |
currentTag = parser.next();
|
219 |
183 |
}
|
220 |
184 |
parser.require(KXmlParser.END_TAG, null, CapabilitiesTags.LAYER);
|
221 |
|
}
|
|
185 |
}
|
|
186 |
|
|
187 |
/**
|
|
188 |
* Protocol 1.3 needs change axis in some cases.
|
|
189 |
* If coordinates are read from the tag BoundingBox (where the bounding box is
|
|
190 |
* defined for each specific CRS) then the axis needs to change its axis order in
|
|
191 |
* geographic projections. If coordinates are read from EX_GeographicBoundingBox
|
|
192 |
* then the axis are in right position.
|
|
193 |
*
|
|
194 |
* There is to take into account that the request will have to change the axis order again
|
|
195 |
* in cases which those had been changed.
|
|
196 |
*/
|
|
197 |
private BoundaryBox changeAxis(String epsg, BoundaryBox oldbbox) {
|
|
198 |
if(epsg.contains("CRS:84") || epsg.contains("CRS84"))
|
|
199 |
return oldbbox;
|
|
200 |
IProjection projSrc = CRSFactory.getCRS(epsg);
|
|
201 |
if(projSrc != null && !projSrc.isProjected()) {
|
|
202 |
BoundaryBox bbox = new BoundaryBox();
|
|
203 |
bbox.setXmin(oldbbox.getYmin());
|
|
204 |
bbox.setYmin(oldbbox.getXmin());
|
|
205 |
bbox.setXmax(oldbbox.getYmax());
|
|
206 |
bbox.setYmax(oldbbox.getXmax());
|
|
207 |
bbox.setSrs(oldbbox.getSrs());
|
|
208 |
return bbox;
|
|
209 |
}
|
|
210 |
return oldbbox;
|
|
211 |
}
|
222 |
212 |
|
223 |
213 |
|
224 |
214 |
/**
|
225 |
215 |
* <p>Parses the EX_GeographicBoundingBox </p>
|
226 |
216 |
*/
|
227 |
|
private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException
|
228 |
|
{
|
|
217 |
private BoundaryBox parseEXGeographicBBTag(KXmlParser parser) throws IOException, XmlPullParserException {
|
229 |
218 |
int currentTag;
|
230 |
219 |
boolean end = false;
|
231 |
220 |
BoundaryBox bbox = new BoundaryBox ();
|
... | ... | |
234 |
223 |
parser.require(KXmlParser.START_TAG, null, CapabilitiesTags.EX_GEOGRAPHICBOUNDINGBOX);
|
235 |
224 |
currentTag = parser.next();
|
236 |
225 |
|
237 |
|
while (!end)
|
238 |
|
{
|
239 |
|
switch(currentTag)
|
240 |
|
{
|
|
226 |
while (!end) {
|
|
227 |
switch(currentTag) {
|
241 |
228 |
case KXmlParser.START_TAG:
|
242 |
|
if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE)==0)
|
243 |
|
{
|
|
229 |
if (parser.getName().compareTo(CapabilitiesTags.WESTBOUNDLONGITUDE) == 0) {
|
244 |
230 |
value = parser.nextText();
|
245 |
231 |
if ((value != null) && (Utilities.isNumber(value)))
|
246 |
232 |
bbox.setXmin(Double.parseDouble(value));
|
247 |
|
}
|
248 |
|
else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE)==0)
|
249 |
|
{
|
|
233 |
} else if (parser.getName().compareTo(CapabilitiesTags.EASTBOUNDLONGITUDE) == 0) {
|
250 |
234 |
value = parser.nextText();
|
251 |
235 |
if ((value != null) && (Utilities.isNumber(value)))
|
252 |
236 |
bbox.setXmax(Double.parseDouble(value));
|
253 |
|
}
|
254 |
|
else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE)==0)
|
255 |
|
{
|
|
237 |
} else if (parser.getName().compareTo(CapabilitiesTags.NORTHBOUNDLATITUDE) == 0) {
|
256 |
238 |
value = parser.nextText();
|
257 |
239 |
if ((value != null) && (Utilities.isNumber(value)))
|
258 |
240 |
bbox.setYmax(Double.parseDouble(value));
|
259 |
|
}
|
260 |
|
else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE)==0)
|
261 |
|
{
|
|
241 |
} else if (parser.getName().compareTo(CapabilitiesTags.SOUTHBOUNDLATITUDE) == 0) {
|
262 |
242 |
value = parser.nextText();
|
263 |
243 |
if ((value != null) && (Utilities.isNumber(value)))
|
264 |
244 |
bbox.setYmin(Double.parseDouble(value));
|
... | ... | |
281 |
261 |
return bbox;
|
282 |
262 |
}
|
283 |
263 |
|
284 |
|
public String toString(){
|
|
264 |
public String toString() {
|
285 |
265 |
return super.toString();
|
286 |
266 |
}
|
287 |
267 |
}
|