From 75c0046c4cc6b930ccaa5858567cbb1fdbba0cde Mon Sep 17 00:00:00 2001 From: andypower Date: Tue, 31 Jan 2012 16:47:08 +0100 Subject: [PATCH] Added putStyle method to replace an existing style on Geo Server --- .../rest/GeoServerRESTPublisher.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 3a9f47a..b823604 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -208,6 +208,36 @@ public class GeoServerRESTPublisher { "application/vnd.ogc.sld+xml", gsuser, gspass); return result != null; } + + /** + * Replace an existing SLD. + *

+ * 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/$FULLSLD}
+     	* 
+ * + * @param sldBody, String sldName + * the SLD document as an XML String. + * + * @return true if the operation completed successfully. + */ + public boolean putStyle(final String sldBody, final String sldName) throws IllegalArgumentException { + if (sldBody == null || sldBody.isEmpty()){ + throw new IllegalArgumentException("The style body may not be null or empty"); + } else if (sldName != null && !sldName.isEmpty()){ + throw new IllegalArgumentException("The style name may not be null or empty"); + } + StringBuilder sUrl = new StringBuilder(restURL); + sUrl.append("/rest/styles/").append(sldName); + final String result = HTTPUtils.put(sUrl.toString(), sldBody, + "application/vnd.ogc.sld+xml", gsuser, gspass); + return result != null; + } /** * Remove a Style.