/* * 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.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 */ public abstract class GSResourceEncoder extends PropertyXMLEncoder { public final static String NAME = "name"; public final static String METADATA="metadata"; public final static String KEYWORDS="keywords"; final private GSMetadataEncoder metadata = new GSMetadataEncoder(); final private Element keywordsListEncoder = new Element(KEYWORDS); 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); } public void setEnabled(boolean enabled) { set("enabled", (enabled) ? "true" : "false"); } // TODO MetadataLink // public void setMetadata(String key, String url){ // metadata.set(key, url); // } /** * @param key * @param dimensionInfo */ protected void addMetadata(String key, XmlElement dimensionInfo) { metadata.add(key, dimensionInfo.getRoot()); } public void setMetadata(String key, XmlElement dimensionInfo) { 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; } /** * Reprojection policy for a published layer. One of: *