Class GeoServerRESTStyleManager


  • public class GeoServerRESTStyleManager
    extends GeoServerRESTAbstractManager

    GeoServerRESTStyleManager class.

    Version:
    $Id: $
    Author:
    ETj (etj at geo-solutions.it)
    • 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.String buildPostUrl​(java.lang.String workspace, java.lang.String name)
      Creates a URL for the given stylename with the name in querystring
      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
      protected java.lang.String buildXmlUrl​(java.lang.String workspace, java.lang.String name)
      buildXmlUrl
      boolean existsStyle​(java.lang.String name)
      Check if a Style exists in the configured GeoServer instance.
      boolean existsStyle​(java.lang.String name, boolean quietOnNotFound)
      Check if a Style exists in the configured GeoServer instance.
      boolean existsStyle​(java.lang.String workspace, java.lang.String name)
      existsStyle
      boolean existsStyle​(java.lang.String workspace, java.lang.String name, boolean quietOnNotFound)
      existsStyle
      java.lang.String getSLD​(java.lang.String styleName)
      Get the SLD body of a Style.
      java.lang.String getSLD​(java.lang.String workspace, java.lang.String name)
      Get the SLD body of a Style.
      RESTStyle getStyle​(java.lang.String name)
      getStyle
      RESTStyle getStyle​(java.lang.String workspace, java.lang.String name)
      getStyle
      RESTStyleList getStyles()
      Get summary info about all Styles.
      RESTStyleList getStyles​(java.lang.String workspace)
      Get summary info about Styles in a workspace.
      boolean publishStyle​(java.io.File sldFile)
      Store and publish a Style.
      boolean publishStyle​(java.io.File sldFile, java.lang.String name)
      Store and publish a Style, assigning it a name.
      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.
      boolean publishStyle​(java.lang.String sldBody)
      Store and publish a Style.
      boolean publishStyle​(java.lang.String sldBody, java.lang.String name)
      Store and publish a Style, assigning it a name.
      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.
      boolean publishStyleInWorkspace​(java.lang.String workspace, java.io.File sldFile)
      Store and publish a Style.
      boolean publishStyleInWorkspace​(java.lang.String workspace, java.io.File sldFile, java.lang.String name)
      Store and publish a Style, assigning it a name.
      boolean publishStyleInWorkspace​(java.lang.String workspace, java.lang.String sldBody)
      Store and publish a Style.
      boolean publishStyleInWorkspace​(java.lang.String workspace, java.lang.String sldBody, java.lang.String name)
      Store and publish a Style, assigning it a name.
      boolean publishStyleZippedInWorkspace​(java.lang.String workspace, java.io.File zipFile, java.lang.String name)
      Store and publish a Style, assigning it a name.
      boolean removeStyle​(java.lang.String styleName)
      Remove a Style.
      boolean removeStyle​(java.lang.String styleName, boolean purge)
      Remove a Style.
      boolean removeStyleInWorkspace​(java.lang.String workspace, java.lang.String styleName)
      Remove a Style.
      boolean removeStyleInWorkspace​(java.lang.String workspace, java.lang.String styleName, boolean purge)
      Remove a Style.
      boolean updateStyle​(java.io.File sldFile, java.lang.String name)
      Update a Style.
      boolean updateStyle​(java.io.File sldFile, java.lang.String name, boolean raw)
      Update a Style.
      boolean updateStyle​(java.lang.String sldBody, java.lang.String name)
      Update a Style.
      boolean updateStyle​(java.lang.String sldBody, java.lang.String name, boolean raw)
      Update a Style.
      boolean updateStyleInWorkspace​(java.lang.String workspace, GSStyleEncoder encoder, java.lang.String name)
      Update a Style.
      boolean updateStyleInWorkspace​(java.lang.String workspace, java.io.File sldFile, java.lang.String name)
      Update a Style.
      boolean updateStyleInWorkspace​(java.lang.String workspace, java.lang.String sldBody, java.lang.String name)
      Update a Style.
      boolean updateStyleInWorkspace​(java.lang.String sldBody, java.lang.String workspace, java.lang.String name, boolean raw)
      Update a Style.
      boolean updateStyleZippedInWorkspace​(java.lang.String workspace, java.io.File zipFile, java.lang.String name)
      Update a Style.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • GeoServerRESTStyleManager

        public GeoServerRESTStyleManager​(java.net.URL restURL,
                                         java.lang.String username,
                                         java.lang.String password)
                                  throws java.lang.IllegalArgumentException
        Default constructor.
        Parameters:
        restURL - GeoServer REST API endpoint
        username - GeoServer REST API authorized username
        password - 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.RuntimeException
        Check 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 - a String object.
        Returns:
        a RESTStyle object.
      • getSLD

        public java.lang.String getSLD​(java.lang.String styleName)
        Get the SLD body of a Style.
        Parameters:
        styleName - a String object.
        Returns:
        a String object.
      • existsStyle

        public boolean existsStyle​(java.lang.String workspace,
                                   java.lang.String name)

        existsStyle

        Parameters:
        workspace - a String object.
        name - a String object.
        Returns:
        a boolean.
        Since:
        GeoServer 2.2
      • existsStyle

        public boolean existsStyle​(java.lang.String workspace,
                                   java.lang.String name,
                                   boolean quietOnNotFound)

        existsStyle

        Parameters:
        workspace - a String object.
        name - a String object.
        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 - a String object.
        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 - a String object.
        name - a String object.
        Returns:
        a RESTStyle object.
        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 - a String object.
        name - a String object.
        Returns:
        a String object.
        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.IllegalArgumentException
        Store 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.IllegalArgumentException
        Update 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.IllegalArgumentException
        Update 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.IllegalArgumentException
        Update 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.IllegalArgumentException
        Update 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.IllegalArgumentException
        Remove 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 - a String object.
        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.IllegalArgumentException
        Store and publish a Style, assigning it a name.
        Parameters:
        sldBody - the full SLD document as a String.
        name - the Style name.
        workspace - a String object.
        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 - a String object.
        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 - a String object.
        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 - a String object.
        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.IllegalArgumentException
        Update a Style.
        Parameters:
        sldBody - the new SLD document as a String.
        name - the Style name to update.
        workspace - a String object.
        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.IllegalArgumentException
        Update 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.IllegalArgumentException
        Update a Style.
        Parameters:
        sldFile - the File containing the SLD document.
        name - the Style name.
        workspace - a String object.
        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.IllegalArgumentException
        Update a Style.
        Parameters:
        encoder - the style metadata.
        name - the Style name.
        workspace - a String object.
        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.IllegalArgumentException
        Update a Style.
        Parameters:
        zipFile - the zip file.
        name - the Style name.
        workspace - a String object.
        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.IllegalArgumentException
        Remove 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 - a String object.
        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 - a String object.
        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 name
        name - style name
        Returns:
        a String object.
      • buildXmlUrl

        protected java.lang.String buildXmlUrl​(java.lang.String workspace,
                                               java.lang.String name)

        buildXmlUrl

        Parameters:
        workspace - a String object.
        name - a String object.
        Returns:
        a String object.
      • 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 name
        name - style name
        ext - nullable output extension (e.g. ".xml" ".sld")
        Returns:
        a String object.