Class StyleHandler
- java.lang.Object
-
- org.hortonmachine.gears.utils.style.sld.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 Summary
Fields Modifier and Type Field Description protected static String[]IMAGE_EXTENSIONSprotected static javax.activation.MimetypesFileTypeMapIMAGE_TYPESprotected static org.geotools.styling.StyleFactorystyleFactory
-
Constructor Summary
Constructors Modifier Constructor Description protectedStyleHandler(String name, String format)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidencode(org.geotools.styling.StyledLayerDescriptor sld, org.geotools.util.Version version, boolean pretty, OutputStream output)Encodes a style.StringgetCodeMirrorEditMode()Returns the identifier for the mode used for syntax highlighting in the code mirror editor.StringgetFileExtension()Returns the file extension for the format.StringgetFormat()Format identifier for the handler.StringgetName()Human readable name of the handler.StringgetStyle(StyleType type, Color color, String colorName, String layerName)Generates a style from a template using the provided substitutions.List<org.geotools.util.Version>getVersions()Supported format versions.String[]imageExtensions()StringinsertImageCode(String imageFileName)abstract StringmimeType(org.geotools.util.Version version)Returns the format mime type for the specified version.abstract org.geotools.styling.StyledLayerDescriptorparse(Object input, org.geotools.util.Version version, org.geotools.styling.ResourceLocator resourceLocator, EntityResolver entityResolver)Parses a style resource.protected ReadertoReader(Object input)Turns input into a Reader.abstract List<Exception>validate(Object input, org.geotools.util.Version version, EntityResolver entityResolver)Validates a style resource.org.geotools.util.Versionversion(Object input)Determines the version of the format/language of the specified style resource.org.geotools.util.VersionversionForMimeType(String mimeType)Returns the format version for the specified mime type.
-
-
-
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
-
-
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, seeorg.geoserver.catalog.StyleType.color- java.aw.Color to use during substitutioncolorName- Human readable color name, for use generating commentslayerName- 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, seetoReader(Object)for accepted inputs.version- Optional version of the format, maybenullresourceLocator- Optional locator for resources (icons, etc...) referenced by the style, may benull.entityResolver- Optional entity resolver for XML based formats, may benull.- Throws:
IOException
-
encode
public abstract void encode(org.geotools.styling.StyledLayerDescriptor sld, org.geotools.util.Version version, boolean pretty, OutputStream output) throws IOExceptionEncodes 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 benull.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, seetoReader(Object)for accepted inputs.version- The version of the format to use to validate the style, may benull.- 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, seetoReader(Object)for accepted inputs.- Throws:
IOException
-
toReader
protected Reader toReader(Object input) throws IOException
Turns input into a Reader.- Parameters:
input- AReader,InputStream,File, orResource.- Throws:
IOException
-
imageExtensions
public String[] imageExtensions()
-
-