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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description 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 Nodeprotected Map<String,Set<String>>
mDuplicatePrefixesByUri
Contains only the duplicate prefix.protected OdfPackage
mPackage
protected OdfPackageDocument
mPackageDocument
protected String
mPackagePath
protected Map<String,String>
mPrefixByUri
protected Map<String,String>
mUriByPrefix
protected XPath
mXPath
protected JenaSink
sink
-
Fields inherited from class org.apache.xerces.dom.DocumentImpl
eventListeners, iteratorReferenceQueue, iterators, mutationEvents, rangeReferenceQueue, ranges
-
Fields inherited from class org.apache.xerces.dom.CoreDocumentImpl
actualEncoding, allowGrammarAccess, changes, docElement, docType, encoding, errorChecking, fDocumentURI, identifiers, standalone, userData, version, xmlVersionChanged
-
Fields inherited from class org.apache.xerces.dom.ParentNode
firstChild, fNodeListCache, ownerDocument
-
Fields inherited from class org.apache.xerces.dom.ChildNode
nextSibling, previousSibling
-
Fields inherited from class org.apache.xerces.dom.NodeImpl
DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_IS_CONTAINED, DOCUMENT_POSITION_PRECEDING, ELEMENT_DEFINITION_NODE, FIRSTCHILD, flags, HASSTRING, ID, IGNORABLEWS, NORMALIZED, OWNED, ownerNode, READONLY, SPECIFIED, SYNCCHILDREN, SYNCDATA, TREE_POSITION_ANCESTOR, TREE_POSITION_DESCENDANT, TREE_POSITION_DISCONNECTED, TREE_POSITION_EQUIVALENT, TREE_POSITION_FOLLOWING, TREE_POSITION_PRECEDING, TREE_POSITION_SAME_NODE
-
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OdfFileDom(OdfPackageDocument packageDocument, String packagePath)
Creates the DOM representation of an XML file of an ODF document.protected
OdfFileDom(OdfPackage pkg, String packagePath)
Creates the DOM representation of an XML file of an Odf document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OdfAttribute
createAttribute(String name)
Create the ODF attribute with its nameOdfAttribute
createAttributeNS(String nsuri, String qname)
Create the ODF attribute with namespace uri and qnameOdfAttribute
createAttributeNS(OdfName name)
Create the ODF attribute with ODF nameOdfElement
createElement(String name)
Create ODF element with namespace uri and qnameOdfElement
createElementNS(String nsuri, String qname)
Create ODF element with namespace uri and qnameOdfElement
createElementNS(OdfName name)
Create ODF element with ODF nameorg.apache.jena.rdf.model.Model
getBookmarkRDFMetadata()
OdfPackageDocument
getDocument()
Retrieves theOdfPackageDocument
of the XML file.Map<Node,org.apache.jena.rdf.model.Model>
getInContentMetadataCache()
Get in-content metadata cache modelString
getNamespaceURI(String prefix)
Get Namespace URI bound to a prefix in the current scope (the XML file).String
getNextMarkupId()
String
getPackagePath()
Retrieves theString
of Package PathString
getPrefix(String namespaceURI)
Get prefix bound to Namespace URI in the current scope (the XML file).Iterator<String>
getPrefixes(String namespaceURI)
Get all prefixes bound to a Namespace URI in the current scope.OdfElement
getRootElement()
Retrieves the ODF root element.JenaSink
getSink()
The end users needn't to care of this method, which is used by BookmarkRDFMetadataExtractorXPath
getXPath()
Create an XPath instance to select one or more nodes from an ODF document.protected void
initialize()
protected void
initialize(DefaultHandler handler, OdfFileDom dom)
static OdfFileDom
newFileDom(OdfPackage pkg, String packagePath)
<T extends OdfElement>
TnewOdfElement(Class<T> clazz)
OdfNamespace
setNamespace(String prefix, String uri)
Adds a new Namespace to the DOM.OdfNamespace
setNamespace(NamespaceName name)
Adds a new Namespace to the DOM.String
toString()
void
updateInContentMetadataCache(Node node)
Update the in content metadata of the node.-
Methods inherited from class org.apache.xerces.dom.DocumentImpl
addEventListener, cloneNode, copyEventListeners, createEvent, createNodeIterator, createNodeIterator, createRange, createTreeWalker, createTreeWalker, dispatchAggregateEvents, dispatchAggregateEvents, dispatchEvent, dispatchEventToSubtree, dispatchingEventToSubtree, getEventListeners, getImplementation, removeEventListener, saveEnclosingAttr, setEventListeners
-
Methods inherited from class org.apache.xerces.dom.CoreDocumentImpl
abort, adoptNode, callUserDataHandlers, canRenameElements, changed, changes, checkDOMNSErr, checkNamespaceWF, checkQName, clearIdentifiers, clone, cloneNode, createAttributeNS, createCDATASection, createComment, createDocumentFragment, createDocumentType, createElementDefinition, createElementNS, createEntity, createEntityReference, createNotation, createProcessingInstruction, createTextNode, getAsync, getBaseURI, getDoctype, getDocumentElement, getDocumentURI, getDomConfig, getElementById, getElementsByTagName, getElementsByTagNameNS, getEncoding, getErrorChecking, getFeature, getIdentifier, getIdentifiers, getInputEncoding, getNodeName, getNodeNumber, getNodeNumber, getNodeType, getOwnerDocument, getStandalone, getStrictErrorChecking, getTextContent, getUserData, getUserData, getUserDataRecord, getVersion, getXmlEncoding, getXmlStandalone, getXmlVersion, importNode, insertBefore, isKidOK, isValidQName, isXMLName, load, loadXML, normalizeDocument, putIdentifier, removeChild, removeIdentifier, renameNode, replaceChild, saveXML, setAsync, setDocumentURI, setEncoding, setErrorChecking, setInputEncoding, setStandalone, setStrictErrorChecking, setTextContent, setUserData, setUserData, setVersion, setXmlEncoding, setXmlStandalone, setXmlVersion, undeferChildren
-
Methods inherited from class org.apache.xerces.dom.ParentNode
getChildNodes, getChildNodesUnoptimized, getFirstChild, getLastChild, getLength, hasChildNodes, isEqualNode, item, normalize, setOwnerDocument, setReadOnly, synchronizeChildren
-
Methods inherited from class org.apache.xerces.dom.ChildNode
getNextSibling, getParentNode, getPreviousSibling
-
Methods inherited from class org.apache.xerces.dom.NodeImpl
addEventListener, appendChild, compareDocumentPosition, compareTreePosition, dispatchEvent, getAttributes, getContainer, getLocalName, getNamespaceURI, getNodeValue, getPrefix, getReadOnly, getUserData, getUserData, getUserDataRecord, hasAttributes, isDefaultNamespace, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, needsSyncChildren, removeEventListener, setNodeValue, setPrefix, setUserData, setUserData, synchronizeData
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.w3c.dom.Node
appendChild, compareDocumentPosition, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getParentNode, getPrefix, getPreviousSibling, getUserData, hasAttributes, hasChildNodes, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, setNodeValue, setPrefix, setUserData
-
-
-
-
Field Detail
-
mPackagePath
protected String mPackagePath
-
mPackageDocument
protected OdfPackageDocument mPackageDocument
-
mPackage
protected OdfPackage mPackage
-
mXPath
protected XPath mXPath
-
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 Detail
-
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 topackagePath
- 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 topackagePath
- the internal package path to the XML file
-
-
Method Detail
-
newFileDom
public static OdfFileDom newFileDom(OdfPackage pkg, String packagePath)
-
initialize
protected void initialize() throws SAXException, IOException, ParserConfigurationException
-
initialize
protected void initialize(DefaultHandler handler, OdfFileDom dom) throws SAXException, IOException, ParserConfigurationException
-
getDocument
public OdfPackageDocument getDocument()
Retrieves theOdfPackageDocument
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 theString
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 interfaceDocument
- Overrides:
createElement
in classCoreDocumentImpl
- 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 interfaceDocument
- Overrides:
createElementNS
in classCoreDocumentImpl
- Parameters:
nsuri
- The namespace uriqname
- The element qname- Throws:
DOMException
-
createElementNS
public OdfElement createElementNS(OdfName name) throws DOMException
Create ODF element with ODF name- Parameters:
name
- TheOdfName
- Returns:
- The
OdfElement
- Throws:
DOMException
-
createAttribute
public OdfAttribute createAttribute(String name) throws DOMException
Create the ODF attribute with its name- Specified by:
createAttribute
in interfaceDocument
- Overrides:
createAttribute
in classCoreDocumentImpl
- 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 interfaceDocument
- Overrides:
createAttributeNS
in classCoreDocumentImpl
- Parameters:
nsuri
- The namespace uriqname
- 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
- TheOdfName
- Returns:
- The
OdfAttribute
- Throws:
DOMException
-
newOdfElement
public <T extends OdfElement> T newOdfElement(Class<T> clazz)
-
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 prefixesprefix parameter Namespace URI return value DEFAULT_NS_PREFIX
("")default Namespace URI in the current scope or
when there is no default Namespace URI in the current scopeXMLConstants.NULL_NS_URI("")
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 interfaceNamespaceContext
- Parameters:
prefix
- prefix to look up- Returns:
- Namespace URI bound to prefix in the current scope
- Throws:
IllegalArgumentException
- Whenprefix
isnull
-
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 URIsNamespace 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 interfaceNamespaceContext
- Parameters:
namespaceURI
- URI of Namespace to lookup- Returns:
- prefix bound to Namespace URI in current context
- Throws:
IllegalArgumentException
- WhennamespaceURI
isnull
-
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. theremove()
method will throwUnsupportedOperationException
.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 URIsNamespace 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, orderunbound Namespace URI empty Iterator
XMLConstants.XML_NS_URI
("http://www.w3.org/XML/1998/namespace")Iterator
with one element set toXMLConstants.XML_NS_PREFIX
("xml")XMLConstants.XMLNS_ATTRIBUTE_NS_URI
("http://www.w3.org/2000/xmlns/")Iterator
with one element set toXMLConstants.XMLNS_ATTRIBUTE
("xmlns")null
IllegalArgumentException
is thrown- Specified by:
getPrefixes
in interfaceNamespaceContext
- Parameters:
namespaceURI
- URI of Namespace to lookup- Returns:
Iterator
for all prefixes bound to the Namespace URI in the current scope- Throws:
IllegalArgumentException
- WhennamespaceURI
isnull
-
setNamespace
public OdfNamespace setNamespace(String prefix, String uri)
Adds a new Namespace to the DOM. Making the prefix usable with JDKXPath
. All namespace attributes will be written to the root element during later serialization of the DOM by theOdfPackage
.- Parameters:
prefix
- of the namespace to be set to this DOMuri
- 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 JDKXPath
. All namespace attributes will be written to the root element during later serialization of the DOM by theOdfPackage
.- 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)
-
-