Class StyleHandler

  • Direct Known Subclasses:
    SLDHandler

    public abstract class StyleHandler
    extends Object
    Extension point for handling a style of a particular language/version.

    Author:
    Justin Deoliveira, Boundless
    • Field Detail

      • styleFactory

        protected static org.geotools.styling.StyleFactory styleFactory
      • IMAGE_EXTENSIONS

        protected static String[] IMAGE_EXTENSIONS
      • IMAGE_TYPES

        protected static javax.activation.MimetypesFileTypeMap IMAGE_TYPES
    • Constructor Detail

      • StyleHandler

        protected StyleHandler​(String name,
                               String format)
    • Method Detail

      • getName

        public String getName()
        Human readable name of the handler.
      • getFormat

        public String getFormat()
        Format identifier for the handler.
      • getVersions

        public List<org.geotools.util.Version> getVersions()
        Supported format versions.
      • getFileExtension

        public String getFileExtension()
        Returns the file extension for the format.

        Defaults to getFormat().

      • getCodeMirrorEditMode

        public String getCodeMirrorEditMode()
        Returns the identifier for the mode used for syntax highlighting in the code mirror editor.

        Defaults to getFormat()

      • getStyle

        public String getStyle​(StyleType type,
                               Color color,
                               String colorName,
                               String layerName)
        Generates a style from a template using the provided substitutions.
        Parameters:
        type - the template type, see org.geoserver.catalog.StyleType.
        color - java.aw.Color to use during substitution
        colorName - Human readable color name, for use generating comments
        layerName - Layer name, for use generating comments
        Returns:
        The text content of the style template after performing substitutions
      • parse

        public abstract org.geotools.styling.StyledLayerDescriptor parse​(Object input,
                                                                         org.geotools.util.Version version,
                                                                         org.geotools.styling.ResourceLocator resourceLocator,
                                                                         EntityResolver entityResolver)
                                                                  throws IOException
        Parses a style resource.
        Parameters:
        input - The style input, see toReader(Object) for accepted inputs.
        version - Optional version of the format, maybe null
        resourceLocator - Optional locator for resources (icons, etc...) referenced by the style, may be null.
        entityResolver - Optional entity resolver for XML based formats, may be null .
        Throws:
        IOException
      • encode

        public abstract void encode​(org.geotools.styling.StyledLayerDescriptor sld,
                                    org.geotools.util.Version version,
                                    boolean pretty,
                                    OutputStream output)
                             throws IOException
        Encodes a style.

        Handlers that don't support encoding should throw UnsupportedOperationException.

        Parameters:
        sld - The style to encode.
        version - The version of the format to use to encode the style, may be null .
        pretty - Flag controlling whether or not the style should be encoded in pretty form.
        output - The stream to write the encoded style to.
        Throws:
        IOException
      • validate

        public abstract List<Exception> validate​(Object input,
                                                 org.geotools.util.Version version,
                                                 EntityResolver entityResolver)
                                          throws IOException
        Validates a style resource.

        For handlers that don't support an extended form of validation (like against an XML schema) this implementation should at a minimum attempt to parse the input and return any parsing errors.

        Parameters:
        input - The style input, see toReader(Object) for accepted inputs.
        version - The version of the format to use to validate the style, may be null .
        Returns:
        Any validation errors, or empty list if the style is valid.
        Throws:
        IOException
      • mimeType

        public abstract String mimeType​(org.geotools.util.Version version)
        Returns the format mime type for the specified version.
      • versionForMimeType

        public org.geotools.util.Version versionForMimeType​(String mimeType)
        Returns the format version for the specified mime type.

        This method should only be overriden by formats that support multiple versions. The default implementation just returns 1.0.0.

      • version

        public org.geotools.util.Version version​(Object input)
                                          throws IOException
        Determines the version of the format/language of the specified style resource.

        This method should only be overriden by formats that support multiple versions. The default implementation just returns 1.0.0.

        Parameters:
        input - The style input, see toReader(Object) for accepted inputs.
        Throws:
        IOException
      • imageExtensions

        public String[] imageExtensions()
      • insertImageCode

        public String insertImageCode​(String imageFileName)