it.geosolutions.geoserver.rest.decoder.RESTLayer21 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geoserver-manager Show documentation
Show all versions of geoserver-manager Show documentation
GeoServer Manager is a library to interact with GeoServer
The scope of this library is to have a simple API, and use as few external
libs as possible.
package it.geosolutions.geoserver.rest.decoder;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.encoder.authorityurl.GSAuthorityURLInfoEncoder;
import it.geosolutions.geoserver.rest.encoder.identifier.GSIdentifierInfoEncoder;
import java.util.ArrayList;
import java.util.List;
import org.jdom.Element;
/**
* Parse Layers returned as XML REST objects. Applicable to GS 2.1 for
* decoding: - AuthorityURLs - Identifiers - advertised property value
*
*
* This is the XML REST representation:
*
*
* {@code
*
* tasmania_cities
* /
* VECTOR
*
* capitals
*
*
*
* tasmania_cities
*
*
* true
* true
* true
*
* 0
* 0
*
*
*
* [{"authority":"authority1","identifier":"identifier1"},]
*
*
* [{"name":"authority1","href":"http://www.authority1.org"},]
*
* true
*
*
* }
*
*
* @author eblondel
* @version $Id: $
*/
public class RESTLayer21 extends RESTLayer{
/**
* Constructor for RESTLayer21.
*
* @param layerElem a {@link org.jdom.Element} object.
*/
public RESTLayer21(Element layerElem) {
super(layerElem);
}
/** {@inheritDoc} */
public static RESTLayer21 build(String response) {
if(response == null)
return null;
Element pb = JDOMBuilder.buildElement(response);
if(pb != null)
return new RESTLayer21(pb);
else
return null;
}
/**
* Decodes the advertised property from the Geoserver Layer
*
* @return a boolean.
*/
public boolean getAdvertised(){
boolean advertised = true;
final Element metadataRoot = layerElem.getChild("metadata");
if(metadataRoot != null){
final List metaElements = metadataRoot.getChildren();
if(metaElements != null){
for(Element el : metaElements){
String key = el.getAttributeValue("key");
if(key.matches("advertised")){
advertised = Boolean.parseBoolean(el.getValue());
}
}
}
}
return advertised;
}
/**
* Decodes the list of AuthorityURLInfo from the GeoServer Layer
*
* @return the list of GSAuthorityURLInfoEncoder
*/
public List getEncodedAuthorityURLInfoList() {
List authorityURLList = null;
final Element metadataRoot = layerElem.getChild("metadata");
if (metadataRoot != null) {
final List metaElements = metadataRoot.getChildren();
if (metaElements != null) {
for (Element element : metaElements) {
String key = element.getAttributeValue("key");
if (key.matches("authorityURLs")) {
String jsonStr = element.getValue();
jsonStr = jsonStr.substring(2);
jsonStr = jsonStr.substring(0,
jsonStr.length() - 3);
String[] items = jsonStr.split("\\}(,)\\{");
authorityURLList = new ArrayList(items.length);
for (String item : items) {
String[] props = item.split(",");
String[] kvp1 = props[0].split("\":");
String name = kvp1[1].replace("\"", "");
String[] kvp2 = props[1].split("\":");
String href = kvp2[1].replace("\"", "");
authorityURLList
.add(new GSAuthorityURLInfoEncoder(
name, href));
}
}
}
}
}
return authorityURLList;
}
/**
* Decodes the list of IdentifierInfo from the GeoServer Layer
*
* @return the list of IdentifierInfoEncoder
*/
public List getEncodedIdentifierInfoList() {
List identifierList = null;
final Element metadataRoot = layerElem.getChild("metadata");
if (metadataRoot != null) {
final List metaElements = metadataRoot.getChildren();
if (metaElements != null) {
for (Element element : metaElements) {
String key = element.getAttributeValue("key");
if (key.matches("identifiers")) {
String jsonStr = element.getValue();
jsonStr = jsonStr.substring(2);
jsonStr = jsonStr.substring(0,
jsonStr.length() - 3);
String[] items = jsonStr.split("\\}(,)\\{");
identifierList = new ArrayList(items.length);
for (String item : items) {
String[] props = item.split(",");
String[] kvp1 = props[0].split("\":");
String authority = kvp1[1].replace("\"", "");
String[] kvp2 = props[1].split("\":");
String identifier = kvp2[1].replace("\"", "");
identifierList
.add(new GSIdentifierInfoEncoder(
authority, identifier));
}
}
}
}
}
return identifierList;
}
}