Class GeoServerRESTStyleManager
- java.lang.Object
-
- it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager
-
- it.geosolutions.geoserver.rest.manager.GeoServerRESTStyleManager
-
public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager
GeoServerRESTStyleManager class.
- Version:
- $Id: $
- Author:
- ETj (etj at geo-solutions.it)
-
-
Field Summary
-
Fields inherited from class it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager
gsBaseUrl, gspass, gsuser
-
-
Constructor Summary
Constructors Constructor Description GeoServerRESTStyleManager(java.net.URL restURL, java.lang.String username, java.lang.String password)Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringbuildPostUrl(java.lang.String workspace, java.lang.String name)Creates a URL for the given stylename with the name in querystringprotected java.lang.StringbuildUrl(java.lang.String workspace, java.lang.String name, java.lang.String ext)Creates a URL for the given stylename with the name in the REST pathprotected java.lang.StringbuildXmlUrl(java.lang.String workspace, java.lang.String name)buildXmlUrlbooleanexistsStyle(java.lang.String name)Check if a Style exists in the configured GeoServer instance.booleanexistsStyle(java.lang.String name, boolean quietOnNotFound)Check if a Style exists in the configured GeoServer instance.booleanexistsStyle(java.lang.String workspace, java.lang.String name)existsStylebooleanexistsStyle(java.lang.String workspace, java.lang.String name, boolean quietOnNotFound)existsStylejava.lang.StringgetSLD(java.lang.String styleName)Get the SLD body of a Style.java.lang.StringgetSLD(java.lang.String workspace, java.lang.String name)Get the SLD body of a Style.RESTStylegetStyle(java.lang.String name)getStyleRESTStylegetStyle(java.lang.String workspace, java.lang.String name)getStyleRESTStyleListgetStyles()Get summary info about all Styles.RESTStyleListgetStyles(java.lang.String workspace)Get summary info about Styles in a workspace.booleanpublishStyle(java.io.File sldFile)Store and publish a Style.booleanpublishStyle(java.io.File sldFile, java.lang.String name)Store and publish a Style, assigning it a name.booleanpublishStyle(java.io.File sldFile, java.lang.String name, boolean raw)Store and publish a Style, assigning it a name and choosing the raw format.booleanpublishStyle(java.lang.String sldBody)Store and publish a Style.booleanpublishStyle(java.lang.String sldBody, java.lang.String name)Store and publish a Style, assigning it a name.booleanpublishStyle(java.lang.String sldBody, java.lang.String name, boolean raw)Store and publish a Style, assigning it a name and choosing the raw format.booleanpublishStyleInWorkspace(java.lang.String workspace, java.io.File sldFile)Store and publish a Style.booleanpublishStyleInWorkspace(java.lang.String workspace, java.io.File sldFile, java.lang.String name)Store and publish a Style, assigning it a name.booleanpublishStyleInWorkspace(java.lang.String workspace, java.lang.String sldBody)Store and publish a Style.booleanpublishStyleInWorkspace(java.lang.String workspace, java.lang.String sldBody, java.lang.String name)Store and publish a Style, assigning it a name.booleanpublishStyleZippedInWorkspace(java.lang.String workspace, java.io.File zipFile, java.lang.String name)Store and publish a Style, assigning it a name.booleanremoveStyle(java.lang.String styleName)Remove a Style.booleanremoveStyle(java.lang.String styleName, boolean purge)Remove a Style.booleanremoveStyleInWorkspace(java.lang.String workspace, java.lang.String styleName)Remove a Style.booleanremoveStyleInWorkspace(java.lang.String workspace, java.lang.String styleName, boolean purge)Remove a Style.booleanupdateStyle(java.io.File sldFile, java.lang.String name)Update a Style.booleanupdateStyle(java.io.File sldFile, java.lang.String name, boolean raw)Update a Style.booleanupdateStyle(java.lang.String sldBody, java.lang.String name)Update a Style.booleanupdateStyle(java.lang.String sldBody, java.lang.String name, boolean raw)Update a Style.booleanupdateStyleInWorkspace(java.lang.String workspace, GSStyleEncoder encoder, java.lang.String name)Update a Style.booleanupdateStyleInWorkspace(java.lang.String workspace, java.io.File sldFile, java.lang.String name)Update a Style.booleanupdateStyleInWorkspace(java.lang.String workspace, java.lang.String sldBody, java.lang.String name)Update a Style.booleanupdateStyleInWorkspace(java.lang.String sldBody, java.lang.String workspace, java.lang.String name, boolean raw)Update a Style.booleanupdateStyleZippedInWorkspace(java.lang.String workspace, java.io.File zipFile, java.lang.String name)Update a Style.
-
-
-
Constructor Detail
-
GeoServerRESTStyleManager
public GeoServerRESTStyleManager(java.net.URL restURL, java.lang.String username, java.lang.String password) throws java.lang.IllegalArgumentExceptionDefault constructor.- Parameters:
restURL- GeoServer REST API endpointusername- GeoServer REST API authorized usernamepassword- GeoServer REST API password for the former username- Throws:
java.lang.IllegalArgumentException- if any.
-
-
Method Detail
-
existsStyle
public boolean existsStyle(java.lang.String name) throws java.lang.RuntimeExceptionCheck if a Style exists in the configured GeoServer instance.- Parameters:
name- the name of the style to check for.- Returns:
- true on HTTP 200, false on HTTP 404
- Throws:
java.lang.RuntimeException- if any other HTTP code than 200 or 404 was retrieved.
-
existsStyle
public boolean existsStyle(java.lang.String name, boolean quietOnNotFound)Check if a Style exists in the configured GeoServer instance. User can choose if log a possible exception or not- Parameters:
name- the name of the style to check for.quietOnNotFound- if true, mute exception if false is returned- Returns:
- true on HTTP 200, false on HTTP 404
- Throws:
java.lang.RuntimeException- if any other HTTP code than 200 or 404 was retrieved.
-
getStyles
public RESTStyleList getStyles()
Get summary info about all Styles.- Returns:
- summary info about Styles as a
RESTStyleList
-
getStyle
public RESTStyle getStyle(java.lang.String name)
getStyle
- Parameters:
name- aStringobject.- Returns:
- a
RESTStyleobject.
-
getSLD
public java.lang.String getSLD(java.lang.String styleName)
Get the SLD body of a Style.- Parameters:
styleName- aStringobject.- Returns:
- a
Stringobject.
-
existsStyle
public boolean existsStyle(java.lang.String workspace, java.lang.String name)existsStyle
- Parameters:
workspace- aStringobject.name- aStringobject.- Returns:
- a boolean.
- Since:
- GeoServer 2.2
-
existsStyle
public boolean existsStyle(java.lang.String workspace, java.lang.String name, boolean quietOnNotFound)existsStyle
- Parameters:
workspace- aStringobject.name- aStringobject.quietOnNotFound- a boolean.- Returns:
- a boolean.
- Since:
- GeoServer 2.6
-
getStyles
public RESTStyleList getStyles(java.lang.String workspace)
Get summary info about Styles in a workspace.- Parameters:
workspace- aStringobject.- Returns:
- summary info about Styles as a
RESTStyleList - Since:
- GeoServer 2.2
-
getStyle
public RESTStyle getStyle(java.lang.String workspace, java.lang.String name)
getStyle
- Parameters:
workspace- aStringobject.name- aStringobject.- Returns:
- a
RESTStyleobject. - Since:
- GeoServer 2.2
-
getSLD
public java.lang.String getSLD(java.lang.String workspace, java.lang.String name)Get the SLD body of a Style.- Parameters:
workspace- aStringobject.name- aStringobject.- Returns:
- a
Stringobject. - Since:
- GeoServer 2.2
-
publishStyle
public boolean publishStyle(java.lang.String sldBody)
Store and publish a Style.- Parameters:
sldBody- the full SLD document as a String.- Returns:
- true if the operation completed successfully.
-
publishStyle
public boolean publishStyle(java.lang.String sldBody, java.lang.String name) throws java.lang.IllegalArgumentExceptionStore and publish a Style, assigning it a name.- Parameters:
sldBody- the full SLD document as a String.name- the Style name.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the style body is null or empty.
-
publishStyle
public boolean publishStyle(java.io.File sldFile)
Store and publish a Style.- Parameters:
sldFile- the File containing the SLD document.- Returns:
- true if the operation completed successfully.
-
publishStyle
public boolean publishStyle(java.io.File sldFile, java.lang.String name)Store and publish a Style, assigning it a name.- Parameters:
sldFile- the File containing the SLD document.name- the Style name.- Returns:
- true if the operation completed successfully.
-
publishStyle
public boolean publishStyle(java.lang.String sldBody, java.lang.String name, boolean raw)Store and publish a Style, assigning it a name and choosing the raw format.- Parameters:
sldBody- the full SLD document as a String.name- the Style name.raw- the raw format- Returns:
- true if the operation completed successfully.
-
publishStyle
public boolean publishStyle(java.io.File sldFile, java.lang.String name, boolean raw)Store and publish a Style, assigning it a name and choosing the raw format.- Parameters:
sldFile- the File containing the SLD document.name- the Style name.raw- the raw format- Returns:
- true if the operation completed successfully.
-
updateStyle
public boolean updateStyle(java.io.File sldFile, java.lang.String name, boolean raw) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
sldFile- the File containing the SLD document.name- the Style name.raw- the raw format- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the style body or name are null or empty.
-
updateStyle
public boolean updateStyle(java.lang.String sldBody, java.lang.String name, boolean raw) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
sldBody- the new SLD document as a String.name- the Style name.raw- the raw format- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the style body or name are null or empty.
-
updateStyle
public boolean updateStyle(java.lang.String sldBody, java.lang.String name) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
sldBody- the new SLD document as a String.name- the Style name to update.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the style body or name are null or empty.
-
updateStyle
public boolean updateStyle(java.io.File sldFile, java.lang.String name) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
sldFile- the File containing the SLD document.name- the Style name.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the sldFile file or name are null or name is empty.
-
removeStyle
public boolean removeStyle(java.lang.String styleName, boolean purge) throws java.lang.IllegalArgumentExceptionRemove a Style.The Style will be unpublished, and (optionally) the SLD file will be removed.
- Parameters:
styleName- the name of the Style to remove.purge- remove the related SLD file from disk.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if styleName is null or empty.
-
removeStyle
public boolean removeStyle(java.lang.String styleName)
Remove a Style.The Style will be unpublished and the related SLD file will be removed.
- Parameters:
styleName- the name of the Style to remove.- Returns:
- true if the operation completed successfully.
-
publishStyleInWorkspace
public boolean publishStyleInWorkspace(java.lang.String workspace, java.lang.String sldBody)Store and publish a Style.- Parameters:
sldBody- the full SLD document as a String.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Since:
- GeoServer 2.2
-
publishStyleInWorkspace
public boolean publishStyleInWorkspace(java.lang.String workspace, java.lang.String sldBody, java.lang.String name) throws java.lang.IllegalArgumentExceptionStore and publish a Style, assigning it a name.- Parameters:
sldBody- the full SLD document as a String.name- the Style name.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the style body is null or empty.- Since:
- GeoServer 2.2
-
publishStyleInWorkspace
public boolean publishStyleInWorkspace(java.lang.String workspace, java.io.File sldFile)Store and publish a Style.- Parameters:
sldFile- the File containing the SLD document.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Since:
- GeoServer 2.2
-
publishStyleInWorkspace
public boolean publishStyleInWorkspace(java.lang.String workspace, java.io.File sldFile, java.lang.String name)Store and publish a Style, assigning it a name.- Parameters:
sldFile- the File containing the SLD document.name- the Style name.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Since:
- GeoServer 2.2
-
publishStyleZippedInWorkspace
public boolean publishStyleZippedInWorkspace(java.lang.String workspace, java.io.File zipFile, java.lang.String name)Store and publish a Style, assigning it a name.- Parameters:
zipFile- the ZIP file.name- the Style name.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Since:
- GeoServer 2.2
-
updateStyleInWorkspace
public boolean updateStyleInWorkspace(java.lang.String workspace, java.lang.String sldBody, java.lang.String name) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
sldBody- the new SLD document as a String.name- the Style name to update.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the style body or name are null or empty.- Since:
- GeoServer 2.2
-
updateStyleInWorkspace
public boolean updateStyleInWorkspace(java.lang.String sldBody, java.lang.String workspace, java.lang.String name, boolean raw) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
sldBody- the new SLD document as a String.name- the Style name.raw- the raw format- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the style body or name are null or empty.
-
updateStyleInWorkspace
public boolean updateStyleInWorkspace(java.lang.String workspace, java.io.File sldFile, java.lang.String name) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
sldFile- the File containing the SLD document.name- the Style name.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the sldFile file or name are null or name is empty.- Since:
- GeoServer 2.2
-
updateStyleInWorkspace
public boolean updateStyleInWorkspace(java.lang.String workspace, GSStyleEncoder encoder, java.lang.String name) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
encoder- the style metadata.name- the Style name.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the sldFile file or name are null or name is empty.- Since:
- GeoServer 2.2
-
updateStyleZippedInWorkspace
public boolean updateStyleZippedInWorkspace(java.lang.String workspace, java.io.File zipFile, java.lang.String name) throws java.lang.IllegalArgumentExceptionUpdate a Style.- Parameters:
zipFile- the zip file.name- the Style name.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if the sldFile file or name are null or name is empty.- Since:
- GeoServer 2.2
-
removeStyleInWorkspace
public boolean removeStyleInWorkspace(java.lang.String workspace, java.lang.String styleName, boolean purge) throws java.lang.IllegalArgumentExceptionRemove a Style.The Style will be unpublished, and (optionally) the SLD file will be removed.
- Parameters:
styleName- the name of the Style to remove.purge- remove the related SLD file from disk.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Throws:
java.lang.IllegalArgumentException- if styleName is null or empty.- Since:
- GeoServer 2.2
-
removeStyleInWorkspace
public boolean removeStyleInWorkspace(java.lang.String workspace, java.lang.String styleName)Remove a Style.The Style will be unpublished and the related SLD file will be removed.
- Parameters:
styleName- the name of the Style to remove.workspace- aStringobject.- Returns:
- true if the operation completed successfully.
- Since:
- GeoServer 2.2
-
buildPostUrl
protected java.lang.String buildPostUrl(java.lang.String workspace, java.lang.String name)Creates a URL for the given stylename with the name in querystring- Parameters:
workspace- nullable workspace namename- style name- Returns:
- a
Stringobject.
-
buildXmlUrl
protected java.lang.String buildXmlUrl(java.lang.String workspace, java.lang.String name)buildXmlUrl
- Parameters:
workspace- aStringobject.name- aStringobject.- Returns:
- a
Stringobject.
-
buildUrl
protected java.lang.String buildUrl(java.lang.String workspace, java.lang.String name, java.lang.String ext)Creates a URL for the given stylename with the name in the REST path- Parameters:
workspace- nullable workspace namename- style nameext- nullable output extension (e.g. ".xml" ".sld")- Returns:
- a
Stringobject.
-
-