/* * GeoServer-Manager - Simple Manager Library for GeoServer * * Copyright (C) 2007,2011 GeoSolutions S.A.S. * http://www.geo-solutions.it * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * 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 * THE SOFTWARE. */ package it.geosolutions.geoserver.rest.encoder; import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadatalink.GSMetadataLinkInfoEncoder; import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils; import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder; import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; import it.geosolutions.geoserver.rest.encoder.utils.XmlElement; import org.jdom.Element; import org.jdom.filter.Filter; /** * * Encode a GeoServer resource. * * @see GSDimensionInfoEncoder * @see GSFeatureDimensionInfoEncoder * * @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 */ public abstract class GSResourceEncoder extends PropertyXMLEncoder { public final static String NAME = "name"; public final static String NATIVENAME = "nativeName"; public final static String METADATA="metadata"; public final static String KEYWORDS="keywords"; public final static String METADATALINKS="metadataLinks"; final private GSMetadataEncoder metadata = new GSMetadataEncoder(); final private Element keywordsListEncoder = new Element(KEYWORDS); final private Element metadataLinksListEncoder = new Element(METADATALINKS); private class GSMetadataEncoder extends NestedElementEncoder{ public GSMetadataEncoder() { super(METADATA); } } /** * @param rootName * Actually 'feature' or 'coverage' * @see GSFeatureTypeEncoder * @see GSCoverageEncoder */ protected GSResourceEncoder(final String rootName) { super(rootName); add("enabled", "true"); // Link members to the parent addContent(metadata.getRoot()); addContent(keywordsListEncoder); addContent(metadataLinksListEncoder); } public void setEnabled(boolean enabled) { set("enabled", (enabled) ? "true" : "false"); } /** * @param key * @param dimensionInfo */ protected void addMetadata(String key, XmlElement dimensionInfo) { metadata.add(key, dimensionInfo.getRoot()); } /** * @deprecated Use {@link #setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be set as protected for internal use only * @param key * @param dimensionInfo */ public void setMetadata(String key, XmlElement dimensionInfo) { metadata.set(key, dimensionInfo.getRoot()); } /** * @param key * @param dimensionInfo */ protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) { addMetadataDimension(key, dimensionInfo, false); } /** * Add the metadata for a custom dimension. * * @param key the name of the dimension * @param dimensionInfo {@link GSDimensionInfoEncoder} with additional information about the dimension * @param custom is the dimension custom or not? */ protected void addMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo, boolean custom) { if(custom){ metadata.set("custom_dimension_"+key.toUpperCase(), dimensionInfo.getRoot()); }else{ metadata.add(key, dimensionInfo.getRoot()); } } public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo) { setMetadataDimension(key, dimensionInfo, false); } /** * Set the metadata for a custom dimension. * * @param key the name of the dimension * @param dimensionInfo {@link GSDimensionInfoEncoder} with additional information about the dimension * @param custom is the dimension custom or not? */ public void setMetadataDimension(String key, GSDimensionInfoEncoder dimensionInfo, boolean custom) { if(custom){ metadata.set("custom_dimension_"+key.toUpperCase(), dimensionInfo.getRoot()); }else{ metadata.set(key, dimensionInfo.getRoot()); } } /** * @param key * the name of the metadata to add (f.e.: elevation, time) * @return true if something is removed, false otherwise */ public boolean delMetadata(String key) { return metadata.remove(key); } public void addKeyword(String keyword) { final Element el = new Element("string"); el.setText(keyword); keywordsListEncoder.addContent(el); } /** * delete a keyword from the list * * @param keyword * @return true if something is removed, false otherwise */ public boolean delKeyword(final String keyword) { final Element el = new Element("string"); el.setText(keyword); return (keywordsListEncoder.removeContent(new Filter() { private static final long serialVersionUID = 1L; public boolean matches(Object obj) { if (((Element) obj).getText().equals(keyword)) { return true; } return false; } })).size() == 0 ? false : true; } /** * Adds a MetadataLinkInfo to the GeoServer Resource * * @param MetadataLink * * @author Emmanuel Blondel */ public void addMetadataLinkInfo(GSMetadataLinkInfoEncoder metadataLinkInfo) { metadataLinksListEncoder.addContent(metadataLinkInfo.getRoot()); } /** * Adds quickly a MetadataLinkInfo to the GeoServer Resource * * @author Emmanuel Blondel * * @param type * @param metadataType * @param content */ public void addMetadataLinkInfo(String type, String metadataType, String content) { final GSMetadataLinkInfoEncoder mde = new GSMetadataLinkInfoEncoder( type, metadataType, content); metadataLinksListEncoder.addContent(mde.getRoot()); } /** * Deletes a metadataLinkInfo from the list using the metadataURL * (MetadataLinkInfo content) * * @author Emmanuel Blondel * * @param metadataURL * @return true if something is removed, false otherwise */ public boolean delMetadataLinkInfo(final String metadataURL) { return (metadataLinksListEncoder .removeContent(GSMetadataLinkInfoEncoder .getFilterByContent(metadataURL))).size() == 0 ? false : true; } /** * Reprojection policy for a published layer. One of: *