Class OdfFileDom

All Implemented Interfaces:
Serializable, Cloneable, NamespaceContext, Document, DocumentEvent, EventTarget, Node, NodeList, DocumentRange, DocumentTraversal
Direct Known Subclasses:
OdfContentOrStylesDomBase, OdfManifestDom, OdfMetaDom, OdfSettingsDom

public class OdfFileDom extends DocumentImpl implements NamespaceContext
The DOM representation of an XML file within the ODF document.
See Also:
  • Field Details

    • mPackagePath

      protected String mPackagePath
    • mPackageDocument

      protected OdfPackageDocument mPackageDocument
    • mPackage

      protected OdfPackage mPackage
    • mXPath

      protected XPath mXPath
    • mUriByPrefix

      protected Map<String,String> mUriByPrefix
    • mPrefixByUri

      protected Map<String,String> mPrefixByUri
    • mDuplicatePrefixesByUri

      protected Map<String,Set<String>> mDuplicatePrefixesByUri
      Contains only the duplicate prefix. The primary hold by mPrefixByUri still have to be added
    • inCententMetadataCache

      protected Map<Node,org.apache.jena.rdf.model.Model> inCententMetadataCache
      The cache of in content metadata: key: a Node in the dom ; value: the Jena RDF model of triples of the Node
    • sink

      protected JenaSink sink
  • Constructor Details

    • OdfFileDom

      protected OdfFileDom(OdfPackageDocument packageDocument, String packagePath)
      Creates the DOM representation of an XML file of an ODF document.
      Parameters:
      packageDocument - the document the XML files belongs to
      packagePath - the internal package path to the XML file
    • OdfFileDom

      protected OdfFileDom(OdfPackage pkg, String packagePath)
      Creates the DOM representation of an XML file of an Odf document.
      Parameters:
      pkg - the package the XML files belongs to
      packagePath - the internal package path to the XML file
  • Method Details

    • newFileDom

      public static OdfFileDom newFileDom(OdfPackage pkg, String packagePath)
    • initialize

      protected void initialize() throws SAXException, IOException, ParserConfigurationException
      Throws:
      SAXException
      IOException
      ParserConfigurationException
    • initialize

      protected void initialize(DefaultHandler handler, OdfFileDom dom) throws SAXException, IOException, ParserConfigurationException
      Throws:
      SAXException
      IOException
      ParserConfigurationException
    • getDocument

      public OdfPackageDocument getDocument()
      Retrieves the OdfPackageDocument of the XML file. A package document is usually represented as a directory with a media type.
      Returns:
      The document holding the XML file.
    • getPackagePath

      public String getPackagePath()
      Retrieves the String of Package Path
      Returns:
      The path of the XML file relative to the package root
    • getRootElement

      public OdfElement getRootElement()
      Retrieves the ODF root element.
      Returns:
      The OdfElement being the root of the document.
    • createElement

      public OdfElement createElement(String name) throws DOMException
      Create ODF element with namespace uri and qname
      Specified by:
      createElement in interface Document
      Overrides:
      createElement in class CoreDocumentImpl
      Parameters:
      name - The element name
      Throws:
      DOMException
    • createElementNS

      public OdfElement createElementNS(String nsuri, String qname) throws DOMException
      Create ODF element with namespace uri and qname
      Specified by:
      createElementNS in interface Document
      Overrides:
      createElementNS in class CoreDocumentImpl
      Parameters:
      nsuri - The namespace uri
      qname - The element qname
      Throws:
      DOMException
    • createElementNS

      public OdfElement createElementNS(OdfName name) throws DOMException
      Create ODF element with ODF name
      Parameters:
      name - The OdfName
      Returns:
      The OdfElement
      Throws:
      DOMException
    • createAttribute

      public OdfAttribute createAttribute(String name) throws DOMException
      Create the ODF attribute with its name
      Specified by:
      createAttribute in interface Document
      Overrides:
      createAttribute in class CoreDocumentImpl
      Parameters:
      name - the attribute qname
      Returns:
      The OdfAttribute
      Throws:
      DOMException
    • createAttributeNS

      public OdfAttribute createAttributeNS(String nsuri, String qname) throws DOMException
      Create the ODF attribute with namespace uri and qname
      Specified by:
      createAttributeNS in interface Document
      Overrides:
      createAttributeNS in class CoreDocumentImpl
      Parameters:
      nsuri - The namespace uri
      qname - the attribute qname
      Returns:
      The OdfAttribute
      Throws:
      DOMException
    • createAttributeNS

      public OdfAttribute createAttributeNS(OdfName name) throws DOMException
      Create the ODF attribute with ODF name
      Parameters:
      name - The OdfName
      Returns:
      The OdfAttribute
      Throws:
      DOMException
    • newOdfElement

      public <T extends OdfElement> T newOdfElement(Class<T> clazz)
    • toString

      public String toString()
      Overrides:
      toString in class NodeImpl
    • getXPath

      public XPath getXPath()
      Create an XPath instance to select one or more nodes from an ODF document. Therefore the namespace context is set to the OdfNamespace
      Returns:
      an XPath instance with namespace context set to include the standard ODFDOM prefixes.
    • getNamespaceURI

      public String getNamespaceURI(String prefix)
      Get Namespace URI bound to a prefix in the current scope (the XML file).

      When requesting a Namespace URI by prefix, the following table describes the returned Namespace URI value for all possible prefix values:

      getNamespaceURI(prefix) return value for specified prefixes
      prefix parameter Namespace URI return value
      DEFAULT_NS_PREFIX ("") default Namespace URI in the current scope or XMLConstants.NULL_NS_URI("") when there is no default Namespace URI in the current scope
      bound prefix Namespace URI bound to prefix in current scope
      unbound prefix XMLConstants.NULL_NS_URI("")
      XMLConstants.XML_NS_PREFIX ("xml") XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace")
      XMLConstants.XMLNS_ATTRIBUTE ("xmlns") XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/")
      null IllegalArgumentException is thrown
      Specified by:
      getNamespaceURI in interface NamespaceContext
      Parameters:
      prefix - prefix to look up
      Returns:
      Namespace URI bound to prefix in the current scope
      Throws:
      IllegalArgumentException - When prefix is null
    • getPrefix

      public String getPrefix(String namespaceURI)
      Get prefix bound to Namespace URI in the current scope (the XML file).

      Multiple prefixes bound to Namespace URI will be normalized to the first prefix defined.

      When requesting a prefix by Namespace URI, the following table describes the returned prefix value for all Namespace URI values:

      getPrefix(namespaceURI) return value for specified Namespace URIs
      Namespace URI parameter prefix value returned
      <default Namespace URI> XMLConstants.DEFAULT_NS_PREFIX ("")
      bound Namespace URI prefix bound to Namespace URI in the current scope, if multiple prefixes are bound to the Namespace URI in the current scope, a single arbitrary prefix, whose choice is implementation dependent, is returned
      unbound Namespace URI null
      XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") XMLConstants.XML_NS_PREFIX ("xml")
      XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
      null IllegalArgumentException is thrown
      Specified by:
      getPrefix in interface NamespaceContext
      Parameters:
      namespaceURI - URI of Namespace to lookup
      Returns:
      prefix bound to Namespace URI in current context
      Throws:
      IllegalArgumentException - When namespaceURI is null
    • getPrefixes

      public Iterator<String> getPrefixes(String namespaceURI)
      Get all prefixes bound to a Namespace URI in the current scope. (the XML file)

      NOTE: Multiple prefixes bound to a similar Namespace URI will be normalized to the first prefix defined. Still the namespace attributes exist in the XML as inner value prefixes might be used.

      The Iterator is not modifiable. e.g. the remove() method will throw UnsupportedOperationException.

      When requesting prefixes by Namespace URI, the following table describes the returned prefixes value for all Namespace URI values:

      getPrefixes(namespaceURI) return value for specified Namespace URIs
      Namespace URI parameter prefixes value returned
      bound Namespace URI, including the <default Namespace URI> Iterator over prefixes bound to Namespace URI in the current scope in an arbitrary, implementation dependent, order
      unbound Namespace URI empty Iterator
      XMLConstants.XML_NS_URI ("http://www.w3.org/XML/1998/namespace") Iterator with one element set to XMLConstants.XML_NS_PREFIX ("xml")
      XMLConstants.XMLNS_ATTRIBUTE_NS_URI ("http://www.w3.org/2000/xmlns/") Iterator with one element set to XMLConstants.XMLNS_ATTRIBUTE ("xmlns")
      null IllegalArgumentException is thrown
      Specified by:
      getPrefixes in interface NamespaceContext
      Parameters:
      namespaceURI - URI of Namespace to lookup
      Returns:
      Iterator for all prefixes bound to the Namespace URI in the current scope
      Throws:
      IllegalArgumentException - When namespaceURI is null
    • setNamespace

      public OdfNamespace setNamespace(String prefix, String uri)
      Adds a new Namespace to the DOM. Making the prefix usable with JDK XPath. All namespace attributes will be written to the root element during later serialization of the DOM by the OdfPackage.
      Parameters:
      prefix - of the namespace to be set to this DOM
      uri - of the namespace to be set to this DOM
      Returns:
      the namespace that was set. If an URI was registered before to the DOM, the previous prefix will be taken. In case of a given prefix that was already registered, but related to a new URI, the prefix will be adapted. The new prefix receives the suffix '__' plus integer, e.g. "__1" for the first duplicate and "__2" for the second.
    • setNamespace

      public OdfNamespace setNamespace(NamespaceName name)
      Adds a new Namespace to the DOM. Making the prefix usable with JDK XPath. All namespace attributes will be written to the root element during later serialization of the DOM by the OdfPackage.
      Parameters:
      name - the namespace to be set
      Returns:
      the namespace that was set. If an URI was registered before to the DOM, the previous prefix will be taken. In case of a given prefix that was already registered, but related to a new URI, the prefix will be adapted. The new prefix receives the suffix '__' plus integer, e.g. "__1" for the first duplicate and "__2" for the second.
    • getInContentMetadataCache

      public Map<Node,org.apache.jena.rdf.model.Model> getInContentMetadataCache()
      Get in-content metadata cache model
      Returns:
      in-content metadata cache model
    • updateInContentMetadataCache

      public void updateInContentMetadataCache(Node node)
      Update the in content metadata of the node. It should be called whenever the xhtml:xxx attributes values of the node are changed.
      Parameters:
      the - node, whose in content metadata will be updated
    • getBookmarkRDFMetadata

      public org.apache.jena.rdf.model.Model getBookmarkRDFMetadata()
      Returns:
      the RDF metadata of all the bookmarks within the dom
    • getSink

      public JenaSink getSink()
      The end users needn't to care of this method, which is used by BookmarkRDFMetadataExtractor
      Returns:
      the JenaSink
    • getNextMarkupId

      public String getNextMarkupId()
      Returns:
      counter for ids that are not allowed to be saved (otherwise it is not guaranteed that this id is unique)