Package org.vast.xml

Class XMLDocument

java.lang.Object
org.vast.xml.XMLDocument

public class XMLDocument extends Object

Wrapper class for a DOM XML document

Since:
Nov 3, 2005
  • Field Details

    • domImpl

      protected static DOMImplementation domImpl
    • uri

      protected URI uri
      document URI
    • domDocument

      protected Document domDocument
      w3c.Document object
    • identifiers

      protected Map<String,Element> identifiers
      map linking each (local) ID (String) to an Element (w3c.Element)
    • nsUriToPrefix

      protected Map<String,String> nsUriToPrefix
      map linking NS URI (String) to a NS prefix (String)
    • nsPrefixToUri

      protected Map<String,String> nsPrefixToUri
      map linking NS Prefix (String) to a NS URI (String)
  • Constructor Details

  • Method Details

    • addId

      public void addId(String id, Element elt)
      Adds a pair identifier/node in the list
      Parameters:
      id - XML Identifier
      elt - XML Node
    • addNS

      public void addNS(String prefix, String uri)
      Adds mapping from uri to prefix and prefix to uri for further lookups
      Parameters:
      prefix -
      uri -
    • getElementByID

      public Element getElementByID(String id) throws DOMHelperException
      Retrieve a node from the unique ID
      Parameters:
      id - Node identifier
      Returns:
      the corresponding Node object
      Throws:
      DOMHelperException - if no node with the given ID belongs to the document
    • getNSPrefix

      public String getNSPrefix(String nsUri)
      Retrieve a namespace prefix for this document
      Parameters:
      nsUri - namespace domain uri
      Returns:
      the prefix string or null if not found
    • getNSUri

      public String getNSUri(String nsPrefix)
      Retrieves the namespace uri matching the given prefix
      Parameters:
      nsPrefix - namespace prefix string
      Returns:
      the uri or null if not found
    • getNSTable

      public Map<String,String> getNSTable()
      Retrieves the namespace table
      Returns:
      map of namespace prefix to URI
    • getDocument

      public Document getDocument()
      Get the dom document object
      Returns:
      Document object
    • getDocumentElement

      public Element getDocumentElement()
      Get this dom document root element
      Returns:
      Element
    • getUri

      public URI getUri()
      Returns:
      Returns the base uri of the document.
    • setUri

      public void setUri(URI uri)
      Parameters:
      uri - The uri to set as base uri for this document.
    • parseDOM

      protected Document parseDOM(InputStream inputStream, boolean validate, Map<String,String> schemaLocations) throws DOMHelperException
      Parse DOM from given input stream
      Parameters:
      inputStream - Stream containing XML file we want to parse
      validate - boolean if true force the validation process with the schema
      Returns:
      The XMLDocument object created
      Throws:
      DOMHelperException - if a problem occur during parsing
    • parseDOM_LS

      protected Document parseDOM_LS(InputStream inputStream, boolean validate, Map<String,String> schemaLocations) throws DOMHelperException, IOException
      Throws:
      DOMHelperException
      IOException
    • parseDOM_JAXP

      protected Document parseDOM_JAXP(InputStream inputStream, boolean validate, Map<String,String> schemaLocations) throws ParserConfigurationException, IOException, SAXException
      Throws:
      ParserConfigurationException
      IOException
      SAXException
    • serialize

      public void serialize(Node node, OutputStream out, boolean pretty) throws IOException
      Helper method to serialize this DOM to a stream
      Parameters:
      node -
      out -
      pretty - set to true to indent output
      Throws:
      IOException
    • serializeDOM_LS

      protected void serializeDOM_LS(Element elt, OutputStream out, boolean pretty) throws LSException
      Throws:
      LSException
    • serializeDOM_JAXP

      protected void serializeDOM_JAXP(Element elt, OutputStream out, boolean pretty) throws TransformerException
      Throws:
      TransformerException
    • readIdentifiers

      public void readIdentifiers(Element elt, boolean recursive)
      This function looks and stores all identifiers attributes found in the document

      This adds every id it founds to the corresponding hashtable in the given XMLDocument

      This is called recursively for each child node
      Parameters:
      elt - the DOM element where to start the search
      recursive - if true, all children elements are also processed recursively
    • readNamespaces

      public void readNamespaces(Element elt, boolean recursive)
      Reads all the namespace prefix:domain pairs and store them in the hashtable of the XMLDocument
      Parameters:
      elt - the DOM element where to start the search
      recursive - if true, all children elements are also processed recursively