From 11204e4e294c28b9952c51e21838f4a8f24342b0 Mon Sep 17 00:00:00 2001 From: ccancellieri Date: Thu, 14 Jul 2011 17:05:40 +0200 Subject: [PATCH] changes implementing enhancement 8 and code review 10, 11 --- .../rest/GeoServerRESTPublisher.java | 33 ++-- .../rest/encoder/GSCoverageEncoder.java | 62 -------- .../rest/encoder/GSFeatureTypeEncoder.java | 42 ----- .../rest/encoder/GSLayerEncoder.java | 8 +- .../encoder/GSPostGISDatastoreEncoder.java | 69 +++++---- .../rest/encoder/GSResourceEncoder.java | 73 +++++---- .../rest/encoder/GSWorkspaceEncoder.java | 6 +- .../encoder/coverage/GSCoverageEncoder.java | 64 -------- .../coverage/GSImageMosaicEncoder.java | 104 +++++++++++++ .../GSFeatureDimensionInfoEncoder.java | 25 +++ .../encoder/feature/GSFeatureTypeEncoder.java | 2 + .../metadata/GSDimensionInfoEncoder.java | 64 +++++++- .../encoder/metadata/GSMetadataEncoder.java | 29 +++- .../rest/encoder/utils/ElementUtils.java | 145 ++++++++++++++++++ ...Encoder.java => NestedElementEncoder.java} | 50 ++---- .../encoder/utils/PropertyXMLEncoder.java | 123 +++++---------- .../encoder/utils/TextNodeListEncoder.java | 66 -------- .../{XMLSerializer.java => XmlElement.java} | 42 +++-- .../GeoserverRESTPostgisDatastoreTest.java | 24 +-- .../GSCoverageEncoderTest.java | 40 +++-- .../coverage/GSImageMosaicEncoderTest.java | 86 +++++++++++ .../GSFeatureEncoderTest.java | 6 +- .../utils/EntryKeyListEncoderTest.java | 4 +- 23 files changed, 691 insertions(+), 476 deletions(-) delete mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/GSCoverageEncoder.java delete mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/GSFeatureTypeEncoder.java create mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoder.java create mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/utils/ElementUtils.java rename src/main/java/it/geosolutions/geoserver/rest/encoder/utils/{EntryKeyListEncoder.java => NestedElementEncoder.java} (70%) delete mode 100644 src/main/java/it/geosolutions/geoserver/rest/encoder/utils/TextNodeListEncoder.java rename src/main/java/it/geosolutions/geoserver/rest/encoder/utils/{XMLSerializer.java => XmlElement.java} (70%) rename src/test/java/it/geosolutions/geoserver/rest/encoder/{utils => coverage}/GSCoverageEncoderTest.java (60%) create mode 100644 src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoderTest.java rename src/test/java/it/geosolutions/geoserver/rest/encoder/{utils => feature}/GSFeatureEncoderTest.java (91%) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index eb3b3f4..28bd0bc 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -38,6 +38,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLEncoder; +import org.apache.commons.io.FilenameUtils; import org.apache.log4j.Logger; /** @@ -217,7 +218,7 @@ public class GeoServerRESTPublisher { try { GSLayerEncoder layerEncoder = new GSLayerEncoder(); - layerEncoder.setDefaultStyle(defaultStyle); + layerEncoder.addDefaultStyle(defaultStyle); configureLayer(layerEncoder, layerName); } catch (Exception e) { LOGGER.warn("Error in publishing shapefile " + e.getMessage(), e); @@ -267,8 +268,8 @@ public class GeoServerRESTPublisher { .append("/featuretypes/").append(layername); GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder(); - fte.setName(layername); - fte.setSRS(srs); + fte.addName(layername); + fte.addSRS(srs); String configuredResult = HTTPUtils.putXml(postUrl.toString(), fte.toString(), this.gsuser, this.gspass); boolean shpConfigured = configuredResult != null; @@ -308,8 +309,8 @@ public class GeoServerRESTPublisher { .append("/featuretypes"); GSFeatureTypeEncoder fte = new GSFeatureTypeEncoder(); - fte.setName(layername); - fte.setSRS(srs); // srs=null?"EPSG:4326":srs); + fte.addName(layername); + fte.addSRS(srs); // srs=null?"EPSG:4326":srs); String ftypeXml = fte.toString(); String configuredResult = HTTPUtils.postXml(postUrl.toString(), ftypeXml, this.gsuser, this.gspass); @@ -323,7 +324,7 @@ public class GeoServerRESTPublisher { LOGGER.info("DB layer successfully added (layer:" + layername + ")"); GSLayerEncoder layerEncoder = new GSLayerEncoder(); - layerEncoder.setDefaultStyle(defaultStyle); + layerEncoder.addDefaultStyle(defaultStyle); configured = configureLayer(layerEncoder, layername); if (!configured) { @@ -385,16 +386,17 @@ public class GeoServerRESTPublisher { LOGGER.error("No coverages found in new coveragestore " + storeName); return null; } - String coverageName = covList.get(0).getName(); + final String coverageName = covList.get(0).getName(); // config coverage props (srs) GSCoverageEncoder coverageEncoder = new GSCoverageEncoder(); - coverageEncoder.setSRS(srs); + coverageEncoder.addName(FilenameUtils.getBaseName(geotiff.getName())); + coverageEncoder.addSRS(srs); configureCoverage(coverageEncoder, workspace, storeName, coverageName); // config layer props (style, ...) GSLayerEncoder layerEncoder = new GSLayerEncoder(); - layerEncoder.setDefaultStyle(defaultStyle); + layerEncoder.addDefaultStyle(defaultStyle); configureLayer(layerEncoder, coverageName); } catch (Exception e) { @@ -452,10 +454,10 @@ public class GeoServerRESTPublisher { */ public RESTCoverageStore publishExternalMosaic(String workspace, String storeName, File mosaicDir, String srs, String defaultStyle) throws FileNotFoundException { GSCoverageEncoder coverageEncoder = new GSCoverageEncoder(); - coverageEncoder.setSRS(srs); - + coverageEncoder.addSRS(srs); + coverageEncoder.addName(FilenameUtils.getBaseName(mosaicDir.getName())); GSLayerEncoder layerEncoder = new GSLayerEncoder(); - layerEncoder.setDefaultStyle(defaultStyle); + layerEncoder.addDefaultStyle(defaultStyle); return publishExternalMosaic(workspace, storeName, mosaicDir, coverageEncoder, layerEncoder); } @@ -754,6 +756,11 @@ public class GeoServerRESTPublisher { } protected String encode(String s) { - return URLEncoder.encode(s); +// try { +// return URLEncoder.encode(s,"UTF-8"); +// } catch (UnsupportedEncodingException e) { +// LOGGER.warn("Error encoding :"+s+" with UTF-8: "+e.getLocalizedMessage()); + return URLEncoder.encode(s); +// } } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSCoverageEncoder.java deleted file mode 100644 index c512958..0000000 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSCoverageEncoder.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.utils.EntryKeyListEncoder; -import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder; -import org.jdom.Element; - -/** - * Creates an XML - * - * @author ETj (etj at geo-solutions.it) - */ -public class GSCoverageEncoder extends GSResourceEncoder { - - private EntryKeyListEncoder metadataEncoder = new EntryKeyListEncoder("metadata"); - private TextNodeListEncoder keywordsListEncoder = new TextNodeListEncoder("keywords"); - - - public GSCoverageEncoder() { - super("coverage"); - set("enabled", "true"); - } - - public void addMetadata(String key, String value) { - metadataEncoder.add(key, value); - } - - public void addKeyword(String keyword) { - keywordsListEncoder.add("string", keyword); - } - - @Override - protected void addNodesBeforeOutput(Element e) { - super.addNodesBeforeOutput(e); - keywordsListEncoder.attachList(e); - metadataEncoder.attachList(e); - } -} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSFeatureTypeEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSFeatureTypeEncoder.java deleted file mode 100644 index 0cc6cf5..0000000 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSFeatureTypeEncoder.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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; - -/** - * - * @author ETj (etj at geo-solutions.it) - */ -public class GSFeatureTypeEncoder extends GSResourceEncoder { - - public GSFeatureTypeEncoder() { - super("featureType"); - set("enabled", "true"); - } - - public void setName(String name) { - setOrRemove("name", name); - } -} \ No newline at end of file diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java index ab71790..c192563 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSLayerEncoder.java @@ -30,6 +30,8 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; /** * * @author ETj (etj at geo-solutions.it) + * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it + * */ public class GSLayerEncoder extends PropertyXMLEncoder { @@ -38,12 +40,8 @@ public class GSLayerEncoder extends PropertyXMLEncoder { // enable layer add("enabled","true"); } - -// public void setWmsPath(String wmspath) { -// add("wmspath", wmspath); -// } - public void setDefaultStyle(String defaultStyle) { + public void addDefaultStyle(String defaultStyle) { add("defaultStyle", defaultStyle); } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSPostGISDatastoreEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSPostGISDatastoreEncoder.java index d0d604b..7b5c68e 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSPostGISDatastoreEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSPostGISDatastoreEncoder.java @@ -25,7 +25,7 @@ package it.geosolutions.geoserver.rest.encoder; -import it.geosolutions.geoserver.rest.encoder.utils.EntryKeyListEncoder; +import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder; import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; /** @@ -33,16 +33,17 @@ import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; * * @author Eric Grosso * @author ETj + * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it */ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder { - private EntryKeyListEncoder connectionParameters = new EntryKeyListEncoder("connectionParameters"); + private NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters"); public GSPostGISDatastoreEncoder() { super("dataStore"); - setType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)" - setDatabaseType("postgis"); + addType("PostGIS"); // may be overwritten with e.g. "PostGIS (JNDI)" + addDatabaseType("postgis"); } /** @@ -59,104 +60,104 @@ public class GSPostGISDatastoreEncoder extends PropertyXMLEncoder { * */ public void defaultInit() { - setMinConnections(1); - setMaxConnections(10); - setFetchSize(1000); - setConnectionTimeout(20); - setLooseBBox(true); - setPreparedStatements(false); - setMaxOpenPreparedStatements(50); + addMinConnections(1); + addMaxConnections(10); + addFetchSize(1000); + addConnectionTimeout(20); + addLooseBBox(true); + addPreparedStatements(false); + addMaxOpenPreparedStatements(50); } - public void setName(String name) { + public void addName(String name) { add("name", name); } - public void setDescription(String description) { + public void addDescription(String description) { add("description", description); } - public void setType(String type) { + public void addType(String type) { add("type", type); } - public void setEnabled(boolean enabled) { + public void addEnabled(boolean enabled) { add("enabled", Boolean.toString(enabled)); } - public void setNamespace(String namespace) { + public void addNamespace(String namespace) { connectionParameters.add("namespace", namespace); } - public void setHost(String host) { + public void addHost(String host) { connectionParameters.add("host", host); } - public void setPort(int port) { + public void addPort(int port) { connectionParameters.add("port", Integer.toString(port)); } - public void setDatabase(String database) { + public void addDatabase(String database) { connectionParameters.add("database", database); } - public void setSchema(String schema) { + public void addSchema(String schema) { connectionParameters.add("schema", schema); } - public void setUser(String user) { + public void addUser(String user) { connectionParameters.add("user", user); } - public void setPassword(String password) { + public void addPassword(String password) { connectionParameters.add("passwd", password); } - public void setDatabaseType(String dbtype) { + public void addDatabaseType(String dbtype) { connectionParameters.add("dbtype", dbtype); } - public void setJndiReferenceName(String jndiReferenceName) { + public void addJndiReferenceName(String jndiReferenceName) { connectionParameters.add("jndiReferenceName", jndiReferenceName); } - public void setExposePrimaryKeys(boolean exposePrimaryKeys) { + public void addExposePrimaryKeys(boolean exposePrimaryKeys) { connectionParameters.add("Expose primary keys", Boolean.toString(exposePrimaryKeys)); } - public void setMaxConnections(int maxConnections) { + public void addMaxConnections(int maxConnections) { connectionParameters.add("max connections", Integer.toString(maxConnections)); } - public void setMinConnections(int minConnections) { + public void addMinConnections(int minConnections) { connectionParameters.add("min connections", Integer.toString(minConnections)); } - public void setFetchSize(int fetchSize) { + public void addFetchSize(int fetchSize) { connectionParameters.add("fetch size", Integer.toString(fetchSize)); } - public void setConnectionTimeout(int seconds) { + public void addConnectionTimeout(int seconds) { connectionParameters.add("Connection timeout", Integer.toString(seconds)); } - public void setValidateConnections(boolean validateConnections) { + public void addValidateConnections(boolean validateConnections) { connectionParameters.add("validate connections", Boolean.toString(validateConnections)); } - public void setPrimaryKeyMetadataTable(String primaryKeyMetadataTable) { + public void addPrimaryKeyMetadataTable(String primaryKeyMetadataTable) { connectionParameters.add("Primary key metadata table", primaryKeyMetadataTable); } - public void setLooseBBox(boolean looseBBox) { + public void addLooseBBox(boolean looseBBox) { connectionParameters.add("Loose bbox", Boolean.toString(looseBBox)); } - public void setPreparedStatements(boolean preparedStatements) { + public void addPreparedStatements(boolean preparedStatements) { connectionParameters.add("preparedStatements", Boolean.toString(preparedStatements)); } - public void setMaxOpenPreparedStatements(int maxOpenPreparedStatements) { + public void addMaxOpenPreparedStatements(int maxOpenPreparedStatements) { connectionParameters.add("Max open prepared statements", Integer.toString(maxOpenPreparedStatements)); } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java index 5d21f28..b869fc0 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java @@ -25,26 +25,55 @@ package it.geosolutions.geoserver.rest.encoder; +import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder; +import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; import it.geosolutions.geoserver.rest.encoder.metadata.GSMetadataEncoder; import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder; -import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder; + +import org.jdom.Element; /** + * + * Encode a GeoServer resouce. + * The type regards the GDSDimensionInfoEncoder metadata Type which has + * different specialization for Features. + * + * @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 { + /** + * @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); + addContent(keywordsListEncoder); + } + final private GSMetadataEncoder metadata=new GSMetadataEncoder(); - public void addMetadata(String key, T dimensionInfo) { metadata.add(key, dimensionInfo); } - private TextNodeListEncoder keywordsListEncoder = new TextNodeListEncoder("keywords"); + final private Element keywordsListEncoder = new Element("keywords"); + + public void addKeyword(String keyword) { + final Element el=new Element("string"); + el.setText(keyword); + keywordsListEncoder.addContent(el); + } /** * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED @@ -52,29 +81,32 @@ public abstract class GSResourceEncoder extend public enum ProjectionPolicy { REPROJECT_TO_DECLARED, FORCE_DECLARED, NONE } - - protected GSResourceEncoder(final String rootName) { - super(rootName); - add("enabled", "true"); - // Link members to the parent - addContent(metadata.getElement()); - addContent(keywordsListEncoder.getElement()); + /** + * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED + */ + public void addProjectionPolicy(ProjectionPolicy policy) { + add("projectionPolicy", policy.toString()); } - public void setName(final String name) { + /** + * Add the 'name' node with a text value from 'name' + * @note REQUIRED to configure a resource + * + */ + public void addName(final String name) { add("name", name); } - public void setTitle(final String title) { + public void addTitle(final String title) { add("title", title); } - public void setSRS(final String srs) { + public void addSRS(final String srs) { add("srs", srs); } - public void setLatLonBoundingBox(double minx, double maxy, double maxx, + public void addLatLonBoundingBox(double minx, double maxy, double maxx, double miny, final String crs) { add("latLonBoundingBox/minx", String.valueOf(minx)); add("latLonBoundingBox/maxy", String.valueOf(maxy)); @@ -83,7 +115,7 @@ public abstract class GSResourceEncoder extend add("latLonBoundingBox/crs", crs); } - public void setNativeBoundingBox(double minx, double maxy, double maxx, + public void addNativeBoundingBox(double minx, double maxy, double maxx, double miny, final String crs) { add("nativeBoundingBox/minx", String.valueOf(minx)); add("nativeBoundingBox/maxy", String.valueOf(maxy)); @@ -92,16 +124,5 @@ public abstract class GSResourceEncoder extend add("nativeBoundingBox/crs", crs); } - /** - * NONE, REPROJECT_TO_DECLARED, FORCE_DECLARED - */ - public void setProjectionPolicy(ProjectionPolicy policy) { - add("projectionPolicy", policy.toString()); - } - - - public void addKeyword(String keyword) { - keywordsListEncoder.add("string", keyword); - } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoder.java index 954b699..46c3e78 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoder.java @@ -42,15 +42,15 @@ public class GSWorkspaceEncoder extends PropertyXMLEncoder { public GSWorkspaceEncoder(String name) { this(); - setName(name); + addName(name); } - public void setName(String name) { + public void addName(String name) { add("name", name); } public String getName(){ - final Element el=get("name"); + final Element el=contains("name"); if (el!=null) return el.getName(); else diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java index 61e5099..a3f8b68 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoder.java @@ -39,73 +39,9 @@ import org.jdom.Element; * */ public class GSCoverageEncoder extends GSResourceEncoder { - - - final private Element parameters=new Element("parameters"); public GSCoverageEncoder() { super("coverage"); - // Link members to the parent - addContent(parameters); - } - - - /** - * @param val - */ - public void setAllowMultithreading(final boolean val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("AllowMultithreading")); - param.addContent(new Element("string").setText((val)?"true":"false")); - parameters.addContent(param); } - public void setFilter(final String val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("Filter")); - param.addContent(new Element("string").setText(val)); - parameters.addContent(param); - } - - public void setMaxAllowedTiles(final int val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("MaxAllowedTiles")); - param.addContent(new Element("string").setText(String.valueOf(val))); - parameters.addContent(param); - } - - public void setInputTransparentColor(final String val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("InputTransparentColor")); - param.addContent(new Element("string").setText(val)); - parameters.addContent(param); - } - - public void setOutputTransparentColor(final String val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("OutputTransparentColor")); - param.addContent(new Element("string").setText(val)); - parameters.addContent(param); - } - - public void setSUGGESTED_TILE_SIZE(final String val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("SUGGESTED_TILE_SIZE")); - param.addContent(new Element("string").setText(val)); - parameters.addContent(param); - } - - public void setUSE_JAI_IMAGEREAD(final boolean val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("USE_JAI_IMAGEREAD")); - param.addContent(new Element("string").setText((val)?"true":"false")); - parameters.addContent(param); - } - - public void setBackgroundValues(final String val){ - final Element param=new Element("entry"); - param.addContent(new Element("string").setText("BackgroundValues")); - param.addContent(new Element("string").setText(val)); - parameters.addContent(param); - } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoder.java new file mode 100644 index 0000000..b3d8bb8 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoder.java @@ -0,0 +1,104 @@ +/* + * 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.coverage; + +import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder; + +import org.jdom.Element; + +/** + * + * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it + * + */ +public class GSImageMosaicEncoder extends GSCoverageEncoder { + + final private NestedElementEncoder parameters=new NestedElementEncoder("parameters"); + + public GSImageMosaicEncoder() { + // Link members to the parent + addContent(parameters); + } + + /** + * @param val + */ + public void addAllowMultithreading(final boolean val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("AllowMultithreading")); + param.addContent(new Element("string").setText((val)?"true":"false")); + parameters.addContent(param); + } + + public void addFilter(final String val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("Filter")); + param.addContent(new Element("string").setText(val)); + parameters.addContent(param); + } + + public void addMaxAllowedTiles(final int val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("MaxAllowedTiles")); + param.addContent(new Element("string").setText(String.valueOf(val))); + parameters.addContent(param); + } + + public void addInputTransparentColor(final String val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("InputTransparentColor")); + param.addContent(new Element("string").setText(val)); + parameters.addContent(param); + } + + public void addOutputTransparentColor(final String val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("OutputTransparentColor")); + param.addContent(new Element("string").setText(val)); + parameters.addContent(param); + } + + public void addSUGGESTED_TILE_SIZE(final String val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("SUGGESTED_TILE_SIZE")); + param.addContent(new Element("string").setText(val)); + parameters.addContent(param); + } + + public void addUSE_JAI_IMAGEREAD(final boolean val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("USE_JAI_IMAGEREAD")); + param.addContent(new Element("string").setText((val)?"true":"false")); + parameters.addContent(param); + } + + public void addBackgroundValues(final String val){ + final Element param=new Element("entry"); + param.addContent(new Element("string").setText("BackgroundValues")); + param.addContent(new Element("string").setText(val)); + parameters.addContent(param); + } + +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureDimensionInfoEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureDimensionInfoEncoder.java index 68111f9..af03bfc 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureDimensionInfoEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureDimensionInfoEncoder.java @@ -1,3 +1,28 @@ +/* + * 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.feature; import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java index 688d108..ff94c09 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureTypeEncoder.java @@ -28,6 +28,8 @@ package it.geosolutions.geoserver.rest.encoder.feature; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; /** + * + * Encode a GeoServer resource as FeatureType * * @author ETj (etj at geo-solutions.it) * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSDimensionInfoEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSDimensionInfoEncoder.java index 76136db..a636ebc 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSDimensionInfoEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSDimensionInfoEncoder.java @@ -1,45 +1,97 @@ +/* + * 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.metadata; +import it.geosolutions.geoserver.rest.encoder.utils.XmlElement; + import java.math.BigDecimal; -import it.geosolutions.geoserver.rest.encoder.utils.TextNodeListEncoder; +import org.jdom.Element; -public class GSDimensionInfoEncoder extends TextNodeListEncoder { +/** + * + * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it + * + */ +public class GSDimensionInfoEncoder extends XmlElement{ final boolean enabled; + /** + * Enum for presentation mode + */ public enum Presentation{ LIST, CONTINUOUS_INTERVAL } - - public enum DiscretePresentation{ + /** + * Enum for presentation mode which needs arguments + */ + public enum PresentationDiscrete{ DISCRETE_INTERVAL } + /** + * Build a dimension + * @param enabled enable dimension if true + * @note a enabled dimension also need a presentation mode set. + */ public GSDimensionInfoEncoder(final boolean enabled) { super("dimensionInfo"); add("enabled", (enabled)?"true":"false"); this.enabled=enabled; } + /** + * build an not enabled dimension + */ public GSDimensionInfoEncoder() { super("dimensionInfo"); add("enabled", "false"); this.enabled=Boolean.FALSE; } - public void setPresentation(final Presentation pres){ + public void addPresentation(final Presentation pres){ if (enabled){ add("presentation",pres.toString()); } } - public void setPresentation(final DiscretePresentation pres, final BigDecimal interval){ + public void addPresentation(final PresentationDiscrete pres, final BigDecimal interval){ if (enabled){ add("presentation",pres.toString()); add("resolution",String.valueOf(interval)); } } + + public void add(String nodename, String nodetext) { + final Element el=new Element(nodename); + el.setText(nodetext); + this.addContent(el); + } + } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSMetadataEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSMetadataEncoder.java index 9dd2482..b75356f 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSMetadataEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/metadata/GSMetadataEncoder.java @@ -1,8 +1,33 @@ +/* + * 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.metadata; -import it.geosolutions.geoserver.rest.encoder.utils.EntryKeyListEncoder; +import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder; -public class GSMetadataEncoder extends EntryKeyListEncoder{ +public class GSMetadataEncoder extends NestedElementEncoder{ public GSMetadataEncoder() { super("metadata"); diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/ElementUtils.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/ElementUtils.java new file mode 100644 index 0000000..23ff7f6 --- /dev/null +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/ElementUtils.java @@ -0,0 +1,145 @@ +/* + * 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.utils; + +import java.util.Iterator; +import java.util.List; + +import org.jdom.Element; + +/** + * + * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it + * + */ +public abstract class ElementUtils { + + /** + * + * @param root + * @param el + * @return true if the FIRST element EQUALS to the 'el' starting from root + * is found AND can be deleted. If it is the root true is returned + * and all of its child are removed. + * + */ + public static boolean remove(Element root, final Element el) { + if (root.equals(el)) { + if (!el.isRootElement()) { + root = el.getParentElement(); + // removing all child + el.removeContent(); + root.removeContent(el); + } else { + // log warn this is root! + // removing all child + el.removeContent(); + } + } else if ((root = ElementUtils.contains(root, el)) != null) { + return remove(root, el); + } else { + return false; + } + + return true; + } + + /** + * @param root + * @param el + * @return the FIRST element EQUALS to the 'el' starting from root or null + */ + public static Element contains(final Element root, final Element el) { + + if (root != null && el != null) { + if (root.equals(el)) + return root; + + final List childrenList = root.getChildren(); + if (childrenList.size() > 0) { + Iterator it = childrenList.iterator(); + while (it.hasNext()) { + final Element ret; + if ((ret = contains(it.next(), el)) != null) + return ret; + } + } + } + return null; + } + + /** + * @param root + * @param name + * @param val + * @return the FIRST element EQUALS to a node with name and a text value + * starting from root or null + */ + public static Element contains(final Element root, final String name, + final String val) { + if (root != null && name != null && val != null) { + if (root.getName().equals(name) && root.getText().equals(val)) + return root; + + final List childrenList = root.getChildren(); + if (childrenList.size() > 0) { + Iterator it = childrenList.iterator(); + while (it.hasNext()) { + final Element ret; + if ((ret = contains(it.next(), name, val)) != null) + return ret; + } + } + } + return null; + } + + /** + * return the FIRST element with name equals to the passed key + * + * @param root + * @param name + * @return + */ + public static Element contains(final Element root, final String name) { + if (root != null && name != null) { + if (root.getName().equals(name)) + return root; + + final List childrenList = root.getChildren(); + if (childrenList.size() > 0) { + Iterator it = childrenList.iterator(); + while (it.hasNext()) { + final Element ret; + if ((ret = contains(it.next(), name)) != null) + return ret; + } + } + } + return null; + } + +} diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/NestedElementEncoder.java similarity index 70% rename from src/main/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoder.java rename to src/main/java/it/geosolutions/geoserver/rest/encoder/utils/NestedElementEncoder.java index 0ea5043..db321bc 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/NestedElementEncoder.java @@ -25,8 +25,6 @@ package it.geosolutions.geoserver.rest.encoder.utils; -import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder; - import org.jdom.Element; /** @@ -43,9 +41,7 @@ import org.jdom.Element; * *
  * 
- * This can be also used in compounded to the PropertyXMLEncoder 
- * or other objects overriding the toString() method
- * 
+ * This can be also add compounded Elements
* e.g.: * *
@@ -71,40 +67,26 @@ import org.jdom.Element;
  * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
  * 
  */
-public class EntryKeyListEncoder  extends XMLSerializer{
+public class NestedElementEncoder extends XmlElement {
 
-	private final Element root;
-	
-	public EntryKeyListEncoder(String listName) {
-		root=new Element(listName);
+	public NestedElementEncoder(String listName) {
+		super(listName);
 	}
 
 	public void add(String key, T value) {
 		final Element entryElem = new Element("entry");
-		entryElem.setAttribute("key", key);
-		if (value instanceof String)
-			entryElem.setText((String)value);
-		else if (value instanceof Element)
-			entryElem.addContent((Element)value);
-		else if (value instanceof GSDimensionInfoEncoder)
-			entryElem.addContent(((GSDimensionInfoEncoder)value).getElement());
-		else
-			throw new IllegalArgumentException("Unable to add entry: unrecognized object");
-		
-		root.addContent(entryElem);
-	}
-	
+		if (key != null)
+			entryElem.setAttribute("key", key);
 
-	/**
-     * add a node to the root
-     * 
-     * @param el the node to add
-     */
-	public void addContent(final Element el){
-		root.addContent(el);
-	}
-	
-	public Element getElement() {
-			return root;
+		if (value instanceof String)
+			entryElem.setText((String) value);
+		else if (value instanceof Element)
+			entryElem.addContent((Element) value);
+		else
+			throw new IllegalArgumentException(
+					"Unable to add entry: unrecognized object");
+
+		this.addContent(entryElem);
 	}
+
 }
diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java
index 2c8b700..853daa0 100644
--- a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java
+++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/PropertyXMLEncoder.java
@@ -29,98 +29,57 @@ import org.jdom.Element;
 
 /**
  * Creates an XML document by mapping properties to XML nodes.
- * You can set the root element name in the constructor. - * Any key/value pair will be encoded as {@code value} node.

+ * You can set the root element name in the constructor. Any key/value pair will + * be encoded as {@code value} node.
+ *
* - *

Nested nodes

- * Any key containing one or more slash ("/") will be encoded as nested nodes; - *
e.g.: - *
 {@code 
- *          key = "k1/k2/k3", value = "value" }
will be encoded as - *
 {@code        value }
+ *

Nested nodes

Any key containing one or more slash ("/") will be + * encoded as nested nodes;
+ * e.g.: + * + *
+ * {@code 
+ *          key = "k1/k2/k3", value = "value" }
+ * 
+ * + * will be encoded as + * + *
+ * {@code        value }
+ * 
* * @author ETj (etj at geo-solutions.it) * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it */ -public class PropertyXMLEncoder extends XMLSerializer{ +public class PropertyXMLEncoder extends XmlElement { -// private final Map configElements = new HashMap(); - private final Element root; + public PropertyXMLEncoder(final String rootName) { + super(rootName); + } - public PropertyXMLEncoder(final String rootName) { - root=new Element(rootName); - } - - /** - * add a node (as child) to the root node - * - * @param el the node to add - */ - @Override - public void addContent(final Element el){ - root.addContent(el); - } - - /** - * @Deprecated use add() - */ - @Deprecated - protected void setOrRemove(String key, String value) { - final Element e=root.getChild(key); - if (value != null && e==null) { - add(root, key, value); - } else { - root.removeChild(key); - } - } - - protected void add(String key, String value) { - final Element e=root.getChild(key); - if (value != null && e==null) { - add(root, key, value); - } - } + protected void add(String key, String value) { + if (key != null && value != null) { + add(this, key, value); + } + } - public boolean isEmpty() { -// return configElements.isEmpty(); - return root.getChildren().isEmpty(); - } + private void add(Element e, String key, String value) { + if (!key.contains("/")) { + e.addContent(new Element(key).setText(value)); + } else { + final int i = key.indexOf("/"); + final String childName = key.substring(0, i); + final String newkey = key.substring(i + 1); - public Element get(final String key){ - return root.getChild(key); -// return configElements.get(key); - } + Element child = e.getChild(childName); + if (child == null) { + child = new Element(childName); + e.addContent(child); + } + add(child, newkey, value); + } - /** - * Subclasses may need to override this method if some more info in the XML - * string are needed when calling {@link #encodeXml() encodeXml()}. - * - * @param root the root element that will be converted into String by encodeXml - */ - @Override - public Element getElement(){ - return root; - } - - private void add(Element e, String key, String value) { - if( ! key.contains("/") ) { - e.addContent(new Element(key).setText(value)); - } else { - int i = key.indexOf("/"); - String childName = key.substring(0,i); - String newkey = key.substring(i+1); - - Element child = e.getChild(childName); - if(child == null) { - child = new Element(childName); - e.addContent(child); - } - - add(child, newkey, value); - } - - } - + } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/TextNodeListEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/TextNodeListEncoder.java deleted file mode 100644 index 09ab87b..0000000 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/TextNodeListEncoder.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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.utils; - -import org.jdom.Element; - -/** - * Encodes lists of simple text nodes. - *
e.g.: - *
- * {@code 
- *  
- *   nodetext1
- *   nodetext2
- *   nodetext3
- * }
- * 
- * 
- * @author ETj (etj at geo-solutions.it)
- * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
- */
-public class TextNodeListEncoder extends XMLSerializer{
-
-    private final Element root;
-    public TextNodeListEncoder(String listName) {
-    	root=new Element(listName);
-    }   
-                    
-    public void add(String nodename, String nodetext) {
-    	final Element el=new Element(nodename);
-    	el.setText(nodetext);
-    	root.addContent(el);
-    }
-
-    public Element getElement() {
-        return root;
-    }
-    
-    public void addContent(final Element el){
-		root.addContent(el);
-	}
-
-}
diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XMLSerializer.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java
similarity index 70%
rename from src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XMLSerializer.java
rename to src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java
index 4abb0dc..a126811 100644
--- a/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XMLSerializer.java
+++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/utils/XmlElement.java
@@ -25,6 +25,7 @@
 
 package it.geosolutions.geoserver.rest.encoder.utils;
 
+
 import org.jdom.Element;
 import org.jdom.output.Format;
 import org.jdom.output.XMLOutputter;
@@ -34,24 +35,45 @@ import org.jdom.output.XMLOutputter;
  * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
  *
  */
-public abstract class XMLSerializer {
+public abstract class XmlElement extends Element {
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	
 	private final static XMLOutputter OUTPUTTER = new XMLOutputter(Format.getCompactFormat());
 	
-	public XMLSerializer(){}
-
-	public abstract Element getElement();
+	public XmlElement(final String name){
+		super(name);
+	}
 	
-	public abstract void addContent(final Element el);
+	private XmlElement(){};
+	
+	public boolean isEmpty() {
+        return getChildren().isEmpty();
+    }
+	
+	public boolean remove(final Element el){
+		return ElementUtils.remove(this,el);
+	}
+	
+	public Element contains(final Element el){
+		return ElementUtils.contains(this,el);
+	}
+	
+	public Element contains(final String key, final String val){
+		return ElementUtils.contains(this,key,val);
+	}
+	
+	public Element contains(final String key){
+		return ElementUtils.contains(this,key);
+	}
 	
 	/**
      * @return an xml String 
      */
     @Override
     public String toString() {
-    	final Element root= getElement();
-    	if (root!=null)
-    		return OUTPUTTER.outputString(root);
-    	else
-    		return "";
+		return OUTPUTTER.outputString(this);
     }
 }
diff --git a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPostgisDatastoreTest.java b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPostgisDatastoreTest.java
index 2930d6c..eff5c46 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPostgisDatastoreTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTPostgisDatastoreTest.java
@@ -94,18 +94,18 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
 
         GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder();
         datastoreEncoder.defaultInit();
-        datastoreEncoder.setName(datastoreName);
-        datastoreEncoder.setDescription(description);
-        datastoreEncoder.setNamespace(dsNamespace);
-        datastoreEncoder.setHost(pgHost);
-        datastoreEncoder.setPort(pgPort);
-        datastoreEncoder.setDatabase(pgDatabase);
-        datastoreEncoder.setSchema(pgSchema);
-        datastoreEncoder.setUser(pgUser);
-        datastoreEncoder.setPassword(pgPassword);
-        datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys);
-        datastoreEncoder.setValidateConnections(validateConnections);
-        datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
+        datastoreEncoder.addName(datastoreName);
+        datastoreEncoder.addDescription(description);
+        datastoreEncoder.addNamespace(dsNamespace);
+        datastoreEncoder.addHost(pgHost);
+        datastoreEncoder.addPort(pgPort);
+        datastoreEncoder.addDatabase(pgDatabase);
+        datastoreEncoder.addSchema(pgSchema);
+        datastoreEncoder.addUser(pgUser);
+        datastoreEncoder.addPassword(pgPassword);
+        datastoreEncoder.addExposePrimaryKeys(exposePrimaryKeys);
+        datastoreEncoder.addValidateConnections(validateConnections);
+        datastoreEncoder.addPrimaryKeyMetadataTable(primaryKeyMetadataTable);
 
         // creation test
         boolean created = publisher.createPostGISDatastore(wsName, datastoreEncoder);
diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/GSCoverageEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java
similarity index 60%
rename from src/test/java/it/geosolutions/geoserver/rest/encoder/utils/GSCoverageEncoderTest.java
rename to src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java
index bdb0913..826680d 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/GSCoverageEncoderTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java
@@ -17,7 +17,7 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
-package it.geosolutions.geoserver.rest.encoder.utils;
+package it.geosolutions.geoserver.rest.encoder.coverage;
 
 import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
 import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
@@ -25,11 +25,12 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Pr
 import junit.framework.TestCase;
 
 import org.apache.log4j.Logger;
+import org.jdom.Element;
+import org.junit.Assert;
 import org.junit.Test;
 
 /**
  *
- * @author ETj (etj at geo-solutions.it)
  * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
  */
 public class GSCoverageEncoderTest extends TestCase {
@@ -44,21 +45,40 @@ public class GSCoverageEncoderTest extends TestCase {
     
     @Test
     public void testAll() {
-    	GSCoverageEncoder encoder=new GSCoverageEncoder();
+    	final GSCoverageEncoder encoder=new GSCoverageEncoder();
     	encoder.addKeyword("KEYWORD_1");
     	encoder.addKeyword("KEYWORD_2");
     	encoder.addKeyword("...");
     	encoder.addKeyword("KEYWORD_N");
-    	GSDimensionInfoEncoder dim=new GSDimensionInfoEncoder(true);
-    	dim.setPresentation(Presentation.CONTINUOUS_INTERVAL);
+    	final GSDimensionInfoEncoder dim=new GSDimensionInfoEncoder(true);
+    	dim.addPresentation(Presentation.CONTINUOUS_INTERVAL);
     	encoder.addMetadata("time", dim);
-    	GSDimensionInfoEncoder dim2=new GSDimensionInfoEncoder(true);
-    	dim2.setPresentation(Presentation.LIST);
+    	final GSDimensionInfoEncoder dim2=new GSDimensionInfoEncoder(true);
+    	dim2.addPresentation(Presentation.LIST);
     	encoder.addMetadata("elev", dim2);
-    	encoder.setAllowMultithreading(true);
-        
+
     	LOGGER.info(encoder.toString());
-// TODO TESTS
+    	
+    	final Element el=encoder.contains("metadata");
+    	Assert.assertNotNull(el);
+    	LOGGER.info("contains_key:"+el.toString());
+    	
+    	final Element el2=encoder.contains("presentation");
+    	Assert.assertNotNull(el2);
+    	LOGGER.info("contains_key:"+el2.toString());
+    	
+    	final Element el3=encoder.contains(encoder.contains("metadata"));
+    	Assert.assertNotNull(el3);
+    	LOGGER.info("contains_by_node:"+el3.toString());
+    	
+    	final boolean removed=encoder.remove(el3);
+    	LOGGER.info("remove:"+removed);
+    	Assert.assertTrue(removed);
+    	
+    	final Element el4=encoder.contains("metadata");
+    	Assert.assertNull(el4);
+    	if (el4==null)
+    		LOGGER.info("REMOVED");
     	
     	
     }
diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoderTest.java
new file mode 100644
index 0000000..2a3ce96
--- /dev/null
+++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSImageMosaicEncoderTest.java
@@ -0,0 +1,86 @@
+/*
+ *  Copyright (C) 2007 - 2011 GeoSolutions S.A.S.
+ *  http://www.geo-solutions.it
+ * 
+ *  GPLv3 + Classpath exception
+ * 
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ * 
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ * 
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see .
+ */
+package it.geosolutions.geoserver.rest.encoder.coverage;
+
+import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
+import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Presentation;
+import junit.framework.TestCase;
+
+import org.apache.log4j.Logger;
+import org.jdom.Element;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
+ */
+public class GSImageMosaicEncoderTest extends TestCase {
+
+    public GSImageMosaicEncoderTest() {
+    }
+
+    /**
+     * Default logger
+     */
+    protected final static Logger LOGGER = Logger.getLogger(GSImageMosaicEncoderTest.class);
+    
+    @Test
+    public void testAll() {
+    	final GSImageMosaicEncoder encoder=new GSImageMosaicEncoder();
+    	encoder.addKeyword("KEYWORD_1");
+    	encoder.addKeyword("KEYWORD_2");
+    	encoder.addKeyword("...");
+    	encoder.addKeyword("KEYWORD_N");
+    	final GSDimensionInfoEncoder dim=new GSDimensionInfoEncoder(true);
+    	dim.addPresentation(Presentation.CONTINUOUS_INTERVAL);
+    	encoder.addMetadata("time", dim);
+    	final GSDimensionInfoEncoder dim2=new GSDimensionInfoEncoder(true);
+    	dim2.addPresentation(Presentation.LIST);
+    	encoder.addMetadata("elev", dim2);
+    	encoder.addAllowMultithreading(true);
+    	encoder.addSUGGESTED_TILE_SIZE("512,512");
+
+    	LOGGER.info(encoder.toString());
+    	
+    	final Element el=encoder.contains("metadata");
+    	Assert.assertNotNull(el);
+    	LOGGER.info("contains_key:"+el.toString());
+    	
+    	final Element el2=encoder.contains("presentation");
+    	Assert.assertNotNull(el2);
+    	LOGGER.info("contains_key:"+el2.toString());
+    	
+    	final Element el3=encoder.contains(encoder.contains("metadata"));
+    	Assert.assertNotNull(el3);
+    	LOGGER.info("contains_by_node:"+el3.toString());
+    	
+    	final boolean removed=encoder.remove(el3);
+    	LOGGER.info("remove:"+removed);
+    	Assert.assertTrue(removed);
+    	
+    	final Element el4=encoder.contains("metadata");
+    	Assert.assertNull(el4);
+    	if (el4==null)
+    		LOGGER.info("REMOVED");
+    	
+    	
+    }
+}
diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/GSFeatureEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java
similarity index 91%
rename from src/test/java/it/geosolutions/geoserver/rest/encoder/utils/GSFeatureEncoderTest.java
rename to src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java
index fcce197..00e6360 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/GSFeatureEncoderTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java
@@ -17,11 +17,11 @@
  *  You should have received a copy of the GNU General Public License
  *  along with this program.  If not, see .
  */
-package it.geosolutions.geoserver.rest.encoder.utils;
+package it.geosolutions.geoserver.rest.encoder.feature;
 
 import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureDimensionInfoEncoder;
 import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
-import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.DiscretePresentation;
+import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.PresentationDiscrete;
 
 import java.math.BigDecimal;
 
@@ -48,7 +48,7 @@ public class GSFeatureEncoderTest extends TestCase {
 		feature.addKeyword("KEYWORD_N");
 		GSFeatureDimensionInfoEncoder dim2 = new GSFeatureDimensionInfoEncoder(
 				"ELE");
-		dim2.setPresentation(DiscretePresentation.DISCRETE_INTERVAL,
+		dim2.addPresentation(PresentationDiscrete.DISCRETE_INTERVAL,
 				BigDecimal.valueOf(10));
 		feature.addMetadata("elevation", dim2);
 
diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java
index eb49356..98437a0 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java
@@ -36,13 +36,13 @@ public class EntryKeyListEncoderTest extends TestCase {
 
     @Test
     public void testAll() {
-        EntryKeyListEncoder ekle = new EntryKeyListEncoder("EKL");
+        NestedElementEncoder ekle = new NestedElementEncoder("EKL");
         ekle.add("k1", "v1");
         ekle.add("k2", "v2");
         ekle.add("k3", "v3");
 
         Element root = new Element("root");
-        root.addContent(ekle.getElement());
+        root.addContent(ekle);
 
         assertEquals(1, root.getChildren().size());
         assertNotNull(root.getChild("EKL"));