Class SLDParser

Object
SLDParser

public class SLDParser extends Object
Utility methods for working with SLD content.
Author:
jgarnett
  • Field Details

    • source

      protected InputSource source
    • factory

      protected StyleFactory factory
    • supportDTD

      protected boolean supportDTD
      Support use of DOCTYPE DTD references, default false.
    • expandEntityReferences

      protected boolean expandEntityReferences
      Support entity resolution expansion, default false.
    • xinclude

      protected boolean xinclude
      Support XInclude , default false.
    • validating

      protected boolean validating
      Support validating , default false.
  • Constructor Details

    • SLDParser

      public SLDParser(StyleFactory factory)
      Create a SLDParser - use if you already have a dom to parse.
      Parameters:
      factory - The StyleFactory to use to build the style
    • SLDParser

      public SLDParser(StyleFactory factory, FilterFactory filterFactory)
    • SLDParser

      public SLDParser(StyleFactory factory, String filename) throws FileNotFoundException
      Creates a new instance of SLDParser.
      Parameters:
      factory - The StyleFactory to use to read the file
      filename - The file to be read.
      Throws:
      FileNotFoundException - - if the file is missing
    • SLDParser

      public SLDParser(StyleFactory factory, File f) throws FileNotFoundException
      Creates a new SLDStyle object.
      Parameters:
      factory - The StyleFactory to use to read the file
      f - the File to be read
      Throws:
      FileNotFoundException - - if the file is missing
    • SLDParser

      public SLDParser(StyleFactory factory, URL url) throws IOException
      Creates a new SLDStyle object.
      Parameters:
      factory - The StyleFactory to use to read the file
      url - the URL to be read.
      Throws:
      IOException - - if something goes wrong reading the file
    • SLDParser

      public SLDParser(StyleFactory factory, InputStream s)
      Creates a new SLDStyle object.
      Parameters:
      factory - The StyleFactory to use to read the file
      s - The inputstream to be read
    • SLDParser

      public SLDParser(StyleFactory factory, Reader r)
      Creates a new SLDStyle object.
      Parameters:
      factory - The StyleFactory to use to read the file
      r - The inputstream to be read
  • Method Details

    • setInput

      public void setInput(String filename) throws FileNotFoundException
      set the file to read the SLD from
      Parameters:
      filename - the file to read the SLD from
      Throws:
      FileNotFoundException - if the file is missing
    • setInput

      public void setInput(File f) throws FileNotFoundException
      Sets the file to use to read the SLD from
      Parameters:
      f - the file to use
      Throws:
      FileNotFoundException - if the file is missing
    • setInput

      public void setInput(URL url) throws IOException
      sets an URL to read the SLD from
      Parameters:
      url - the url to read the SLD from
      Throws:
      IOException - If anything goes wrong opening the url
    • setInput

      public void setInput(InputStream in)
      Sets the input stream to read the SLD from
      Parameters:
      in - the inputstream used to read the SLD from
    • setInput

      public void setInput(Reader in)
      Sets the input stream to read the SLD from
      Parameters:
      in - the inputstream used to read the SLD from
    • setOnLineResourceLocator

      public void setOnLineResourceLocator(ResourceLocator onlineResourceLocator)
      Sets the resource loader implementation for parsing online resources.
    • setEntityResolver

      public void setEntityResolver(EntityResolver entityResolver)
      Sets the EntityResolver implementation that will be used by DocumentBuilder to resolve XML external entities.
    • isSupportDTD

      public boolean isSupportDTD()
      Use of DTD is not recommended, and is false by default. May be set to true if required for XML using DOCTYPE.
      Returns:
      false to prevent support of DTD, or true if required.
    • setSupportDTD

      public void setSupportDTD(boolean supportDTD)
      Use of DTD is not recommended, and is false by default.
      Parameters:
      supportDTD - false to prevent support of DTD, if required for XML using DOCTYPE.
    • isExpandEntityReferences

      public boolean isExpandEntityReferences()
      Use of expand entity references is not recommended, and is false by default. May be set to true DOCTYPE is used to define injected entities.
      Returns:
      false to prevent support of expanding entity references, or true if required.
    • setExpandEntityReferences

      public void setExpandEntityReferences(boolean expandEntityReferences)
      Use of expand entity references is not recommended, and is false by default. May be set to true if DOCTYPE is used to to define references.
      Parameters:
      expandEntityReferences - Use false to prevent support of expanding entity references, or true if required.
    • setXInclude

      public void setXInclude(boolean xinclude)
      Use of XInclude is not recommended, and is false by default. May be set to true to support inclusion of xsd content.
      Parameters:
      xinclude - Use false to prevent use of XInclude, or true if required.
    • getXInclude

      public boolean getXInclude()
      Use of XInclude is not recommended, and is false by default. May be set to true to support inclusion of xsd content.
      Returns:
      Use false to prevent use of XInclude, or true if required.
    • setValidating

      public void setValidating(boolean validating)
      Use of validating is not required, and is false by default. Use of validating,
      Parameters:
      validating - Use false to parse document without validation, or true to validate using XMLConstants.W3C_XML_SCHEMA_NS_URI.
    • getValidating

      public boolean getValidating()
      Use of validating is not required, and is false by default.
      Returns:
      Use false to parse document without validation, or true to validate using XMLConstants.W3C_XML_SCHEMA_NS_URI.
    • newDocumentBuilder

      protected DocumentBuilder newDocumentBuilder(boolean namespaceAware) throws ParserConfigurationException
      Configured DocumentBuilder for parsing SLD documents, which requires namespace information.
      Parameters:
      namespaceAware -
      Returns:
      Throws:
      ParserConfigurationException
    • readXML

      public Style[] readXML()
      Read the xml inputsource provided and create a Style object for each user style found
      Returns:
      Style[] the styles constructed.
      Throws:
      RuntimeException - if a parsing error occurs
    • readDOM

      public Style[] readDOM()
      Read styles from the dom that was previously parsed.
    • readDOM

      public Style[] readDOM(Document document)
      Read the DOM provided and create a Style object for each user style found
      Parameters:
      document - a dom containing the SLD
      Returns:
      Style[] the styles constructed.
    • parseSLD

      public StyledLayerDescriptor parseSLD()
    • parseDescriptor

      public StyledLayerDescriptor parseDescriptor(Node root)
    • parseFeatureTypeConstraint

      protected FeatureTypeConstraint parseFeatureTypeConstraint(Node root)
    • parseRemoteOWS

      protected RemoteOWS parseRemoteOWS(Node root)
    • parseNamedStyle

      public NamedStyle parseNamedStyle(Node n)
      Parses a NamedStyle from node.

      A NamedStyle is used to refer to a style that has a name in a WMS, and is defined as:

       <code>
       <xsd:element name="NamedStyle">
        <xsd:annotation>
         <xsd:documentation> A NamedStyle is used to refer to a style that has a name in a WMS. </xsd:documentation>
        </xsd:annotation>
        <xsd:complexType>
         <xsd:sequence>
          <xsd:element ref="sld:Name"/>
         </xsd:sequence>
        </xsd:complexType>
       </xsd:element>
       </code>
       
    • parseStyle

      public Style parseStyle(Node n)
      build a style for the Node provided
      Parameters:
      n - the node which contains the style to be parsed.
      Returns:
      the Style constructed.
      Throws:
      RuntimeException - if an error occurs setting up the parser
    • parseFeatureTypeStyle

      protected FeatureTypeStyle parseFeatureTypeStyle(Node style)
      Internal parse method - made protected for unit testing
    • parseRule

      protected Rule parseRule(Node ruleNode)
      Internal parse method - made protected for unit testing
    • parseFilter

      protected Filter parseFilter(Node child)
      Internal parse method - made protected for unit testing
    • parseLineSymbolizer

      protected LineSymbolizer parseLineSymbolizer(Node root)
      parses the SLD for a linesymbolizer
      Parameters:
      root - a w2c Dom Node
      Returns:
      the linesymbolizer
    • parsePolygonSymbolizer

      protected PolygonSymbolizer parsePolygonSymbolizer(Node root)
      parses the SLD for a polygonsymbolizer
      Parameters:
      root - w3c dom node
      Returns:
      the polygon symbolizer
    • parseTextSymbolizer

      protected TextSymbolizer parseTextSymbolizer(Node root)
      parses the SLD for a text symbolizer
      Parameters:
      root - w3c dom node
      Returns:
      the TextSymbolizer
    • parseOtherText

      protected OtherText parseOtherText(Node root)
    • parseRasterSymbolizer

      protected RasterSymbolizer parseRasterSymbolizer(Node root)
      parses the SLD for a text symbolizer
      Parameters:
      root - w3c dom node
      Returns:
      the TextSymbolizer
    • parseColorMapEntry

      protected ColorMapEntry parseColorMapEntry(Node root)
      Internal parse method - made protected for unit testing
    • parseColorMap

      protected ColorMap parseColorMap(Node root)
      Internal parse method - made protected for unit testing
    • parseSelectedChannel

      protected SelectedChannelType parseSelectedChannel(Node root)
      Internal parse method - made protected for unit testing
    • parseChannelSelection

      protected ChannelSelection parseChannelSelection(Node root)
      Internal parse method - made protected for unit testing
    • parseContrastEnhancement

      protected ContrastEnhancement parseContrastEnhancement(Node root)
      Internal parse method - made protected for unit testing
    • parseShadedRelief

      protected ShadedRelief parseShadedRelief(Node root)
      Internal parse method - made protected for unit testing
    • parsePointSymbolizer

      protected PointSymbolizer parsePointSymbolizer(Node root)
      parses the SLD for a point symbolizer
      Parameters:
      root - a w3c dom node
      Returns:
      the pointsymbolizer
    • parseGraphic

      protected Graphic parseGraphic(Node root)
      Internal parse method - made protected for unit testing
    • parseGeometryName

      protected String parseGeometryName(Node root)
      Internal parse method - made protected for unit testing
    • parseGeometry

      protected Expression parseGeometry(Node root)
      Internal parse method - made protected for unit testing
    • parseMark

      protected Mark parseMark(Node root)
      Internal parse method - made protected for unit testing
    • parseExternalGraphic

      protected ExternalGraphic parseExternalGraphic(Node root)
      Internal parse method - made protected for unit testing
    • parseOnlineResource

      protected String parseOnlineResource(Node root)
      Internal parse method - made protected for unit testing
    • parseStroke

      protected Stroke parseStroke(Node root)
      Internal parse method - made protected for unit testing
    • parseFill

      protected Fill parseFill(Node root)
      Internal parse method - made protected for unit testing
    • parseFont

      protected Font parseFont(Node root)
      Internal method to parse a Font Node; protected to allow for unit testing
    • parseLabelPlacement

      protected LabelPlacement parseLabelPlacement(Node root)
      Internal parse method - made protected for unit testing
    • parsePointPlacement

      protected PointPlacement parsePointPlacement(Node root)
      Internal parse method - made protected for unit testing
    • parseLinePlacement

      protected LinePlacement parseLinePlacement(Node root)
      Internal parse method - made protected for unit testing
    • parseAnchorPoint

      protected AnchorPoint parseAnchorPoint(Node root)
      Internal method to parse an AnchorPoint node; protected visibility for testing.
    • parseDisplacement

      protected Displacement parseDisplacement(Node root)
      Internal parse method - made protected for unit testing
    • parseHalo

      protected Halo parseHalo(Node root)
      Internal parse method - made protected for unit testing