From e04dd7428e33111e6402b611bc8fa9ee36c50f67 Mon Sep 17 00:00:00 2001 From: andypower Date: Thu, 26 Mar 2015 16:39:02 +0100 Subject: [PATCH] Alternative to GEOS-6568 (https://jira.codehaus.org/browse/GEOS-6568) Using raw format to update correctly an SLD file v. 1.1.0 via REST API --- .../rest/GeoServerRESTPublisher.java | 15 ++++++++ .../manager/GeoServerRESTStyleManager.java | 37 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 2b547fc..278bb22 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -369,6 +369,21 @@ public class GeoServerRESTPublisher { return styleManager.publishStyle(sldFile, name, raw); } + /** + * Update a Style. + * + * @param sldFile the File containing the SLD document. + * @param name the Style name. + * @param raw the raw format + * + * @return true if the operation completed successfully. + * @throws IllegalArgumentException if the sldFile file or name are null or name is empty. + */ + public boolean updateStyle(final File sldFile, final String name, boolean raw) + throws IllegalArgumentException { + return styleManager.updateStyle(sldFile, name, raw); + } + /** * Update a Style. * diff --git a/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java b/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java index 8a75e9d..7f68fa0 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java +++ b/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java @@ -286,7 +286,7 @@ public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager { * 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&raw=raw} + * http://$GSIP:$GSPORT/$SERVLET/rest/styles?name=$name&raw=$raw} */ String sUrl = buildPostUrl(null, name); sUrl += "&raw=" + raw; @@ -298,6 +298,41 @@ public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager { String result = HTTPUtils.post(sUrl, sldFile, contentType, gsuser, gspass); return result != null; } + + /** + * Update a Style. + * + * @param sldFile the File containing the SLD document. + * @param name the Style name. + * @param raw the raw format + * + * @return true if the operation completed successfully. + * @throws IllegalArgumentException if the sldFile file or name are null or name is empty. + */ + public boolean updateStyle(final File sldFile, final String name, final boolean raw) + 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=$name&raw=$raw} + */ + 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"); + } + + String sUrl = buildUrl(null, name, null); + sUrl += "&raw=" + raw; + LOGGER.debug("POSTing new style " + name + " to " + sUrl); + String contentType = GeoServerRESTPublisher.Format.SLD.getContentType(); + if(!this.checkSLD10Version(sldFile)){ + contentType = GeoServerRESTPublisher.Format.SLD_1_1_0.getContentType(); + } + String result = HTTPUtils.put(sUrl, sldFile, contentType, gsuser, gspass); + return result != null; + } /** * Update a Style.