MetadataLink support - RESTResource metadatalink decoder
This commit is contained in:
parent
47282974b5
commit
8adef995c2
@ -1,196 +1,252 @@
|
|||||||
/*
|
/*
|
||||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
* http://www.geo-solutions.it
|
* http://www.geo-solutions.it
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
*
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
*
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.geosolutions.geoserver.rest.decoder;
|
package it.geosolutions.geoserver.rest.decoder;
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
|
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
|
||||||
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
|
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder;
|
||||||
import java.util.ArrayList;
|
import it.geosolutions.geoserver.rest.encoder.metadatalink.ResourceMetadataLinkInfo;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import org.jdom.Element;
|
import java.util.Map;
|
||||||
import org.jdom.Namespace;
|
|
||||||
|
import org.jdom.Element;
|
||||||
/**
|
import org.jdom.Namespace;
|
||||||
* Parse a resource (FeatureType or Coverage) returned as XML REST objects.
|
|
||||||
*
|
/**
|
||||||
* @author etj
|
* Parse a resource (FeatureType or Coverage) returned as XML REST objects.
|
||||||
*/
|
*
|
||||||
public class RESTResource {
|
* @author etj
|
||||||
protected final Element rootElem;
|
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org
|
||||||
|
*/
|
||||||
public static RESTResource build(String response) {
|
public class RESTResource {
|
||||||
Element elem = JDOMBuilder.buildElement(response);
|
protected final Element rootElem;
|
||||||
return elem == null ? null : new RESTCoverage(elem);
|
|
||||||
}
|
public static RESTResource build(String response) {
|
||||||
|
Element elem = JDOMBuilder.buildElement(response);
|
||||||
public RESTResource(Element resource) {
|
return elem == null ? null : new RESTCoverage(elem);
|
||||||
this.rootElem = resource;
|
}
|
||||||
}
|
|
||||||
|
public RESTResource(Element resource) {
|
||||||
public String getName() {
|
this.rootElem = resource;
|
||||||
return rootElem.getChildText("name");
|
}
|
||||||
}
|
|
||||||
|
public String getName() {
|
||||||
public String getTitle() {
|
return rootElem.getChildText("name");
|
||||||
return rootElem.getChildText("title");
|
}
|
||||||
}
|
|
||||||
|
public String getTitle() {
|
||||||
public String getNativeName() {
|
return rootElem.getChildText("title");
|
||||||
return rootElem.getChildText("nativeName");
|
}
|
||||||
}
|
|
||||||
|
public String getNativeName() {
|
||||||
public String getAbstract() {
|
return rootElem.getChildText("nativeName");
|
||||||
return rootElem.getChildText("abstract");
|
}
|
||||||
}
|
|
||||||
|
public String getAbstract() {
|
||||||
public String getNameSpace() {
|
return rootElem.getChildText("abstract");
|
||||||
return rootElem.getChild("namespace").getChildText("name");
|
}
|
||||||
}
|
|
||||||
|
public String getNameSpace() {
|
||||||
public String getStoreName() {
|
return rootElem.getChild("namespace").getChildText("name");
|
||||||
return rootElem.getChild("store").getChildText("name");
|
}
|
||||||
}
|
|
||||||
|
public String getStoreName() {
|
||||||
public String getStoreType() {
|
return rootElem.getChild("store").getChildText("name");
|
||||||
return rootElem.getChild("store").getAttributeValue("class");
|
}
|
||||||
}
|
|
||||||
|
public String getStoreType() {
|
||||||
public String getStoreUrl() {
|
return rootElem.getChild("store").getAttributeValue("class");
|
||||||
Element store = rootElem.getChild("store");
|
}
|
||||||
Element atom = store.getChild("link",
|
|
||||||
Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
public String getStoreUrl() {
|
||||||
return atom.getAttributeValue("href");
|
Element store = rootElem.getChild("store");
|
||||||
}
|
Element atom = store.getChild("link",
|
||||||
|
Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"));
|
||||||
public String getCRS() {
|
return atom.getAttributeValue("href");
|
||||||
Element elBBox = rootElem.getChild("latLonBoundingBox");
|
}
|
||||||
return elBBox.getChildText("crs");
|
|
||||||
}
|
public String getCRS() {
|
||||||
|
Element elBBox = rootElem.getChild("latLonBoundingBox");
|
||||||
protected double getLatLonEdge(String edge) {
|
return elBBox.getChildText("crs");
|
||||||
Element elBBox = rootElem.getChild("latLonBoundingBox");
|
}
|
||||||
return Double.parseDouble(elBBox.getChildText(edge));
|
|
||||||
}
|
protected double getLatLonEdge(String edge) {
|
||||||
|
Element elBBox = rootElem.getChild("latLonBoundingBox");
|
||||||
public double getMinX() {
|
return Double.parseDouble(elBBox.getChildText(edge));
|
||||||
return getLatLonEdge("minx");
|
}
|
||||||
}
|
|
||||||
|
public double getMinX() {
|
||||||
public double getMaxX() {
|
return getLatLonEdge("minx");
|
||||||
return getLatLonEdge("maxx");
|
}
|
||||||
}
|
|
||||||
|
public double getMaxX() {
|
||||||
public double getMinY() {
|
return getLatLonEdge("maxx");
|
||||||
return getLatLonEdge("miny");
|
}
|
||||||
}
|
|
||||||
|
public double getMinY() {
|
||||||
public double getMaxY() {
|
return getLatLonEdge("miny");
|
||||||
return getLatLonEdge("maxy");
|
}
|
||||||
}
|
|
||||||
|
public double getMaxY() {
|
||||||
public List<Map<FeatureTypeAttribute, String>> getAttributeList() {
|
return getLatLonEdge("maxy");
|
||||||
List<Map<FeatureTypeAttribute, String>> attrsList = null;
|
}
|
||||||
|
|
||||||
final Element attrsRoot = rootElem.getChild("attributes");
|
public List<Map<FeatureTypeAttribute, String>> getAttributeList() {
|
||||||
final List<Element> attrs = attrsRoot.getChildren();
|
List<Map<FeatureTypeAttribute, String>> attrsList = null;
|
||||||
if (attrs != null) {
|
|
||||||
attrsList = new ArrayList<Map<FeatureTypeAttribute, String>>(attrs.size());
|
final Element attrsRoot = rootElem.getChild("attributes");
|
||||||
for (Element attr : attrs) {
|
final List<Element> attrs = attrsRoot.getChildren();
|
||||||
Map<FeatureTypeAttribute, String> attrsMap = new HashMap<FeatureTypeAttribute, String>();
|
if (attrs != null) {
|
||||||
attrsList.add(attrsMap);
|
attrsList = new ArrayList<Map<FeatureTypeAttribute, String>>(attrs.size());
|
||||||
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
for (Element attr : attrs) {
|
||||||
String key = at.toString();
|
Map<FeatureTypeAttribute, String> attrsMap = new HashMap<FeatureTypeAttribute, String>();
|
||||||
attrsMap.put(at, attr.getChildText(key));
|
attrsList.add(attrsMap);
|
||||||
}
|
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
||||||
}
|
String key = at.toString();
|
||||||
}
|
attrsMap.put(at, attr.getChildText(key));
|
||||||
return attrsList;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public List<GSAttributeEncoder> getEncodedAttributeList() {
|
return attrsList;
|
||||||
List<GSAttributeEncoder> attrsList = null;
|
}
|
||||||
|
|
||||||
final Element attrsRoot = rootElem.getChild("attributes");
|
public List<GSAttributeEncoder> getEncodedAttributeList() {
|
||||||
final List<Element> attrs = attrsRoot.getChildren();
|
List<GSAttributeEncoder> attrsList = null;
|
||||||
if (attrs != null) {
|
|
||||||
attrsList = new ArrayList<GSAttributeEncoder>(attrs.size());
|
final Element attrsRoot = rootElem.getChild("attributes");
|
||||||
for (Element attr : attrs) {
|
final List<Element> attrs = attrsRoot.getChildren();
|
||||||
final GSAttributeEncoder attrEnc = new GSAttributeEncoder();
|
if (attrs != null) {
|
||||||
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
attrsList = new ArrayList<GSAttributeEncoder>(attrs.size());
|
||||||
String key = at.toString();
|
for (Element attr : attrs) {
|
||||||
attrEnc.setAttribute(at, attr.getChildText(key));
|
final GSAttributeEncoder attrEnc = new GSAttributeEncoder();
|
||||||
}
|
for (FeatureTypeAttribute at : FeatureTypeAttribute.values()) {
|
||||||
attrsList.add(attrEnc);
|
String key = at.toString();
|
||||||
}
|
attrEnc.setAttribute(at, attr.getChildText(key));
|
||||||
|
}
|
||||||
}
|
attrsList.add(attrEnc);
|
||||||
return attrsList;
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
// /**
|
return attrsList;
|
||||||
// * @return the list of available attribute names
|
}
|
||||||
// */
|
|
||||||
// public List<String> getAttributeNames() {
|
/**
|
||||||
// return getAttributes("name");
|
*
|
||||||
// }
|
* @author Emmanuel Blondel
|
||||||
//
|
*
|
||||||
// /**
|
* @return the list of metadataLinkInfo
|
||||||
// * @return a list of object which are String representation of Classes
|
*/
|
||||||
// */
|
public List<Map<ResourceMetadataLinkInfo, String>> getMetadataLinkInfoList() {
|
||||||
// public List<String> getAttributeBinding() {
|
List<Map<ResourceMetadataLinkInfo, String>> metaLinksList = null;
|
||||||
// return getAttributes("binding");
|
|
||||||
// }
|
final Element metaLinksRoot = rootElem.getChild("metadataLinks");
|
||||||
|
final List<Element> metaLinks = metaLinksRoot.getChildren();
|
||||||
// /**
|
if (metaLinks != null) {
|
||||||
// * <attribute><br>
|
metaLinksList = new ArrayList<Map<ResourceMetadataLinkInfo, String>>(metaLinks.size());
|
||||||
// * <name>NATION</name><br>
|
for (Element metaLink : metaLinks) {
|
||||||
// * <minOccurs>0</minOccurs><br>
|
Map<ResourceMetadataLinkInfo, String> metaLinkMap = new HashMap<ResourceMetadataLinkInfo, String>();
|
||||||
// * <maxOccurs>1</maxOccurs><br>
|
metaLinksList.add(metaLinkMap);
|
||||||
// * <nillable>true</nillable><br>
|
for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo.values()) {
|
||||||
// * <binding>java.lang.Integer</binding><br>
|
String key = rmd.toString();
|
||||||
// * <length>3</length><br>
|
metaLinkMap.put(rmd, metaLink.getChildText(key));
|
||||||
// * </attribute><br>
|
}
|
||||||
// *
|
}
|
||||||
// * @param name
|
}
|
||||||
// * @return
|
return metaLinksList;
|
||||||
// */
|
}
|
||||||
// private List<String> getAttributes(String name) {
|
|
||||||
// final Element attrsRoot = rootElem.getChild("attributes");
|
|
||||||
// final List<Element> attrs = attrsRoot.getChildren();
|
/**
|
||||||
// List<String> attrNames = null;
|
*
|
||||||
// if (attrs != null) {
|
* @author Emmanuel Blondel
|
||||||
// attrNames = new ArrayList<String>(attrs.size());
|
*
|
||||||
// for (Element attr : attrs) {
|
* @return the list of GSMetadataLinkEncoder
|
||||||
// attrNames.add(attr.getChildText(name));
|
*/
|
||||||
// }
|
public List<GSMetadataLinkInfoEncoder> getEncodedMetadataLinkInfoList() {
|
||||||
// }
|
List<GSMetadataLinkInfoEncoder> metaLinksList = null;
|
||||||
// return attrNames;
|
|
||||||
// }
|
final Element metaLinksRoot = rootElem.getChild("metadataLinks");
|
||||||
}
|
final List<Element> metaLinks = metaLinksRoot.getChildren();
|
||||||
|
if (metaLinks != null) {
|
||||||
|
metaLinksList = new ArrayList<GSMetadataLinkInfoEncoder>(metaLinks.size());
|
||||||
|
for (Element metaLink : metaLinks) {
|
||||||
|
final GSMetadataLinkInfoEncoder metaLinkEnc = new GSMetadataLinkInfoEncoder();
|
||||||
|
for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo.values()) {
|
||||||
|
String key = rmd.toString();
|
||||||
|
metaLinkEnc.setMetadataLinkInfoMember(rmd, metaLink.getChildText(key)); //change
|
||||||
|
}
|
||||||
|
metaLinksList.add(metaLinkEnc);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return metaLinksList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return the list of available attribute names
|
||||||
|
// */
|
||||||
|
// public List<String> getAttributeNames() {
|
||||||
|
// return getAttributes("name");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /**
|
||||||
|
// * @return a list of object which are String representation of Classes
|
||||||
|
// */
|
||||||
|
// public List<String> getAttributeBinding() {
|
||||||
|
// return getAttributes("binding");
|
||||||
|
// }
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * <attribute><br>
|
||||||
|
// * <name>NATION</name><br>
|
||||||
|
// * <minOccurs>0</minOccurs><br>
|
||||||
|
// * <maxOccurs>1</maxOccurs><br>
|
||||||
|
// * <nillable>true</nillable><br>
|
||||||
|
// * <binding>java.lang.Integer</binding><br>
|
||||||
|
// * <length>3</length><br>
|
||||||
|
// * </attribute><br>
|
||||||
|
// *
|
||||||
|
// * @param name
|
||||||
|
// * @return
|
||||||
|
// */
|
||||||
|
// private List<String> getAttributes(String name) {
|
||||||
|
// final Element attrsRoot = rootElem.getChild("attributes");
|
||||||
|
// final List<Element> attrs = attrsRoot.getChildren();
|
||||||
|
// List<String> attrNames = null;
|
||||||
|
// if (attrs != null) {
|
||||||
|
// attrNames = new ArrayList<String>(attrs.size());
|
||||||
|
// for (Element attr : attrs) {
|
||||||
|
// attrNames.add(attr.getChildText(name));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return attrNames;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user