From 21fdc7fed53f1ca495b1394f3ecbd1182dd3b65b Mon Sep 17 00:00:00 2001 From: ccancellieri Date: Tue, 25 Sep 2012 13:39:40 +0200 Subject: [PATCH] Selective reload improvement fix to close issue 43 --- .../rest/GeoServerRESTPublisher.java | 3745 ++++++++--------- .../geoserver/rest/GeoserverRESTTest.java | 2 +- .../publisher/GeoserverRESTGeoTiffTest.java | 36 +- .../publisher/GeoserverRESTPublisherTest.java | 3 +- .../publisher/GeoserverRESTShapeTest.java | 25 +- 5 files changed, 1747 insertions(+), 2064 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 3635208..ae9fa57 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -30,12 +30,13 @@ import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; import it.geosolutions.geoserver.rest.encoder.GSBackupEncoder; import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.GSNamespaceEncoder; +import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder; import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder; -import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder; +import it.geosolutions.geoserver.rest.manager.GeoServerRESTDatastoreManager; import java.io.File; import java.io.FileNotFoundException; @@ -51,8 +52,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Connect to a GeoServer instance to publish or modify its contents via REST - * API. + * Connect to a GeoServer instance to publish or modify its contents via REST API. *

* There are no modifiable instance fields, so all the calls are thread-safe. * @@ -63,45 +63,36 @@ public class GeoServerRESTPublisher { public static final String DEFAULT_CRS = "EPSG:4326"; - /** The logger for this class */ - private static final Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTPublisher.class); - - /** - * GeoServer instance base URL. E.g.: - * http://localhost:8080/geoserver. - */ - private final String restURL; - - /** - * GeoServer instance privileged username, with read & write permission on - * REST API - */ - private final String gsuser; - - /** - * GeoServer instance password for privileged username with r&w permission - * on REST API - */ - private final String gspass; + /** The logger for this class */ + private static final Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTPublisher.class); /** - * Creates a GeoServerRESTPublisher to connect against a GeoServer - * instance with the given URL and user credentials. - * - * @param restURL - * the base GeoServer URL (e.g.: - * http://localhost:8080/geoserver) - * @param username - * auth credential - * @param password - * auth credential + * GeoServer instance base URL. E.g.: http://localhost:8080/geoserver. */ - public GeoServerRESTPublisher(String restURL, String username, - String password) { - this.restURL = HTTPUtils.decurtSlash(restURL); - this.gsuser = username; - this.gspass = password; - } + private final String restURL; + + /** + * GeoServer instance privileged username, with read & write permission on REST API + */ + private final String gsuser; + + /** + * GeoServer instance password for privileged username with r&w permission on REST API + */ + private final String gspass; + + /** + * Creates a GeoServerRESTPublisher to connect against a GeoServer instance with the given URL and user credentials. + * + * @param restURL the base GeoServer URL (e.g.: http://localhost:8080/geoserver) + * @param username auth credential + * @param password auth credential + */ + public GeoServerRESTPublisher(String restURL, String username, String password) { + this.restURL = HTTPUtils.decurtSlash(restURL); + this.gsuser = username; + this.gspass = password; + } // ========================================================================== // === BACKUP and RESTORE @@ -110,62 +101,45 @@ public class GeoServerRESTPublisher { /** * Issues a GeoServer BACKUP. *

- * Won't include data, cached tiles, or logs. Use - * {@link #backup(String, boolean, boolean, boolean)} to control these - * parameters. + * Won't include data, cached tiles, or logs. Use {@link #backup(String, boolean, boolean, boolean)} to control these parameters. * - * @param backupDir - * the target Backup Dir String. + * @param backupDir the target Backup Dir String. * * @return id of the backup. - * @throws IllegalArgumentException - * if the backupDir is null or empty + * @throws IllegalArgumentException if the backupDir is null or empty */ - public String backup(final String backupDir) throws IllegalArgumentException - { - /* - * This is the equivalent call with cUrl: - * - * {@code curl -u admin:geoserver -XPOST \ - * -H 'Content-type: text/xml' \ - * --data "<task><path>${BACKUP_DATADIR}</path></task>" \ - * ${restURL}/rest/bkprst/backup} - */ + public String backup(final String backupDir) throws IllegalArgumentException { + /* + * This is the equivalent call with cUrl: + * + * {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: text/xml' \ --data + * "<task><path>${BACKUP_DATADIR}</path></task>" \ ${restURL}/rest/bkprst/backup} + */ return backup(backupDir, false, false, false); } /** * Issues a GeoServer BACKUP. * - * @param backupDir - * the target Backup Dir String. - * @param includedata - * whether or not include the data dir Boolean. - * @param includegwc - * whether or not include the geowebcache dir Boolean. - * @param includelog - * whether or not include the log dir Boolean. + * @param backupDir the target Backup Dir String. + * @param includedata whether or not include the data dir Boolean. + * @param includegwc whether or not include the geowebcache dir Boolean. + * @param includelog whether or not include the log dir Boolean. * * @return id of the backup. - * @throws IllegalArgumentException - * if the backupDir is null or empty. + * @throws IllegalArgumentException if the backupDir is null or empty. */ - public String backup(final String backupDir, - final boolean includedata, - final boolean includegwc, - final boolean includelog) throws IllegalArgumentException - { - /* This is the equivalent call with cUrl: - * - * {@code curl -u admin:geoserver -XPOST \ - * -H 'Content-type: text/xml' \ - * --data "<task><path>${BACKUP_DATADIR}</path><includedata>${includedata}</includedata><includegwc>${includegwc}</includegwc><includelog>${includelog}</includelog></task>" \ - * ${restURL}/rest/bkprst/backup} - */ - if ((backupDir == null) || backupDir.isEmpty()) - { - throw new IllegalArgumentException( - "The backup_dir must not be null or empty"); + public String backup(final String backupDir, final boolean includedata, + final boolean includegwc, final boolean includelog) throws IllegalArgumentException { + /* + * This is the equivalent call with cUrl: + * + * {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: text/xml' \ --data + * "<task><path>${BACKUP_DATADIR}</path><includedata>${includedata}</includedata><includegwc>${includegwc}</includegwc><includelog>${includelog}</includelog></task>" + * \ ${restURL}/rest/bkprst/backup} + */ + if ((backupDir == null) || backupDir.isEmpty()) { + throw new IllegalArgumentException("The backup_dir must not be null or empty"); } StringBuilder bkpUrl = new StringBuilder(restURL); @@ -175,8 +149,8 @@ public class GeoServerRESTPublisher { bkpenc.setIncludeData(includedata); bkpenc.setIncludeGwc(includegwc); bkpenc.setIncludeLog(includelog); - final String result = HTTPUtils.post(bkpUrl.toString(), bkpenc.toString(), - "text/xml", gsuser, gspass); + final String result = HTTPUtils.post(bkpUrl.toString(), bkpenc.toString(), "text/xml", + gsuser, gspass); return result; } @@ -184,395 +158,371 @@ public class GeoServerRESTPublisher { /** * Issues a GeoServer RESTORE. * - * @param backupDir - * the source backup dir. + * @param backupDir the source backup dir. * * @return id of the backup. - * @throws IllegalArgumentException - * if the backupDir is null or empty + * @throws IllegalArgumentException if the backupDir is null or empty */ - public String restore(final String backupDir) throws IllegalArgumentException - { + public String restore(final String backupDir) throws IllegalArgumentException { /* * This is the equivalent call with cUrl: - * - * {@code curl -u admin:geoserver -XPOST \ - * -H 'Content-type: text/xml' \ - * --data "<task><path>${BACKUP_DATADIR}</path></task>" \ - * ${restURL}/rest/bkprst/restore} + * + * {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: text/xml' \ --data + * "<task><path>${BACKUP_DATADIR}</path></task>" \ ${restURL}/rest/bkprst/restore} */ - if ((backupDir == null) || backupDir.isEmpty()) - { - throw new IllegalArgumentException( - "The backup_dir must not be null or empty"); + if ((backupDir == null) || backupDir.isEmpty()) { + throw new IllegalArgumentException("The backup_dir must not be null or empty"); } StringBuilder bkpUrl = new StringBuilder(restURL); bkpUrl.append("/rest/bkprst/restore"); final GSBackupEncoder bkpenc = new GSBackupEncoder(backupDir); - - final String result = HTTPUtils.post(bkpUrl.toString(), bkpenc.toString(), - "text/xml", gsuser, gspass); + + final String result = HTTPUtils.post(bkpUrl.toString(), bkpenc.toString(), "text/xml", + gsuser, gspass); return result; } - // ========================================================================== - // === WORKSPACES - // ========================================================================== + // ========================================================================== + // === WORKSPACES + // ========================================================================== /** * Create a new Workspace. *

- * GeoServer will automatically create an associated Namespace with the URI - * being "http://{workspaceName}". To specify a custom Namespace URI, use + * GeoServer will automatically create an associated Namespace with the URI being "http://{workspaceName}". To specify a custom Namespace URI, use * {@link #createWorkspace(String, URI)}. * - * @param workspace - * The name of the new workspace. + * @param workspace The name of the new workspace. * * @return true if the workspace was created. */ - public boolean createWorkspace(final String workspace) { - /* This is the equivalent call with cUrl: - * - * {@code curl -u admin:geoserver -XPOST \ - * -H 'Content-type: text/xml' \ - * -d "$WORKSPACE" \ - * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces - * } - */ - final String sUrl = restURL + "/rest/workspaces"; - final GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace); - final String wsxml = wsenc.toString(); - final String result = HTTPUtils.postXml(sUrl, wsxml, gsuser, gspass); - return result != null; - } - + public boolean createWorkspace(final String workspace) { + /* + * This is the equivalent call with cUrl: + * + * {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: text/xml' \ -d "$WORKSPACE" \ + * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces } + */ + final String sUrl = restURL + "/rest/workspaces"; + final GSWorkspaceEncoder wsenc = new GSWorkspaceEncoder(workspace); + final String wsxml = wsenc.toString(); + final String result = HTTPUtils.postXml(sUrl, wsxml, gsuser, gspass); + return result != null; + } + /** * Create both a workspace and its associated namespace. *

* Note that this method is equivalent to {@link #createNamespace}. * - * @param name - * Name for the new workspace, which will be also its associated - * namespace prefix. - * @param uri - * Namespace URI. Cannot be empty. - * @return true if the Workspace and its associated namespace were - * successfully created. + * @param name Name for the new workspace, which will be also its associated namespace prefix. + * @param uri Namespace URI. Cannot be empty. + * @return true if the Workspace and its associated namespace were successfully created. */ - public boolean createWorkspace(final String name, final URI uri) { - // This is really an alias to createNamespace, as GeoServer - // will automatically create the associated workspace as well. - return createNamespace(name, uri); - } - - // ========================================================================== - // === NAMESPACES - // ========================================================================== + public boolean createWorkspace(final String name, final URI uri) { + // This is really an alias to createNamespace, as GeoServer + // will automatically create the associated workspace as well. + return createNamespace(name, uri); + } + + // ========================================================================== + // === NAMESPACES + // ========================================================================== /** - * Create a new Namespace. GeoServer will automatically create the - * corresponding Workspace. + * Create a new Namespace. GeoServer will automatically create the corresponding Workspace. * - * Prefix and URI are mandatory and cannot be empty. If a Namespace with the - * given prefix already exists, it won't be created. + * Prefix and URI are mandatory and cannot be empty. If a Namespace with the given prefix already exists, it won't be created. * - * @param prefix - * The name of the new Namespace. - * @param uri - * The URI of the new Namespace. + * @param prefix The name of the new Namespace. + * @param uri The URI of the new Namespace. * * @return true if the Namespace was successfully created. - * @see - * GeoServer Documentation + * @see GeoServer Documentation */ - public boolean createNamespace(final String prefix, final URI uri) { - final String sUrl = restURL + "/rest/namespaces"; - final GSNamespaceEncoder nsenc = new GSNamespaceEncoder(prefix, uri); - final String nsxml = nsenc.toString(); - final String result = HTTPUtils.postXml(sUrl, nsxml, gsuser, gspass); - return result != null; - } - + public boolean createNamespace(final String prefix, final URI uri) { + final String sUrl = restURL + "/rest/namespaces"; + final GSNamespaceEncoder nsenc = new GSNamespaceEncoder(prefix, uri); + final String nsxml = nsenc.toString(); + final String result = HTTPUtils.postXml(sUrl, nsxml, gsuser, gspass); + return result != null; + } + /** * Update a Namespace URI. * - * Prefix and URI are mandatory and cannot be empty. A Namespace with the - * given prefix should exist. + * Prefix and URI are mandatory and cannot be empty. A Namespace with the given prefix should exist. * - * @param prefix - * The prefix of an existing Namespace. - * @param uri - * The new URI. + * @param prefix The prefix of an existing Namespace. + * @param uri The new URI. * * @return true if the Namespace was successfully updated. */ - public boolean updateNamespace(final String prefix, final URI uri) { - final String sUrl = restURL + "/rest/namespaces/"+ encode(prefix); - final GSNamespaceEncoder nsenc = new GSNamespaceEncoder(prefix, uri); - final String nsxml = nsenc.toString(); - final String result = HTTPUtils.put(sUrl, nsxml, "application/xml", gsuser, gspass); - return result != null; - } - + public boolean updateNamespace(final String prefix, final URI uri) { + final String sUrl = restURL + "/rest/namespaces/" + encode(prefix); + final GSNamespaceEncoder nsenc = new GSNamespaceEncoder(prefix, uri); + final String nsxml = nsenc.toString(); + final String result = HTTPUtils.put(sUrl, nsxml, "application/xml", gsuser, gspass); + return result != null; + } + /** - * Remove a given Namespace. It will remove the associated Workspace as - * well. + * Remove a given Namespace. It will remove the associated Workspace as well. * - * @param prefix - * The Namespace prefix - * @param recurse - * The recurse parameter is used to recursively delete all - * resources contained in the workspace associated with this - * Namespace. This includes data stores, coverage stores, feature - * types, etc... Allowable values for this parameter are - * true or false. The default (safer) value is - * false. + * @param prefix The Namespace prefix + * @param recurse The recurse parameter is used to recursively delete all resources contained in the workspace associated with this Namespace. + * This includes data stores, coverage stores, feature types, etc... Allowable values for this parameter are true or false. + * The default (safer) value is false. * * @return true if the Namespace was successfully removed. */ - public boolean removeNamespace(final String prefix, boolean recurse) { - // Hack: We are instead calling removeWorkspace, as DELETE on - // a namespace will leave associated workspace in an inconsistent - // state. See https://jira.codehaus.org/browse/GEOS-5075 - // TODO switch to namespace when GEOS-5075 is solved - return removeWorkspace(prefix, recurse); - } + public boolean removeNamespace(final String prefix, boolean recurse) { + // Hack: We are instead calling removeWorkspace, as DELETE on + // a namespace will leave associated workspace in an inconsistent + // state. See https://jira.codehaus.org/browse/GEOS-5075 + // TODO switch to namespace when GEOS-5075 is solved + return removeWorkspace(prefix, recurse); + } - // ========================================================================== - // === STYLES - // ========================================================================== + // ========================================================================== + // === STYLES + // ========================================================================== /** * Store and publish a Style. * - * @param sldBody - * the full SLD document as a String. + * @param sldBody the full SLD document as a String. * * @return true if the operation completed successfully. */ - public boolean publishStyle(String sldBody) { - /* This is the equivalent call with cUrl: - * - * {@code curl -u admin:geoserver -XPOST \ - * -H 'Content-type: application/vnd.ogc.sld+xml' \ - * -d @$FULLSLD \ - * http://$GSIP:$GSPORT/$SERVLET/rest/styles} - */ - try { - return publishStyle(sldBody, null); - } catch (IllegalArgumentException e) { - if (LOGGER.isErrorEnabled()) { - LOGGER.error(e.getLocalizedMessage(), e); - } - } - return false; - } + public boolean publishStyle(String sldBody) { + /* + * This is the equivalent call with cUrl: + * + * {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \ + * http://$GSIP:$GSPORT/$SERVLET/rest/styles} + */ + try { + return publishStyle(sldBody, null); + } catch (IllegalArgumentException e) { + if (LOGGER.isErrorEnabled()) { + LOGGER.error(e.getLocalizedMessage(), e); + } + } + return false; + } /** * Store and publish a Style, assigning it a name. * - * @param sldBody - * the full SLD document as a String. - * @param name - * the Style name. + * @param sldBody the full SLD document as a String. + * @param name the Style name. * * @return true if the operation completed successfully. - * @throws IllegalArgumentException - * if the style body is null or empty. + * @throws IllegalArgumentException if the style body is null or empty. */ - public boolean publishStyle(final String sldBody, final String name) - throws IllegalArgumentException { - /* - * This is the equivalent call with cUrl: + public boolean publishStyle(final String sldBody, final String name) + throws IllegalArgumentException { + /* + * This is the equivalent call with cUrl: * - * {@code curl -u admin:geoserver -XPOST \ - * -H 'Content-type: application/vnd.ogc.sld+xml' \ - * -d @$FULLSLD \ - * http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=name} - */ - if (sldBody == null || sldBody.isEmpty()) { - throw new IllegalArgumentException( - "The style body may not be null or empty"); - } - StringBuilder sUrl = new StringBuilder(restURL); - sUrl.append("/rest/styles"); - if (name != null && !name.isEmpty()) { - sUrl.append("?name=").append(name); - } - final String result = HTTPUtils.post(sUrl.toString(), sldBody, - "application/vnd.ogc.sld+xml", gsuser, gspass); - return result != null; - } + * {@code curl -u admin:geoserver -XPOST \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \ + * http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=name} + */ + if (sldBody == null || sldBody.isEmpty()) { + throw new IllegalArgumentException("The style body may not be null or empty"); + } + StringBuilder sUrl = new StringBuilder(restURL); + sUrl.append("/rest/styles"); + if (name != null && !name.isEmpty()) { + sUrl.append("?name=").append(name); + } + final String result = HTTPUtils.post(sUrl.toString(), sldBody, + "application/vnd.ogc.sld+xml", gsuser, gspass); + return result != null; + } - /** - * Store and publish a Style. - * - * @param sldFile the File containing the SLD document. - * - * @return true if the operation completed successfully. - */ - public boolean publishStyle(File sldFile) { - return publishStyle(sldFile, null); - } + /** + * Store and publish a Style. + * + * @param sldFile the File containing the SLD document. + * + * @return true if the operation completed successfully. + */ + public boolean publishStyle(File sldFile) { + return publishStyle(sldFile, null); + } /** * Store and publish a Style, assigning it a name. * - * @param sldFile - * the File containing the SLD document. - * @param name - * the Style name. + * @param sldFile the File containing the SLD document. + * @param name the Style name. * * @return true if the operation completed successfully. */ - public boolean publishStyle(File sldFile, String name) { - String sUrl = restURL + "/rest/styles"; - if (name != null && !name.isEmpty()) { - sUrl += "?name=" + encode(name); - } - LOGGER.debug("POSTing new style " + name + " to " + sUrl); - String result = HTTPUtils.post(sUrl, sldFile, - "application/vnd.ogc.sld+xml", gsuser, gspass); - return result != null; - } + public boolean publishStyle(File sldFile, String name) { + String sUrl = restURL + "/rest/styles"; + if (name != null && !name.isEmpty()) { + sUrl += "?name=" + encode(name); + } + LOGGER.debug("POSTing new style " + name + " to " + sUrl); + String result = HTTPUtils + .post(sUrl, sldFile, "application/vnd.ogc.sld+xml", gsuser, gspass); + return result != null; + } /** * Update a Style. * - * @param sldBody - * the new SLD document as a String. - * @param name - * the Style name to update. + * @param sldBody the new SLD document as a String. + * @param name the Style name to update. * * @return true if the operation completed successfully. - * @throws IllegalArgumentException - * if the style body or name are null or empty. + * @throws IllegalArgumentException if the style body or name are null or empty. */ - public boolean updateStyle(final String sldBody, final String name) - throws IllegalArgumentException { - /* - * This is the equivalent call with cUrl: + public boolean updateStyle(final String sldBody, final String name) + throws IllegalArgumentException { + /* + * This is the equivalent call with cUrl: * - * {@code curl -u admin:geoserver -XPUT \ - * -H 'Content-type: application/vnd.ogc.sld+xml' \ - * -d @$FULLSLD \ - * http://$GSIP:$GSPORT/$SERVLET/rest/styles/$NAME} - */ - if (sldBody == null || sldBody.isEmpty()) { - throw new IllegalArgumentException( - "The style body may not be null or empty"); - } else if (name == null || name.isEmpty()) { - throw new IllegalArgumentException( - "The style name may not be null or empty"); - } + * {@code curl -u admin:geoserver -XPUT \ -H 'Content-type: application/vnd.ogc.sld+xml' \ -d @$FULLSLD \ + * http://$GSIP:$GSPORT/$SERVLET/rest/styles/$NAME} + */ + if (sldBody == null || sldBody.isEmpty()) { + throw new IllegalArgumentException("The style body may not be null or empty"); + } else if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("The style name may not be null or empty"); + } - final StringBuilder sUrl = new StringBuilder(restURL); - sUrl.append("/rest/styles/").append(encode(name)); + final StringBuilder sUrl = new StringBuilder(restURL); + sUrl.append("/rest/styles/").append(encode(name)); - final String result = HTTPUtils.put(sUrl.toString(), sldBody, - "application/vnd.ogc.sld+xml", gsuser, gspass); - return result != null; - } + final String result = HTTPUtils.put(sUrl.toString(), sldBody, + "application/vnd.ogc.sld+xml", gsuser, gspass); + return result != null; + } /** * Update a Style. * - * @param sldFile - * the File containing the SLD document. - * @param name - * the Style name. + * @param sldFile the File containing the SLD document. + * @param name the Style name. * * @return true if the operation completed successfully. - * @throws IllegalArgumentException - * if the sldFile file or name are null or name is empty. + * @throws IllegalArgumentException if the sldFile file or name are null or name is empty. */ - public boolean updateStyle(final File sldFile, final String name) - throws IllegalArgumentException { + public boolean updateStyle(final File sldFile, final String name) + throws IllegalArgumentException { - if (sldFile == null) { - throw new IllegalArgumentException( - "Unable to updateStyle using a null parameter file"); - } else if (name == null || name.isEmpty()) { - throw new IllegalArgumentException( - "The style name may not be null or empty"); - } + if (sldFile == null) { + throw new IllegalArgumentException("Unable to updateStyle using a null parameter file"); + } else if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("The style name may not be null or empty"); + } - final StringBuilder sUrl = new StringBuilder(restURL); - sUrl.append("/rest/styles/").append(encode(name)); + final StringBuilder sUrl = new StringBuilder(restURL); + sUrl.append("/rest/styles/").append(encode(name)); - final String result = HTTPUtils.put(sUrl.toString(), sldFile, - "application/vnd.ogc.sld+xml", gsuser, gspass); - return result != null; + final String result = HTTPUtils.put(sUrl.toString(), sldFile, + "application/vnd.ogc.sld+xml", gsuser, gspass); + return result != null; - } + } /** * Remove a Style. *

- * The Style will be unpublished, and (optionally) the SLD file will be - * removed. + * The Style will be unpublished, and (optionally) the SLD file will be removed. * - * @param styleName - * the name of the Style to remove. - * @param purge - * remove the related SLD file from disk. + * @param styleName the name of the Style to remove. + * @param purge remove the related SLD file from disk. * * @return true if the operation completed successfully. - * @throws IllegalArgumentException - * if styleName is null or empty. + * @throws IllegalArgumentException if styleName is null or empty. */ - public boolean removeStyle(String styleName, final boolean purge) - throws IllegalArgumentException { - if (styleName == null || styleName.isEmpty()) - throw new IllegalArgumentException( - "Check styleName parameter, it may never be null or empty"); + public boolean removeStyle(String styleName, final boolean purge) + throws IllegalArgumentException { + if (styleName == null || styleName.isEmpty()) + throw new IllegalArgumentException( + "Check styleName parameter, it may never be null or empty"); - final StringBuffer sUrl = new StringBuffer(restURL); + final StringBuffer sUrl = new StringBuffer(restURL); - // check style name - // TODO may we whant to throw an exception instead of - // change style name? - styleName = styleName.replaceAll(":", "_"); - styleName = encode(styleName); + // check style name + // TODO may we whant to throw an exception instead of + // change style name? + styleName = styleName.replaceAll(":", "_"); + styleName = encode(styleName); - sUrl.append("/rest/styles/").append(styleName); - if (purge) { - sUrl.append("?purge=true"); - } + sUrl.append("/rest/styles/").append(styleName); + if (purge) { + sUrl.append("?purge=true"); + } - return HTTPUtils.delete(sUrl.toString(), gsuser, gspass); - } + return HTTPUtils.delete(sUrl.toString(), gsuser, gspass); + } - /** - * Remove a Style. - *

- * The Style will be unpublished and the related SLD file will be removed. - * - * @param styleName - * the name of the Style to remove. - * - * @return true if the operation completed successfully. - */ - public boolean removeStyle(String styleName) { - try { - return removeStyle(styleName, true); - } catch (IllegalArgumentException e) { - if (LOGGER.isErrorEnabled()) { - LOGGER.error(e.getLocalizedMessage(), e); - } - } - return false; - } + /** + * Remove a Style. + *

+ * The Style will be unpublished and the related SLD file will be removed. + * + * @param styleName the name of the Style to remove. + * + * @return true if the operation completed successfully. + */ + public boolean removeStyle(String styleName) { + try { + return removeStyle(styleName, true); + } catch (IllegalArgumentException e) { + if (LOGGER.isErrorEnabled()) { + LOGGER.error(e.getLocalizedMessage(), e); + } + } + return false; + } // ========================================================================== // === DATASTORE PUBLISHING // ========================================================================== + /** + * + * @author cancellieri + * @deprecated use {@link StoreType} + */ + public enum DataStoreType { + /** + * Raster based data sources. + */ + COVERAGESTORES, + /** + * Vector based data sources. Can be a file in the case of a Shapefile, a database connection in the case of PostGIS, or a server in the case + * of a remote Web Feature Service. + */ + DATASTORES; + + /** + * @deprecated use {@link StoreType#getTypeNameWithFormat(StoreType, Format)} + * @param type + * @return + */ + public static String getTypeName(StoreType type) { + return StoreType.getTypeNameWithFormat(type,Format.XML); + } + + /** + * @deprecated use {@link StoreType#toString()} + */ + public String toString() { + return this.name().toLowerCase(); + } + } + /** * DataStoreType definitions. *