/**
* @param resource
* @param map
*/
static private void processLayer( Element resource, Map map ) {
Layer layer = ProjectFactory.eINSTANCE.createLayer();
String hidden = resource.getAttributeValue("hidden"); //$NON-NLS-1$
if (hidden != null) {
layer.setVisible(!"0".equals(hidden)); //$NON-NLS-1$
}
String queryable = resource.getAttributeValue("queryable"); //$NON-NLS-1$
if (queryable != null) {
layer.setInteraction(Interaction.SELECT, !"0".equals(queryable)); //$NON-NLS-1$ //$NON-NLS-2$
}
Namespace oc = Namespace.getNamespace("http://www.opengis.net/oc"); //$NON-NLS-1$
Namespace sld = Namespace.getNamespace("http://www.opengis.net/sld"); //$NON-NLS-1$
Namespace xlink = Namespace.getNamespace("http://www.w3.org/1999/xlink"); //$NON-NLS-1$
String name = resource.getChildTextTrim("Name", oc); //$NON-NLS-1$
{
String title = resource.getChildTextTrim("Title", oc); //$NON-NLS-1$
layer.setName(title != null ? title : name);
}
{
Element server = resource.getChild("Server", oc); //$NON-NLS-1$
String service = server.getAttributeValue("service"); // should be OGC:WMS //$NON-NLS-1$
// //$NON-NLS-1$
String title = server.getAttributeValue("title"); //$NON-NLS-1$
String version = server.getAttributeValue("version"); // eg 1.1.1 //$NON-NLS-1$
Element onlineResouce = server.getChild("OnlineResource", oc); //$NON-NLS-1$
String type = onlineResouce.getAttributeValue("type", xlink); // eg simple //$NON-NLS-1$
// //$NON-NLS-1$
String href = onlineResouce.getAttributeValue("href", xlink); // url //$NON-NLS-1$
try {
href = URLDecoder.decode(href, "US-ASCII"); //$NON-NLS-1$
} catch (UnsupportedEncodingException ex) {
System.out.println(ex.toString());
ex.printStackTrace();
}
try {
URL url = new URL(href
+ "?SERVICE=WMS&VERSION=" + version + "&REQUEST=GetCapabilities"); //$NON-NLS-1$ //$NON-NLS-2$
url = service(url, WebMapServer.class);
layer.setID(new URL(url + "#" + name)); //$NON-NLS-1$
} catch (MalformedURLException e) {
System.out.println("Skip " + name + " due to " + e); //$NON-NLS-1$ //$NON-NLS-2$
return;
}
}
String min = resource.getChildTextTrim("MinScaleDenominator", sld); //$NON-NLS-1$
String max = resource.getChildTextTrim("MaxScaleDenominator", sld); //$NON-NLS-1$
if (min != null)
layer.setMinScaleDenominator(Double.parseDouble(min));
if (max != null)
layer.setMaxScaleDenominator(Double.parseDouble(max));
String srs = resource.getChildTextTrim("SRS", oc); //$NON-NLS-1$
try {
layer.setCRS(CRS.decode(srs));
} catch (Throwable ignore) {
System.out.println(name + " srs unavailable:" + srs); //$NON-NLS-1$
}
map.getLayersInternal().add(layer);