Class ParseOptions

  • All Implemented Interfaces:
    java.io.Serializable

    public class ParseOptions
    extends java.lang.Object
    implements java.io.Serializable
    This class defines options for parsing a source document
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      ParseOptions()
      Create a ParseOptions object with default options set
      ParseOptions​(ParseOptions p)
      Create a ParseOptions object as a copy of another ParseOptions
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFilter​(FilterFactory filterFactory)
      Add a filter to the list of filters to be applied to the raw input
      void applyDefaults​(Configuration config)
      Merge settings from the Configuration object into these parseOptions
      static void close​(javax.xml.transform.Source source)
      Close any resources held by a given Source.
      int getDTDValidationMode()
      Get whether or not DTD validation of this source is required
      org.xml.sax.EntityResolver getEntityResolver()
      Get the EntityResolver that will be used when parsing
      org.xml.sax.ErrorHandler getErrorHandler()
      Get the ErrorHandler that will be used when parsing
      javax.xml.transform.ErrorListener getErrorListener()
      Get the ErrorListener that will be used when parsing
      java.util.List<FilterFactory> getFilters()
      Get the list of filters to be applied to the input.
      TreeModel getModel()
      Get the tree model that will be used.
      int getSchemaValidationMode()
      Get whether or not schema validation of this source is required
      int getStripSpace()
      Get the space-stripping action to be applied to the source document
      StructuredQName getTopLevelElement()
      Get the name of the top-level element for validation.
      SchemaType getTopLevelType()
      Get the type of the document element for validation.
      int getTreeModel()
      Get the tree model that will be used.
      ValidationStatisticsRecipient getValidationStatisticsRecipient()
      Ask whether statistics of component usage are maintained during schema validation, and where they will be sent
      java.lang.Boolean getWrapDocument()
      Assuming that the contained Source is a node in a tree, determine whether a tree will be created as a view of this supplied tree, or as a copy.
      org.xml.sax.XMLReader getXMLReader()
      Get the SAX parser (XMLReader) to be used
      boolean isAddCommentsAfterValidationErrors()
      Ask whether on validation errors, messages explaining the error should (where possible) be written as comments in the validated source document.
      boolean isCheckEntityReferences()
      Ask whether to check elements and attributes of type xs:ENTITY (or xs:ENTITIES) against the unparsed entities declared in the document's DTD.
      boolean isContinueAfterValidationErrors()
      Ask whether processing should continue after a validation error (true when the output is a final output)
      boolean isExpandAttributeDefaults()
      Ask whether to expand default attributes defined in a DTD or schema.
      boolean isLineNumbering()
      Get whether line numbers are to be maintained in the constructed document
      boolean isLineNumberingSet()
      Determine whether setLineNumbering() has been called
      boolean isPleaseCloseAfterUse()
      Determine whether or not the user of this Source is encouraged to close it as soon as reading is finished.
      boolean isUseXsiSchemaLocation()
      Ask whether or not to use the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes in an instance document to locate a schema for validation.
      boolean isXIncludeAware()
      Get state of XInclude processing.
      boolean isXIncludeAwareSet()
      Determine whether setXIncludeAware() has been called.
      void merge​(ParseOptions options)
      Merge another set of parseOptions into these parseOptions
      void setAddCommentsAfterValidationErrors​(boolean keepGoing)
      Say that on validation errors, messages explaining the error should (where possible) be written as comments in the validated source document.
      void setCheckEntityReferences​(boolean check)
      Say whether to check elements and attributes of type xs:ENTITY (or xs:ENTITIES) against the unparsed entities declared in the document's DTD.
      void setContinueAfterValidationErrors​(boolean keepGoing)
      Say that processing should continue after a validation error (true when the output is a final output)
      void setDTDValidationMode​(int option)
      Set whether or not DTD validation of this source is required
      void setEntityResolver​(org.xml.sax.EntityResolver resolver)
      Set an EntityResolver to be used when parsing.
      void setErrorHandler​(org.xml.sax.ErrorHandler handler)
      Set an ErrorHandler to be used when parsing.
      void setErrorListener​(javax.xml.transform.ErrorListener listener)
      Set an ErrorListener to be used when parsing
      void setExpandAttributeDefaults​(boolean expand)
      Set whether to expand default attributes defined in a DTD or schema.
      void setLineNumbering​(boolean lineNumbering)
      Set whether line numbers are to be maintained in the constructed document
      void setModel​(TreeModel model)
      Set the tree model to use.
      void setPleaseCloseAfterUse​(boolean close)
      Set whether or not the user of this Source is encouraged to close it as soon as reading is finished.
      void setSchemaValidationMode​(int option)
      Set whether or not schema validation of this source is required
      void setStripSpace​(int stripAction)
      Set the space-stripping action to be applied to the source document
      void setTopLevelElement​(StructuredQName elementName)
      Set the name of the top-level element for validation.
      void setTopLevelType​(SchemaType type)
      Set the type of the top-level element for validation.
      void setTreeModel​(int model)
      Set the tree model to use.
      void setUseXsiSchemaLocation​(boolean use)
      Set whether or not to use the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes in an instance document to locate a schema for validation.
      void setValidationStatisticsRecipient​(ValidationStatisticsRecipient recipient)
      Say that statistics of component usage are maintained during schema validation, and indicate where they should be sent
      void setWrapDocument​(java.lang.Boolean wrap)
      Assuming that the contained Source is a node in a tree, indicate whether a tree should be created as a view of this supplied tree, or as a copy.
      void setXIncludeAware​(boolean state)
      Set state of XInclude processing.
      void setXMLReader​(org.xml.sax.XMLReader parser)
      Set the SAX parser (XMLReader) to be used
      • Methods inherited from class java.lang.Object

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

      • ParseOptions

        public ParseOptions()
        Create a ParseOptions object with default options set
      • ParseOptions

        public ParseOptions​(ParseOptions p)
        Create a ParseOptions object as a copy of another ParseOptions
        Parameters:
        p - the ParseOptions to be copied
    • Method Detail

      • merge

        public void merge​(ParseOptions options)
        Merge another set of parseOptions into these parseOptions
        Parameters:
        options - the other parseOptions. If both are present, the other parseOptions take precedence
      • applyDefaults

        public void applyDefaults​(Configuration config)
        Merge settings from the Configuration object into these parseOptions
        Parameters:
        config - the Configuration. Settings from the Configuration are used only where no setting is present in this ParseOptions object
      • addFilter

        public void addFilter​(FilterFactory filterFactory)
        Add a filter to the list of filters to be applied to the raw input
        Parameters:
        filterFactory - the filterFactory to be added
      • getFilters

        public java.util.List<FilterFactory> getFilters()
        Get the list of filters to be applied to the input. Returns null if there are no filters.
        Returns:
        the list of filters, if there are any
      • getSchemaValidationMode

        public int getSchemaValidationMode()
        Get whether or not schema validation of this source is required
        Returns:
        the validation mode requested, or Validation.DEFAULT to use the default validation mode from the Configuration.
      • setExpandAttributeDefaults

        public void setExpandAttributeDefaults​(boolean expand)
        Set whether to expand default attributes defined in a DTD or schema. By default, default attribute values are expanded
        Parameters:
        expand - true if missing attribute values are to take the default value supplied in a DTD or schema, false if they are to be left as absent
      • isExpandAttributeDefaults

        public boolean isExpandAttributeDefaults()
        Ask whether to expand default attributes defined in a DTD or schema. By default, default attribute values are expanded
        Returns:
        true if missing attribute values are to take the default value supplied in a DTD or schema, false if they are to be left as absent
      • setTopLevelElement

        public void setTopLevelElement​(StructuredQName elementName)
        Set the name of the top-level element for validation. If a top-level element is set then the document being validated must have this as its outermost element
        Parameters:
        elementName - the QName of the required top-level element, or null to unset the value
      • getTopLevelElement

        public StructuredQName getTopLevelElement()
        Get the name of the top-level element for validation. If a top-level element is set then the document being validated must have this as its outermost element
        Returns:
        the QName of the required top-level element, or null if no value is set
        Since:
        9.0
      • setTopLevelType

        public void setTopLevelType​(SchemaType type)
        Set the type of the top-level element for validation. If this is set then the document element is validated against this type
        Parameters:
        type - the schema type required for the document element, or null to unset the value
      • getTopLevelType

        public SchemaType getTopLevelType()
        Get the type of the document element for validation. If this is set then the document element of the document being validated must have this type
        Returns:
        the type of the required top-level element, or null if no value is set
      • setUseXsiSchemaLocation

        public void setUseXsiSchemaLocation​(boolean use)
        Set whether or not to use the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes in an instance document to locate a schema for validation. Note, these attribute are only used if validation is requested.
        Parameters:
        use - true if these attributes are to be used, false if they are to be ignored
      • isUseXsiSchemaLocation

        public boolean isUseXsiSchemaLocation()
        Ask whether or not to use the xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes in an instance document to locate a schema for validation. Note, these attribute are only used if validation is requested.
        Returns:
        true (the default) if these attributes are to be used, false if they are to be ignored
      • getDTDValidationMode

        public int getDTDValidationMode()
        Get whether or not DTD validation of this source is required
        Returns:
        the validation mode requested, or Validation.DEFAULT to use the default validation mode from the Configuration.

        The value Validation.LAX indicates that DTD validation is requested, but validation failures are treated as warnings only.

      • setValidationStatisticsRecipient

        public void setValidationStatisticsRecipient​(ValidationStatisticsRecipient recipient)
        Say that statistics of component usage are maintained during schema validation, and indicate where they should be sent
        Parameters:
        recipient - the agent to be notified of the validation statistics on completion of the validation episode, May be set to null if no agent is to be notified.
      • getValidationStatisticsRecipient

        public ValidationStatisticsRecipient getValidationStatisticsRecipient()
        Ask whether statistics of component usage are maintained during schema validation, and where they will be sent
        Returns:
        the agent to be notified of the validation statistics on completion of the validation episode, or null if none has been nominated
      • setLineNumbering

        public void setLineNumbering​(boolean lineNumbering)
        Set whether line numbers are to be maintained in the constructed document
        Parameters:
        lineNumbering - true if line numbers are to be maintained
      • isLineNumbering

        public boolean isLineNumbering()
        Get whether line numbers are to be maintained in the constructed document
        Returns:
        true if line numbers are maintained
      • isLineNumberingSet

        public boolean isLineNumberingSet()
        Determine whether setLineNumbering() has been called
        Returns:
        true if setLineNumbering() has been called
      • setXMLReader

        public void setXMLReader​(org.xml.sax.XMLReader parser)
        Set the SAX parser (XMLReader) to be used
        Parameters:
        parser - the SAX parser
      • getXMLReader

        public org.xml.sax.XMLReader getXMLReader()
        Get the SAX parser (XMLReader) to be used
        Returns:
        the parser
      • setEntityResolver

        public void setEntityResolver​(org.xml.sax.EntityResolver resolver)
        Set an EntityResolver to be used when parsing. Note that this will not be used if an XMLReader has been supplied (in that case, the XMLReader should be initialized with the EntityResolver already set.)
        Parameters:
        resolver - the EntityResolver to be used. May be null, in which case any existing EntityResolver is removed from the options
      • getEntityResolver

        public org.xml.sax.EntityResolver getEntityResolver()
        Get the EntityResolver that will be used when parsing
        Returns:
        the EntityResolver, if one has been set using setEntityResolver(org.xml.sax.EntityResolver), otherwise null.
      • setErrorHandler

        public void setErrorHandler​(org.xml.sax.ErrorHandler handler)
        Set an ErrorHandler to be used when parsing. Note that this will not be used if an XMLReader has been supplied (in that case, the XMLReader should be initialized with the ErrorHandler already set.)
        Parameters:
        handler - the ErrorHandler to be used, or null to indicate that no ErrorHandler is to be used.
      • getErrorHandler

        public org.xml.sax.ErrorHandler getErrorHandler()
        Get the ErrorHandler that will be used when parsing
        Returns:
        the ErrorHandler, if one has been set using setErrorHandler(org.xml.sax.ErrorHandler), otherwise null.
      • setWrapDocument

        public void setWrapDocument​(java.lang.Boolean wrap)
        Assuming that the contained Source is a node in a tree, indicate whether a tree should be created as a view of this supplied tree, or as a copy.
        Parameters:
        wrap - if true, the node in the supplied Source is wrapped, to create a view. If false, the node and its contained subtree is copied. If null, the system default is chosen.
      • getWrapDocument

        public java.lang.Boolean getWrapDocument()
        Assuming that the contained Source is a node in a tree, determine whether a tree will be created as a view of this supplied tree, or as a copy.
        Returns:
        if true, the node in the supplied Source is wrapped, to create a view. If false, the node and its contained subtree is copied. If null, the system default is chosen.
        Since:
        8.8
      • setXIncludeAware

        public void setXIncludeAware​(boolean state)

        Set state of XInclude processing.

        If XInclude markup is found in the document instance, should it be processed as specified in XML Inclusions (XInclude) Version 1.0.

        XInclude processing defaults to false.

        Parameters:
        state - Set XInclude processing to true or false
        Since:
        8.9
      • isXIncludeAwareSet

        public boolean isXIncludeAwareSet()

        Determine whether setXIncludeAware() has been called.

        Returns:
        true if setXIncludeAware() has been called
      • isXIncludeAware

        public boolean isXIncludeAware()

        Get state of XInclude processing.

        Returns:
        current state of XInclude processing. Default value is false.
      • setErrorListener

        public void setErrorListener​(javax.xml.transform.ErrorListener listener)
        Set an ErrorListener to be used when parsing
        Parameters:
        listener - the ErrorListener to be used; or null, to indicate that the standard ErrorListener is to be used
      • getErrorListener

        public javax.xml.transform.ErrorListener getErrorListener()
        Get the ErrorListener that will be used when parsing
        Returns:
        the ErrorListener, if one has been set using setErrorListener(javax.xml.transform.ErrorListener), otherwise null.
      • setContinueAfterValidationErrors

        public void setContinueAfterValidationErrors​(boolean keepGoing)
        Say that processing should continue after a validation error (true when the output is a final output)
        Parameters:
        keepGoing - true if processing should continue
      • isContinueAfterValidationErrors

        public boolean isContinueAfterValidationErrors()
        Ask whether processing should continue after a validation error (true when the output is a final output)
        Returns:
        true if processing should continue
      • setAddCommentsAfterValidationErrors

        public void setAddCommentsAfterValidationErrors​(boolean keepGoing)
        Say that on validation errors, messages explaining the error should (where possible) be written as comments in the validated source document. This option is only relevant when processing continues after a validation error
        Parameters:
        keepGoing - true if comments should be added
        Since:
        9.3. Default is now false; in previous releases this option was always on.
      • isAddCommentsAfterValidationErrors

        public boolean isAddCommentsAfterValidationErrors()
        Ask whether on validation errors, messages explaining the error should (where possible) be written as comments in the validated source document. This option is only relevant when processing continues after a validation error
        Returns:
        true if comments should be added
        Since:
        9.3
      • setCheckEntityReferences

        public void setCheckEntityReferences​(boolean check)
        Say whether to check elements and attributes of type xs:ENTITY (or xs:ENTITIES) against the unparsed entities declared in the document's DTD. This is normally true when performing standalone schema validation, false when invoking validation from XSLT or XQuery.
        Parameters:
        check - true if entities are to be checked, false otherwise
      • isCheckEntityReferences

        public boolean isCheckEntityReferences()
        Ask whether to check elements and attributes of type xs:ENTITY (or xs:ENTITIES) against the unparsed entities declared in the document's DTD. This is normally true when performing standalone schema validation, false when invoking validation from XSLT or XQuery.
        Returns:
        true if entities are to be checked, false otherwise
      • setPleaseCloseAfterUse

        public void setPleaseCloseAfterUse​(boolean close)
        Set whether or not the user of this Source is encouraged to close it as soon as reading is finished. Normally the expectation is that any Stream in a StreamSource will be closed by the component that created the Stream. However, in the case of a Source returned by a URIResolver, there is no suitable interface (the URIResolver has no opportunity to close the stream). Also, in some cases such as reading of stylesheet modules, it is possible to close the stream long before control is returned to the caller who supplied it. This tends to make a difference on .NET, where a file often can't be opened if there is a stream attached to it.
        Parameters:
        close - true if the source should be closed as soon as it has been consumed
      • isPleaseCloseAfterUse

        public boolean isPleaseCloseAfterUse()
        Determine whether or not the user of this Source is encouraged to close it as soon as reading is finished.
        Returns:
        true if the source should be closed as soon as it has been consumed
      • close

        public static void close​(javax.xml.transform.Source source)
        Close any resources held by a given Source. This only works if the underlying Source is one that is recognized as holding closable resources.
        Parameters:
        source - the source to be closed
        Since:
        9.2