Package com.oss.asn1

Class XERDocument

java.lang.Object
com.oss.asn1.XERDocument

public final class XERDocument extends Object
The XERDocument class helps to customize XML output generated by the XERCoder class. It allows the following customizations:
    - include or exclude the XML preamble <?xml version="1.0" encoding="UTF-8"?>
    - include link to XML stylesheet
    - include link to DTD
    - control formatting (verbose XML for better readability or compact
      XML for smaller size of encoding)
    
Since:
ASN.1/Java 2.0-beta A
  • Constructor Summary

    Constructors
    Constructor
    Description
    XERDocument(XERCoder coder, AbstractData rootElement)
    Constructs XERDocument from a XERCoder and an AbstractData value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Add whitespace as necessary to improve readability In the compact mode the encoding is written without any whitespace as a single line of text.
    void
    Do not generate whitespace into the XML document.
    void
    Do not include link to the DTD into the document
    void
    Initial XML declaration is excluded from the XML document
    void
    Do not include link to the stylesheet into the document
    com.oss.util.XMLDoctype
    Get the XMLDoctype (information about DOCTYPE element)
    int
    Get the number of spaces allocated for indenting
    Get the root element of the XML as represented by a data value
    com.oss.util.XMLStylesheet
    Get the current setting for the stylesheet
    void
    Include link to the DTD, taking the XMLDoctype from the root element data value
    void
    includeDTD(com.oss.util.XMLDoctype dtd)
    Include link to the DTD specified by the dtd parameter
    void
    Make the XML document contain the initial XML declaration
    void
    Include link to the stylesheet, taking the XMLStylesheet from the root element data value
    void
    includeStylesheet(com.oss.util.XMLStylesheet styleSheet)
    Include link to the stylesheet specified by the styleSheet parameter
    void
    setIndentWidth(int width)
    Set indentation width for generating whitespace
    void
    Set abstract value which represents the document
    void
    Send the document to the output stream.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • XERDocument

      public XERDocument(XERCoder coder, AbstractData rootElement)
      Constructs XERDocument from a XERCoder and an AbstractData value.

      Upon construction the XML document includes:

      • an XML preamble,
      • links to a stylesheet, and
      • DTD if OSS.Stylesheet and OSS.DTD directives were used for the root element abstract value at ASN.1 compile time.
      By default the XML document does not use compact encoding (whitespace is included). Also by default, the indentation width is set to 2.
      Parameters:
      coder - coder used to generate XML output
      rootElement - data value which represents root element of the XML document
  • Method Details

    • includePreamble

      public void includePreamble()
      Make the XML document contain the initial XML declaration
    • excludePreamble

      public void excludePreamble()
      Initial XML declaration is excluded from the XML document
    • includeStylesheet

      public void includeStylesheet(com.oss.util.XMLStylesheet styleSheet)
      Include link to the stylesheet specified by the styleSheet parameter
      Parameters:
      styleSheet - XMLStylesheet to generate link to be included into the XML document
    • getStylesheet

      public com.oss.util.XMLStylesheet getStylesheet()
      Get the current setting for the stylesheet
      Returns:
      current setting for the stylesheet (null for no stylesheet)
    • excludeStylesheet

      public void excludeStylesheet()
      Do not include link to the stylesheet into the document
    • includeStylesheet

      public void includeStylesheet()
      Include link to the stylesheet, taking the XMLStylesheet from the root element data value
    • includeDTD

      public void includeDTD(com.oss.util.XMLDoctype dtd)
      Include link to the DTD specified by the dtd parameter
      Parameters:
      dtd - XMLDoctype to generate link to be included into the XML document
    • getDTD

      public com.oss.util.XMLDoctype getDTD()
      Get the XMLDoctype (information about DOCTYPE element)
      Returns:
      current setting for the DTD (null for no DTD)
    • excludeDTD

      public void excludeDTD()
      Do not include link to the DTD into the document
    • includeDTD

      public void includeDTD()
      Include link to the DTD, taking the XMLDoctype from the root element data value
    • setRootElement

      public void setRootElement(AbstractData value)
      Set abstract value which represents the document
      Parameters:
      value - data value which represents root element of the XML document
    • getRootElement

      public AbstractData getRootElement()
      Get the root element of the XML as represented by a data value
      Returns:
      data value which represents the root element of the XML document
    • enableCompact

      public void enableCompact()
      Do not generate whitespace into the XML document. In the compact mode the encoding is written without any whitespace as a single line of text. If the compact mode is disabled newlines are inserted as necessary and the indentation is applied.
    • disableCompact

      public void disableCompact()
      Add whitespace as necessary to improve readability In the compact mode the encoding is written without any whitespace as a single line of text. If the compact mode is disabled newlines are inserted as necessary and the indentation is applied.
    • setIndentWidth

      public void setIndentWidth(int width)
      Set indentation width for generating whitespace
      Parameters:
      width - number of spaces for indenting
    • getIndentWidth

      public int getIndentWidth()
      Get the number of spaces allocated for indenting
      Returns:
      indentation width setting
    • writeTo

      Send the document to the output stream. The document is written as follows: XML preamble (if enabled), DOCTYPE element (if enabled), the stylesheet processing instruction (if enabled), XER encoding of the root element. In compact mode the encoding is written without any whitespace as a single line of text. If compact mode is disabled newlines are inserted as necessary and indentation is applied.
      Parameters:
      sink - the output stream to write this document to
      Throws:
      EncodeNotSupportedException - if encoding is not supported for the specified element.
      EncodeFailedException - if an error occurs while encoding.
      IOException - if an I/O error occurs.