MetadataLink support - enrich javadoc & format code/comments
This commit is contained in:
parent
7fee169369
commit
4aeac4d080
@ -43,7 +43,8 @@ import org.jdom.Namespace;
|
||||
* Parse a resource (FeatureType or Coverage) returned as XML REST objects.
|
||||
*
|
||||
* @author etj
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||
* emmanuel.blondel@fao.org
|
||||
*/
|
||||
public class RESTResource {
|
||||
protected final Element rootElem;
|
||||
@ -160,10 +161,11 @@ public class RESTResource {
|
||||
|
||||
|
||||
/**
|
||||
* Decodes the list of MetadataLinkInfo from the GeoServer Resource
|
||||
*
|
||||
* @author Emmanuel Blondel
|
||||
*
|
||||
* @return the list of metadataLinkInfo
|
||||
* @return the list of Map<ResourceMetadataLinkInfo,String>
|
||||
*/
|
||||
public List<Map<ResourceMetadataLinkInfo, String>> getMetadataLinkInfoList() {
|
||||
List<Map<ResourceMetadataLinkInfo, String>> metaLinksList = null;
|
||||
@ -171,11 +173,13 @@ public class RESTResource {
|
||||
final Element metaLinksRoot = rootElem.getChild("metadataLinks");
|
||||
final List<Element> metaLinks = metaLinksRoot.getChildren();
|
||||
if (metaLinks != null) {
|
||||
metaLinksList = new ArrayList<Map<ResourceMetadataLinkInfo, String>>(metaLinks.size());
|
||||
metaLinksList = new ArrayList<Map<ResourceMetadataLinkInfo, String>>(
|
||||
metaLinks.size());
|
||||
for (Element metaLink : metaLinks) {
|
||||
Map<ResourceMetadataLinkInfo, String> metaLinkMap = new HashMap<ResourceMetadataLinkInfo, String>();
|
||||
metaLinksList.add(metaLinkMap);
|
||||
for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo.values()) {
|
||||
for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo
|
||||
.values()) {
|
||||
String key = rmd.toString();
|
||||
metaLinkMap.put(rmd, metaLink.getChildText(key));
|
||||
}
|
||||
@ -184,8 +188,8 @@ public class RESTResource {
|
||||
return metaLinksList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Decodes the list of MetadataLinkInfo from the GeoServer Resource
|
||||
*
|
||||
* @author Emmanuel Blondel
|
||||
*
|
||||
@ -197,12 +201,15 @@ public class RESTResource {
|
||||
final Element metaLinksRoot = rootElem.getChild("metadataLinks");
|
||||
final List<Element> metaLinks = metaLinksRoot.getChildren();
|
||||
if (metaLinks != null) {
|
||||
metaLinksList = new ArrayList<GSMetadataLinkInfoEncoder>(metaLinks.size());
|
||||
metaLinksList = new ArrayList<GSMetadataLinkInfoEncoder>(
|
||||
metaLinks.size());
|
||||
for (Element metaLink : metaLinks) {
|
||||
final GSMetadataLinkInfoEncoder metaLinkEnc = new GSMetadataLinkInfoEncoder();
|
||||
for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo.values()) {
|
||||
for (ResourceMetadataLinkInfo rmd : ResourceMetadataLinkInfo
|
||||
.values()) {
|
||||
String key = rmd.toString();
|
||||
metaLinkEnc.setMetadataLinkInfoMember(rmd, metaLink.getChildText(key)); //change
|
||||
metaLinkEnc.setMetadataLinkInfoMember(rmd,
|
||||
metaLink.getChildText(key)); // change
|
||||
}
|
||||
metaLinksList.add(metaLinkEnc);
|
||||
}
|
||||
@ -211,7 +218,6 @@ public class RESTResource {
|
||||
return metaLinksList;
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// * @return the list of available attribute names
|
||||
// */
|
||||
|
||||
@ -47,7 +47,8 @@ import org.jdom.filter.Filter;
|
||||
*
|
||||
* @author ETj (etj at geo-solutions.it)
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||
* emmanuel.blondel@fao.org
|
||||
*/
|
||||
public abstract class GSResourceEncoder
|
||||
extends PropertyXMLEncoder {
|
||||
@ -86,10 +87,6 @@ public abstract class GSResourceEncoder
|
||||
set("enabled", (enabled) ? "true" : "false");
|
||||
}
|
||||
|
||||
// TODO MetadataLink
|
||||
// public void setMetadata(String key, String url){
|
||||
// metadata.set(key, url);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @param key
|
||||
@ -141,9 +138,10 @@ public abstract class GSResourceEncoder
|
||||
})).size() == 0 ? false : true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param MetadataLink the metadataLink to add
|
||||
* Adds a MetadataLinkInfo to the GeoServer Resource
|
||||
*
|
||||
* @param MetadataLink
|
||||
*
|
||||
* @author Emmanuel Blondel
|
||||
*/
|
||||
@ -151,8 +149,8 @@ public abstract class GSResourceEncoder
|
||||
metadataLinksListEncoder.addContent(metadataLinkInfo.getRoot());
|
||||
}
|
||||
|
||||
|
||||
/** Quick MetadataLinkInfo set-up
|
||||
/**
|
||||
* Adds quickly a MetadataLinkInfo to the GeoServer Resource
|
||||
*
|
||||
* @author Emmanuel Blondel
|
||||
*
|
||||
@ -160,15 +158,16 @@ public abstract class GSResourceEncoder
|
||||
* @param metadataType
|
||||
* @param content
|
||||
*/
|
||||
public void addMetadataLinkInfo(String type, String metadataType, String content){
|
||||
public void addMetadataLinkInfo(String type, String metadataType,
|
||||
String content) {
|
||||
final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder();
|
||||
mde.setup(type, metadataType, content);
|
||||
metadataLinksListEncoder.addContent(mde.getRoot());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete a metadataLinkInfo from the list using the metadataURL (MetadataLinkInfo content)
|
||||
* Deletes a metadataLinkInfo from the list using the metadataURL
|
||||
* (MetadataLinkInfo content)
|
||||
*
|
||||
* @author Emmanuel Blondel
|
||||
*
|
||||
@ -176,7 +175,9 @@ public abstract class GSResourceEncoder
|
||||
* @return true if something is removed, false otherwise
|
||||
*/
|
||||
public boolean delMetadataLinkInfo(final String metadataURL) {
|
||||
return (metadataLinksListEncoder.removeContent(GSMetadataLinkInfoEncoder.getFilterByContent(metadataURL))).size() == 0 ? false
|
||||
return (metadataLinksListEncoder
|
||||
.removeContent(GSMetadataLinkInfoEncoder
|
||||
.getFilterByContent(metadataURL))).size() == 0 ? false
|
||||
: true;
|
||||
}
|
||||
|
||||
|
||||
@ -33,72 +33,129 @@ import org.jdom.filter.Filter;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
|
||||
|
||||
/** GSMetadataLinkEncoder
|
||||
/**
|
||||
* GSMetadataLinkEncoder - encodes a metadataLink for a given GeoServer Resource
|
||||
* (feature type /coverage), as follows:
|
||||
* <pre>
|
||||
* {@code
|
||||
* final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder();
|
||||
* mde.setup("text/xml", "ISO19115:2003","http://www.organization.org/metadata");
|
||||
* }
|
||||
* </pre>
|
||||
* For this example, the XML output is:
|
||||
* <pre>
|
||||
* {@code
|
||||
* <metadataLink>
|
||||
* <type>text/xml</type>
|
||||
* <metadataType>ISO19115:2003</metadataType>
|
||||
* <content>http://www.organization.org/metadata</content>
|
||||
* </metadataLink>
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||
* emmanuel.blondel@fao.org
|
||||
*
|
||||
*/
|
||||
public class GSMetadataLinkInfoEncoder extends PropertyXMLEncoder {
|
||||
|
||||
/** A class to filter the MetadataLinkInfo by content
|
||||
*
|
||||
*
|
||||
*/
|
||||
public static class filterByContent implements Filter {
|
||||
|
||||
final private String key;
|
||||
|
||||
public filterByContent(String content){
|
||||
this.key=content;
|
||||
public filterByContent(String content) {
|
||||
this.key = content;
|
||||
}
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public boolean matches(Object obj) {
|
||||
Element el=((Element) obj).getChild(ResourceMetadataLinkInfo.content.toString());
|
||||
if (el!=null && el.getTextTrim().equals(key)) {
|
||||
Element el = ((Element) obj)
|
||||
.getChild(ResourceMetadataLinkInfo.content.toString());
|
||||
if (el != null && el.getTextTrim().equals(key)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Filter getFilterByContent(String content){
|
||||
/**
|
||||
* Get a Filter using the MetadataLinkInfo content (metadataURL)
|
||||
*
|
||||
* @param content
|
||||
* @return the filter
|
||||
*/
|
||||
public static Filter getFilterByContent(String content) {
|
||||
return new filterByContent(content);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new GSMetadataLinkInfoEncoder
|
||||
*
|
||||
*/
|
||||
public GSMetadataLinkInfoEncoder() {
|
||||
super("metadataLink");
|
||||
}
|
||||
|
||||
/** quick MetadataLinkInfo set-up
|
||||
/**
|
||||
* Set-up quickly a metadataLinkInfo
|
||||
*
|
||||
* @param type
|
||||
* @param metadataType
|
||||
* @param content
|
||||
*/
|
||||
public void setup(String type, String metadataType, String content){
|
||||
public void setup(String type, String metadataType, String content) {
|
||||
set(ResourceMetadataLinkInfo.type.name(), type);
|
||||
set(ResourceMetadataLinkInfo.metadataType.name(), metadataType);
|
||||
set(ResourceMetadataLinkInfo.content.name(), content);
|
||||
}
|
||||
|
||||
public void setup(Map<ResourceMetadataLinkInfo, String> metadataLinkInfos){
|
||||
for (Entry<ResourceMetadataLinkInfo,String> mdLinkInfo:metadataLinkInfos.entrySet()){
|
||||
set(mdLinkInfo.getKey().toString(),mdLinkInfo.getValue());
|
||||
/**
|
||||
* Set-up a metadataLinkInfo
|
||||
*
|
||||
* @param metadataLinkInfos
|
||||
*/
|
||||
public void setup(Map<ResourceMetadataLinkInfo, String> metadataLinkInfos) {
|
||||
for (Entry<ResourceMetadataLinkInfo, String> mdLinkInfo : metadataLinkInfos
|
||||
.entrySet()) {
|
||||
set(mdLinkInfo.getKey().toString(), mdLinkInfo.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public void setMetadataLinkInfoMember(ResourceMetadataLinkInfo type, String value){
|
||||
set(type.toString(),value);
|
||||
/**
|
||||
* Set a MetadataLinkInfo member (type, metadataType or content)
|
||||
*
|
||||
* @param type
|
||||
* @param value
|
||||
*/
|
||||
public void setMetadataLinkInfoMember(ResourceMetadataLinkInfo type,
|
||||
String value) {
|
||||
set(type.toString(), value);
|
||||
}
|
||||
|
||||
|
||||
public boolean delMetadataLinkInfoMember(ResourceMetadataLinkInfo type){
|
||||
/**
|
||||
* Deletes a MetadataLinkInfo member
|
||||
*
|
||||
* @param type
|
||||
* @return true if the metadataLinkInfo member is removed
|
||||
*/
|
||||
public boolean delMetadataLinkInfoMember(ResourceMetadataLinkInfo type) {
|
||||
return ElementUtils.remove(this.getRoot(), get(type.toString()));
|
||||
}
|
||||
|
||||
|
||||
public String getMetadataLinkInfoMember(ResourceMetadataLinkInfo type){
|
||||
/**
|
||||
* Get the value of the MetadataLinkInfo member
|
||||
*
|
||||
* @param type
|
||||
* @return the value of the MetadataLinkInfo member
|
||||
*/
|
||||
public String getMetadataLinkInfoMember(ResourceMetadataLinkInfo type) {
|
||||
Element el = get(type.toString());
|
||||
if (el!=null)
|
||||
if (el != null)
|
||||
return el.getTextTrim();
|
||||
else
|
||||
return null;
|
||||
|
||||
@ -27,7 +27,8 @@ package it.geosolutions.geoserver.rest.encoder.metadatalink;
|
||||
/**
|
||||
* Enumeration of featureType metadataLink member
|
||||
*
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com | emmanuel.blondel@fao.org
|
||||
* @author Emmanuel Blondel - emmanuel.blondel1@gmail.com |
|
||||
* emmanuel.blondel@fao.org
|
||||
*
|
||||
*/
|
||||
public enum ResourceMetadataLinkInfo {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user