| Method from org.apache.xerces.dom.CoreDocumentImpl Detail: |
public void abort() {
}
DOM Level 3 WD - Experimental.
If the document is currently being loaded as a result of the method
load being invoked the loading and parsing is
immediately aborted. The possibly partial result of parsing the
document is discarded and the document is cleared. |
protected void addEventListener(NodeImpl node,
String type,
EventListener listener,
boolean useCapture) {
// does nothing by default - overidden in subclass
}
|
public Node adoptNode(Node source) {
NodeImpl node;
Hashtable userData = null;
try {
node = (NodeImpl) source;
} catch (ClassCastException e) {
// source node comes from a different DOMImplementation
return null;
}
// Return null if the source is null
if (source == null ) {
return null;
} else if (source != null && source.getOwnerDocument() != null) {
DOMImplementation thisImpl = this.getImplementation();
DOMImplementation otherImpl = source.getOwnerDocument().getImplementation();
// when the source node comes from a different implementation.
if (thisImpl != otherImpl) {
// Adopting from a DefferedDOM to DOM
if (thisImpl instanceof org.apache.xerces.dom.DOMImplementationImpl &&
otherImpl instanceof org.apache.xerces.dom.DeferredDOMImplementationImpl) {
// traverse the DOM and expand deffered nodes and then allow adoption
undeferChildren (node);
} else if ( thisImpl instanceof org.apache.xerces.dom.DeferredDOMImplementationImpl
&& otherImpl instanceof org.apache.xerces.dom.DOMImplementationImpl) {
// Adopting from a DOM into a DefferedDOM, this should be okay
} else {
// Adopting between two dissimilar DOM's is not allowed
return null;
}
}
}
switch (node.getNodeType()) {
case ATTRIBUTE_NODE: {
AttrImpl attr = (AttrImpl) node;
// remove node from wherever it is
if( attr.getOwnerElement() != null){
//1. owner element attribute is set to null
attr.getOwnerElement().removeAttributeNode(attr);
}
//2. specified flag is set to true
attr.isSpecified(true);
userData = node.getUserDataRecord();
//3. change ownership
attr.setOwnerDocument(this);
if(userData != null )
setUserDataTable(node,userData);
break;
}
//entity, notation nodes are read only nodes.. so they can't be adopted.
//runtime will fall through to NOTATION_NODE
case ENTITY_NODE:
case NOTATION_NODE:{
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg);
}
//document, documentype nodes can't be adopted.
//runtime will fall through to DocumentTypeNode
case DOCUMENT_NODE:
case DOCUMENT_TYPE_NODE: {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
case ENTITY_REFERENCE_NODE: {
userData = node.getUserDataRecord();
// remove node from wherever it is
Node parent = node.getParentNode();
if (parent != null) {
parent.removeChild(source);
}
// discard its replacement value
Node child;
while ((child = node.getFirstChild()) != null) {
node.removeChild(child);
}
// change ownership
node.setOwnerDocument(this);
if(userData != null)
setUserDataTable(node,userData);
// set its new replacement value if any
if (docType == null) {
break;
}
NamedNodeMap entities = docType.getEntities();
Node entityNode = entities.getNamedItem(node.getNodeName());
if (entityNode == null) {
break;
}
for (child = entityNode.getFirstChild();
child != null; child = child.getNextSibling()) {
Node childClone = child.cloneNode(true);
node.appendChild(childClone);
}
break;
}
case ELEMENT_NODE: {
userData = node.getUserDataRecord();
// remove node from wherever it is
Node parent = node.getParentNode();
if (parent != null) {
parent.removeChild(source);
}
// change ownership
node.setOwnerDocument(this);
if(userData != null)
setUserDataTable(node,userData);
// reconcile default attributes
((ElementImpl)node).reconcileDefaultAttributes();
break;
}
default: {
userData = node.getUserDataRecord();
// remove node from wherever it is
Node parent = node.getParentNode();
if (parent != null) {
parent.removeChild(source);
}
// change ownership
node.setOwnerDocument(this);
if(userData != null)
setUserDataTable(node,userData);
}
}
//DOM L3 Core CR
//http://www.w3.org/TR/2003/CR-DOM-Level-3-Core-20031107/core.html#UserDataHandler-ADOPTED
if(userData != null)
callUserDataHandlers(source, null, UserDataHandler.NODE_ADOPTED,userData);
return node;
}
DOM Level 3 WD - Experimental
Change the node's ownerDocument, and its subtree, to this Document |
protected void callUserDataHandlers(Node n,
Node c,
short operation) {
if (userData == null) {
return;
}
//Hashtable t = (Hashtable) userData.get(n);
if(n instanceof NodeImpl){
Hashtable t = ((NodeImpl)n).getUserDataRecord();
if (t == null || t.isEmpty()) {
return;
}
callUserDataHandlers(n, c, operation,t);
}
}
Call user data handlers when a node is deleted (finalized) |
void callUserDataHandlers(Node n,
Node c,
short operation,
Hashtable userData) {
if (userData == null || userData.isEmpty()) {
return;
}
Enumeration keys = userData.keys();
while (keys.hasMoreElements()) {
String key = (String) keys.nextElement();
UserDataRecord r = (UserDataRecord) userData.get(key);
if (r.fHandler != null) {
r.fHandler.handle(operation, key, r.fData, n, c);
}
}
}
Call user data handlers when a node is deleted (finalized) |
protected void changed() {
changes++;
}
Denotes that this node has changed. |
protected int changes() {
return changes;
}
Returns the number of changes to this node. |
protected final void checkDOMNSErr(String prefix,
String namespace) {
if (errorChecking) {
if (namespace == null) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
else if (prefix.equals("xml")
&& !namespace.equals(NamespaceContext.XML_URI)) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
else if (
prefix.equals("xmlns")
&& !namespace.equals(NamespaceContext.XMLNS_URI)
|| (!prefix.equals("xmlns")
&& namespace.equals(NamespaceContext.XMLNS_URI))) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
}
|
protected final void checkNamespaceWF(String qname,
int colon1,
int colon2) {
if (!errorChecking) {
return;
}
// it is an error for NCName to have more than one ':'
// check if it is valid QName [Namespace in XML production 6]
// :camera , nikon:camera:minolta, camera:
if (colon1 == 0 || colon1 == qname.length() - 1 || colon2 != colon1) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
}
Call user data handlers to let them know the nodes they are related to
are being deleted. The alternative would be to do that on Node but
because the nodes are used as the keys we have a reference to them that
prevents them from being gc'ed until the document is. At the same time,
doing it here has the advantage of avoiding a finalize() method on Node,
which would affect all nodes and not just the ones that have a user
data. |
protected final void checkQName(String prefix,
String local) {
if (!errorChecking) {
return;
}
// check that both prefix and local part match NCName
boolean validNCName = false;
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
&& XMLChar.isValidNCName(local);
}
else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
&& XML11Char.isXML11ValidNCName(local);
}
if (!validNCName) {
// REVISIT: add qname parameter to the message
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR",
null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
}
Checks if the given qualified name is legal with respect
to the version of XML to which this document must conform. |
protected final void clearIdentifiers() {
if (identifiers != null){
identifiers.clear();
}
}
Remove all identifiers from the ID table |
public Object clone() throws CloneNotSupportedException {
CoreDocumentImpl newdoc = (CoreDocumentImpl) super.clone();
newdoc.docType = null;
newdoc.docElement = null;
return newdoc;
}
|
public Node cloneNode(boolean deep) {
CoreDocumentImpl newdoc = new CoreDocumentImpl();
callUserDataHandlers(this, newdoc, UserDataHandler.NODE_CLONED);
cloneNode(newdoc, deep);
return newdoc;
}
Deep-clone a document, including fixing ownerDoc for the cloned
children. Note that this requires bypassing the WRONG_DOCUMENT_ERR
protection. I've chosen to implement it by calling importNode
which is DOM Level 2. |
protected void cloneNode(CoreDocumentImpl newdoc,
boolean deep) {
// clone the children by importing them
if (needsSyncChildren()) {
synchronizeChildren();
}
if (deep) {
Hashtable reversedIdentifiers = null;
if (identifiers != null) {
// Build a reverse mapping from element to identifier.
reversedIdentifiers = new Hashtable();
Enumeration elementIds = identifiers.keys();
while (elementIds.hasMoreElements()) {
Object elementId = elementIds.nextElement();
reversedIdentifiers.put(identifiers.get(elementId),
elementId);
}
}
// Copy children into new document.
for (ChildNode kid = firstChild; kid != null;
kid = kid.nextSibling) {
newdoc.appendChild(newdoc.importNode(kid, true, true,
reversedIdentifiers));
}
}
// experimental
newdoc.allowGrammarAccess = allowGrammarAccess;
newdoc.errorChecking = errorChecking;
}
internal method to share code with subclass |
protected void copyEventListeners(NodeImpl src,
NodeImpl tgt) {
// does nothing by default - overidden in subclass
}
|
public Attr createAttribute(String name) throws DOMException {
if (errorChecking && !isXMLName(name,xml11Version)) {
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR",
null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new AttrImpl(this, name);
}
Factory method; creates an Attribute having this Document as its
OwnerDoc. |
public Attr createAttributeNS(String namespaceURI,
String qualifiedName) throws DOMException {
return new AttrNSImpl(this, namespaceURI, qualifiedName);
}
Introduced in DOM Level 2.
Creates an attribute of the given qualified name and namespace URI.
If the given namespaceURI is null or an empty string and the
qualifiedName has a prefix that is "xml", the created element
is bound to the predefined namespace
"http://www.w3.org/XML/1998/namespace" [Namespaces]. |
public Attr createAttributeNS(String namespaceURI,
String qualifiedName,
String localpart) throws DOMException {
return new AttrNSImpl(this, namespaceURI, qualifiedName, localpart);
}
NON-DOM: a factory method used by the Xerces DOM parser
to create an element. |
public CDATASection createCDATASection(String data) throws DOMException {
return new CDATASectionImpl(this, data);
}
Factory method; creates a CDATASection having this Document as
its OwnerDoc. |
public Comment createComment(String data) {
return new CommentImpl(this, data);
}
Factory method; creates a Comment having this Document as its
OwnerDoc. |
public DocumentFragment createDocumentFragment() {
return new DocumentFragmentImpl(this);
}
Factory method; creates a DocumentFragment having this Document
as its OwnerDoc. |
public DocumentType createDocumentType(String qualifiedName,
String publicID,
String systemID) throws DOMException {
return new DocumentTypeImpl(this, qualifiedName, publicID, systemID);
}
NON-DOM
Factory method; creates a DocumentType having this Document
as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
DTD information unspecified.) |
public Element createElement(String tagName) throws DOMException {
if (errorChecking && !isXMLName(tagName,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new ElementImpl(this, tagName);
}
Factory method; creates an Element having this Document
as its OwnerDoc. |
public ElementDefinitionImpl createElementDefinition(String name) throws DOMException {
if (errorChecking && !isXMLName(name,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new ElementDefinitionImpl(this, name);
}
NON-DOM Factory method: creates an element definition. Element
definitions hold default attribute values. |
public Element createElementNS(String namespaceURI,
String qualifiedName) throws DOMException {
return new ElementNSImpl(this, namespaceURI, qualifiedName);
}
Introduced in DOM Level 2.
Creates an element of the given qualified name and namespace URI.
If the given namespaceURI is null or an empty string and the
qualifiedName has a prefix that is "xml", the created element
is bound to the predefined namespace
"http://www.w3.org/XML/1998/namespace" [Namespaces]. |
public Element createElementNS(String namespaceURI,
String qualifiedName,
String localpart) throws DOMException {
return new ElementNSImpl(this, namespaceURI, qualifiedName, localpart);
}
NON-DOM: a factory method used by the Xerces DOM parser
to create an element. |
public Entity createEntity(String name) throws DOMException {
if (errorChecking && !isXMLName(name,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new EntityImpl(this, name);
}
NON-DOM
Factory method; creates an Entity having this Document
as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
DTD information unspecified.) |
public EntityReference createEntityReference(String name) throws DOMException {
if (errorChecking && !isXMLName(name,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new EntityReferenceImpl(this, name);
}
Factory method; creates an EntityReference having this Document
as its OwnerDoc. |
public Notation createNotation(String name) throws DOMException {
if (errorChecking && !isXMLName(name,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new NotationImpl(this, name);
}
NON-DOM
Factory method; creates a Notation having this Document
as its OwnerDoc. (REC-DOM-Level-1-19981001 left the process of building
DTD information unspecified.) |
public ProcessingInstruction createProcessingInstruction(String target,
String data) throws DOMException {
if (errorChecking && !isXMLName(target,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
}
return new ProcessingInstructionImpl(this, target, data);
}
Factory method; creates a ProcessingInstruction having this Document
as its OwnerDoc. |
public Text createTextNode(String data) {
return new TextImpl(this, data);
}
Factory method; creates a Text node having this Document as its
OwnerDoc. |
void deletedText(CharacterDataImpl node,
int offset,
int count) {
}
A method to be called when some text was deleted from a text node,
so that live objects can be notified. |
protected boolean dispatchEvent(NodeImpl node,
Event event) {
// does nothing by default - overidden in subclass
return false;
}
|
void freeNodeListCache(NodeListCache c) {
c.next = fFreeNLCache;
fFreeNLCache = c;
}
Puts the given NodeListCache in the free list.
Note: The owner node can keep using it until we reuse it |
public boolean getAsync() {
return false;
}
DOM Level 3 WD - Experimental.
Indicates whether the method load should be synchronous or
asynchronous. When the async attribute is set to true
the load method returns control to the caller before the document has
completed loading. The default value of this property is
false.
Setting the value of this attribute might throw NOT_SUPPORTED_ERR
if the implementation doesn't support the mode the attribute is being
set to. Should the DOM spec define the default value of this
property? What if implementing both async and sync IO is impractical
in some systems? 2001-09-14. default is false but we
need to check with Mozilla and IE. |
public String getBaseURI() {
if (fDocumentURI != null && fDocumentURI.length() != 0 ) {// attribute value is always empty string
try {
return new URI(fDocumentURI).toString();
}
catch (org.apache.xerces.util.URI.MalformedURIException e){
// REVISIT: what should happen in this case?
return null;
}
}
return fDocumentURI;
}
Returns the absolute base URI of this node or null if the implementation
wasn't able to obtain an absolute URI. Note: If the URI is malformed, a
null is returned. |
public DocumentType getDoctype() {
if (needsSyncChildren()) {
synchronizeChildren();
}
return docType;
}
For XML, this provides access to the Document Type Definition.
For HTML documents, and XML documents which don't specify a DTD,
it will be null. |
public Element getDocumentElement() {
if (needsSyncChildren()) {
synchronizeChildren();
}
return docElement;
}
Convenience method, allowing direct access to the child node
which is considered the root of the actual document content. For
HTML, where it is legal to have more than one Element at the top
level of the document, we pick the one with the tagName
"HTML". For XML there should be only one top-level
(HTML not yet supported.) |
public String getDocumentURI() {
return fDocumentURI;
}
DOM Level 3 WD - Experimental.
The location of the document or null if undefined.
Beware that when the Document supports the feature
"HTML" , the href attribute of the HTML BASE element takes precedence
over this attribute. |
public DOMConfiguration getDomConfig() {
if (fConfiguration == null) {
fConfiguration = new DOMConfigurationImpl();
}
return fConfiguration;
}
DOM Level 3 CR - Experimental
The configuration used when Document.normalizeDocument is
invoked. |
public Element getElementById(String elementId) {
return getIdentifier(elementId);
}
Introduced in DOM Level 2
Returns the Element whose ID is given by elementId. If no such element
exists, returns null. Behavior is not defined if more than one element
has this ID.
Note: The DOM implementation must have information that says which
attributes are of type ID. Attributes with the name "ID" are not of type
ID unless so defined. Implementations that do not know whether
attributes are of type ID or not are expected to return null. |
public NodeList getElementsByTagName(String tagname) {
return new DeepNodeListImpl(this,tagname);
}
Return a live collection of all descendent Elements (not just
immediate children) having the specified tag name. |
public NodeList getElementsByTagNameNS(String namespaceURI,
String localName) {
return new DeepNodeListImpl(this, namespaceURI, localName);
}
Introduced in DOM Level 2.
Returns a NodeList of all the Elements with a given local name and
namespace URI in the order in which they would be encountered in a
preorder traversal of the Document tree. |
public String getEncoding() {
return getXmlEncoding();
} Deprecated! This - method is internal and only exists for
compatibility with older applications. New applications
should never call this method.
|
public boolean getErrorChecking() {
return errorChecking;
}
Returns true if the DOM implementation performs error checking. |
public Object getFeature(String feature,
String version) {
boolean anyVersion = version == null || version.length() == 0;
// if a plus sign "+" is prepended to any feature name, implementations
// are considered in which the specified feature may not be directly
// castable DOMImplementation.getFeature(feature, version). Without a
// plus, only features whose interfaces are directly castable are
// considered.
if ((feature.equalsIgnoreCase("+XPath"))
&& (anyVersion || version.equals("3.0"))) {
// If an XPathEvaluator was created previously
// return it otherwise create a new one.
if (fXPathEvaluator != null) {
return fXPathEvaluator;
}
try {
Class xpathClass = ObjectFactory.findProviderClass(
"org.apache.xpath.domapi.XPathEvaluatorImpl",
ObjectFactory.findClassLoader(), true);
Constructor xpathClassConstr =
xpathClass.getConstructor(new Class[] { Document.class });
// Check if the DOM XPath implementation implements
// the interface org.w3c.dom.XPathEvaluator
Class interfaces[] = xpathClass.getInterfaces();
for (int i = 0; i < interfaces.length; i++) {
if (interfaces[i].getName().equals(
"org.w3c.dom.xpath.XPathEvaluator")) {
fXPathEvaluator = xpathClassConstr.newInstance(new Object[] { this });
return fXPathEvaluator;
}
}
return null;
} catch (Exception e) {
return null;
}
}
return super.getFeature(feature, version);
}
|
public Element getIdentifier(String idName) {
if (needsSyncData()) {
synchronizeData();
}
if (identifiers == null) {
return null;
}
Element elem = (Element) identifiers.get(idName);
if (elem != null) {
// check that the element is in the tree
Node parent = elem.getParentNode();
while (parent != null) {
if (parent == this) {
return elem;
}
parent = parent.getParentNode();
}
}
return null;
}
Returns a previously registered element with the specified
identifier name, or null if no element is registered. |
public Enumeration getIdentifiers() {
if (needsSyncData()) {
synchronizeData();
}
if (identifiers == null) {
identifiers = new Hashtable();
}
return identifiers.keys();
}
Returns an enumeration registered of identifier names. |
public DOMImplementation getImplementation() {
// Currently implemented as a singleton, since it's hardcoded
// information anyway.
return CoreDOMImplementationImpl.getDOMImplementation();
}
Retrieve information describing the abilities of this particular
DOM implementation. Intended to support applications that may be
using DOMs retrieved from several different sources, potentially
with different underlying representations. |
public String getInputEncoding() {
return actualEncoding;
}
DOM Level 3 CR - Experimental. (Was getActualEncoding)
An attribute specifying the encoding used for this document
at the time of the parsing. This is null when
it is not known, such as when the Document was
created in memory. |
boolean getMutationEvents() {
// does nothing by default - overriden in subclass
return false;
}
Returns true if the DOM implementation generates mutation events. |
NodeListCache getNodeListCache(ParentNode owner) {
if (fFreeNLCache == null) {
return new NodeListCache(owner);
}
NodeListCache c = fFreeNLCache;
fFreeNLCache = fFreeNLCache.next;
c.fChild = null;
c.fChildIndex = -1;
c.fLength = -1;
// revoke previous ownership
if (c.fOwner != null) {
c.fOwner.fNodeListCache = null;
}
c.fOwner = owner;
// c.next = null; not necessary, except for confused people...
return c;
}
Returns a NodeListCache for the given node. |
public String getNodeName() {
return "#document";
}
|
protected int getNodeNumber() {
if (documentNumber==0) {
CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl)CoreDOMImplementationImpl.getDOMImplementation();
documentNumber = cd.assignDocumentNumber();
}
return documentNumber;
}
NON-DOM: Get the number associated with this document. Used to
order documents in the implementation. |
protected int getNodeNumber(Node node) {
// Check if the node is already in the hash
// If so, retrieve the node number
// If not, assign a number to the node
// Node numbers are negative, from -1 to -n
int num;
if (nodeTable == null) {
nodeTable = new Hashtable();
num = --nodeCounter;
nodeTable.put(node, new Integer(num));
}
else {
Integer n = (Integer)nodeTable.get(node);
if (n== null) {
num = --nodeCounter;
nodeTable.put(node, new Integer(num));
}
else
num = n.intValue();
}
return num;
}
NON-DOM: Get a number associated with a node created with respect
to this document. Needed for compareDocumentPosition when nodes
are disconnected. This is only used on demand. |
public short getNodeType() {
return Node.DOCUMENT_NODE;
}
|
public final Document getOwnerDocument() {
return null;
}
|
public boolean getStandalone() {
return getXmlStandalone();
} Deprecated! This - method is internal and only exists for
compatibility with older applications. New applications
should never call this method.
|
public boolean getStrictErrorChecking() {
return errorChecking;
}
|
public String getTextContent() throws DOMException {
return null;
}
|
protected Object getUserData(NodeImpl n) {
return getUserData(n, "XERCES1DOMUSERDATA");
}
NON-DOM: kept for backward compatibility
Retreive user data related to a given node |
public Object getUserData(Node n,
String key) {
if (userData == null) {
return null;
}
Hashtable t = (Hashtable) userData.get(n);
if (t == null) {
return null;
}
Object o = t.get(key);
if (o != null) {
UserDataRecord r = (UserDataRecord) o;
return r.fData;
}
return null;
}
Retrieves the object associated to a key on a this node. The object
must first have been set to this node by calling
setUserData with the same key. |
protected Hashtable getUserDataRecord(Node n) {
if (userData == null) {
return null;
}
Hashtable t = (Hashtable) userData.get(n);
if (t == null) {
return null;
}
return t;
}
|
public String getVersion() {
return getXmlVersion();
} Deprecated! This - method is internal and only exists for
compatibility with older applications. New applications
should never call this method.
|
public String getXmlEncoding() {
return encoding;
}
DOM Level 3 WD - Experimental.
The encoding of this document (part of XML Declaration) |
public boolean getXmlStandalone() {
return standalone;
}
DOM Level 3 WD - Experimental.
standalone that specifies whether this document is standalone
(part of XML Declaration) |
public String getXmlVersion() {
return (version == null)?"1.0":version;
}
DOM Level 3 WD - Experimental.
The version of this document (part of XML Declaration) |
public Node importNode(Node source,
boolean deep) throws DOMException {
return importNode(source, deep, false, null);
}
Copies a node from another document to this document. The new nodes are
created using this document's factory methods and are populated with the
data from the source's accessor methods defined by the DOM interfaces.
Its behavior is otherwise similar to that of cloneNode.
According to the DOM specifications, document nodes cannot be imported
and a NOT_SUPPORTED_ERR exception is thrown if attempted. |
public Node insertBefore(Node newChild,
Node refChild) throws DOMException {
// Only one such child permitted
int type = newChild.getNodeType();
if (errorChecking) {
if (needsSyncChildren()) {
synchronizeChildren();
}
if((type == Node.ELEMENT_NODE && docElement != null) ||
(type == Node.DOCUMENT_TYPE_NODE && docType != null)) {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null);
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, msg);
}
}
// Adopt orphan doctypes
if (newChild.getOwnerDocument() == null &&
newChild instanceof DocumentTypeImpl) {
((DocumentTypeImpl) newChild).ownerDocument = this;
}
super.insertBefore(newChild,refChild);
// If insert succeeded, cache the kid appropriately
if (type == Node.ELEMENT_NODE) {
docElement = (ElementImpl)newChild;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = (DocumentTypeImpl)newChild;
}
return newChild;
}
Since a Document may contain at most one top-level Element child,
and at most one DocumentType declaraction, we need to subclass our
add-children methods to implement this constraint.
Since appendChild() is implemented as insertBefore(,null),
altering the latter fixes both.
While I'm doing so, I've taken advantage of the opportunity to
cache documentElement and docType so we don't have to
search for them.
REVISIT: According to the spec it is not allowed to alter neither the
document element nor the document type in any way |
void insertedNode(NodeImpl node,
NodeImpl newInternal,
boolean replace) {
}
A method to be called when a node has been inserted in the tree. |
void insertedText(CharacterDataImpl node,
int offset,
int count) {
}
A method to be called when some text was inserted into a text node,
so that live objects can be notified. |
void insertingNode(NodeImpl node,
boolean replace) {
}
A method to be called when a node is about to be inserted in the tree. |
protected boolean isKidOK(Node parent,
Node child) {
if (allowGrammarAccess &&
parent.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
return child.getNodeType() == Node.ELEMENT_NODE;
}
return 0 != (kidOK[parent.getNodeType()] & 1 < < child.getNodeType());
}
Uses the kidOK lookup table to check whether the proposed
tree structure is legal. |
boolean isNormalizeDocRequired() {
// REVISIT: Implement to optimize when normalization
// is required
return true;
}
|
public static final boolean isValidQName(String prefix,
String local,
boolean xml11Version) {
// check that both prefix and local part match NCName
if (local == null) return false;
boolean validNCName = false;
if (!xml11Version) {
validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
&& XMLChar.isValidNCName(local);
}
else {
validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
&& XML11Char.isXML11ValidNCName(local);
}
return validNCName;
}
Checks if the given qualified name is legal with respect
to the version of XML to which this document must conform. |
boolean isXML11Version() {
return xml11Version;
}
We could have more xml versions in future , but for now we could
do with this to handle XML 1.0 and 1.1 |
public static final boolean isXMLName(String s,
boolean xml11Version) {
if (s == null) {
return false;
}
if(!xml11Version)
return XMLChar.isValidName(s);
else
return XML11Char.isXML11ValidName(s);
}
Check the string against XML's definition of acceptable names for
elements and attributes and so on using the XMLCharacterProperties
utility class |
boolean isXMLVersionChanged() {
return xmlVersionChanged ;
}
|
public boolean load(String uri) {
return false;
}
DOM Level 3 WD - Experimental.
Replaces the content of the document with the result of parsing the
given URI. Invoking this method will either block the caller or
return to the caller immediately depending on the value of the async
attribute. Once the document is fully loaded a "load" event (as
defined in [DOM Level 3 Events]
, except that the Event.targetNode will be the document,
not an element) will be dispatched on the document. If an error
occurs, an implementation dependent "error" event will be dispatched
on the document. If this method is called on a document that is
currently loading, the current load is interrupted and the new URI
load is initiated.
When invoking this method the parameters used in the
DOMParser interface are assumed to have their default
values with the exception that the parameters "entities"
, "normalize-characters",
"check-character-normalization" are set to
"false".
The result of a call to this method is the same the result of a
call to DOMParser.parseWithContext with an input stream
referencing the URI that was passed to this call, the document as the
context node, and the action ACTION_REPLACE_CHILDREN. |
public boolean loadXML(String source) {
return false;
}
DOM Level 3 WD - Experimental.
Replace the content of the document with the result of parsing the
input string, this method is always synchronous. |
void modifiedAttrValue(AttrImpl attr,
String oldvalue) {
}
A method to be called when an attribute value has been modified |
void modifiedCharacterData(NodeImpl node,
String oldvalue,
String value,
boolean replace) {
}
A method to be called when a character data node has been modified |
void modifyingCharacterData(NodeImpl node,
boolean replace) {
}
A method to be called when a character data node is about to be modified |
public void normalizeDocument() {
// No need to normalize if already normalized.
if (isNormalized() && !isNormalizeDocRequired()) {
return;
}
if (needsSyncChildren()) {
synchronizeChildren();
}
if (domNormalizer == null) {
domNormalizer = new DOMNormalizer();
}
if (fConfiguration == null) {
fConfiguration = new DOMConfigurationImpl();
}
else {
fConfiguration.reset();
}
domNormalizer.normalizeDocument(this, fConfiguration);
isNormalized(true);
//set the XMLversion changed value to false -- once we have finished
//doing normalization
xmlVersionChanged = false ;
}
DOM Level 3 WD - Experimental
Normalize document. |
public void putIdentifier(String idName,
Element element) {
if (element == null) {
removeIdentifier(idName);
return;
}
if (needsSyncData()) {
synchronizeData();
}
if (identifiers == null) {
identifiers = new Hashtable();
}
identifiers.put(idName, element);
}
Registers an identifier name with a specified element node.
If the identifier is already registered, the new element
node replaces the previous node. If the specified element
node is null, removeIdentifier() is called. |
public Node removeChild(Node oldChild) throws DOMException {
super.removeChild(oldChild);
// If remove succeeded, un-cache the kid appropriately
int type = oldChild.getNodeType();
if(type == Node.ELEMENT_NODE) {
docElement = null;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = null;
}
return oldChild;
}
Since insertBefore caches the docElement (and, currently, docType),
removeChild has to know how to undo the cache
REVISIT: According to the spec it is not allowed to alter neither the
document element nor the document type in any way |
protected void removeEventListener(NodeImpl node,
String type,
EventListener listener,
boolean useCapture) {
// does nothing by default - overidden in subclass
}
|
public void removeIdentifier(String idName) {
if (needsSyncData()) {
synchronizeData();
}
if (identifiers == null) {
return;
}
identifiers.remove(idName);
}
Removes a previously registered element with the specified
identifier name. |
Hashtable removeUserDataTable(Node n) {
if (userData == null) {
return null;
}
return (Hashtable) userData.get(n);
}
Remove user data table for the given node. |
void removedAttrNode(AttrImpl attr,
NodeImpl oldOwner,
String name) {
}
A method to be called when an attribute node has been removed |
void removedNode(NodeImpl node,
boolean replace) {
}
A method to be called when a node has been removed from the tree. |
void removingNode(NodeImpl node,
NodeImpl oldChild,
boolean replace) {
}
A method to be called when a node is about to be removed from the tree. |
public Node renameNode(Node n,
String namespaceURI,
String name) throws DOMException {
if (errorChecking && n.getOwnerDocument() != this && n != this) {
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
}
switch (n.getNodeType()) {
case ELEMENT_NODE: {
ElementImpl el = (ElementImpl) n;
if (el instanceof ElementNSImpl) {
((ElementNSImpl) el).rename(namespaceURI, name);
// fire user data NODE_RENAMED event
callUserDataHandlers(el, null, UserDataHandler.NODE_RENAMED);
}
else {
if (namespaceURI == null) {
if (errorChecking) {
int colon1 = name.indexOf(':");
if(colon1 != -1){
String msg =
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"NAMESPACE_ERR",
null);
throw new DOMException(DOMException.NAMESPACE_ERR, msg);
}
if (!isXMLName(name,xml11Version)) {
String msg = DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
"INVALID_CHARACTER_ERR", null);
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
msg);
}
}
el.rename(name);
// fire user data NODE_RENAMED event
callUserDataHandlers(el, null,
UserDataHandler.NODE_RENAMED);
}
else {
// we need to create a new object
ElementNSImpl nel =
new ElementNSImpl(this, namespaceURI, name);
// register event listeners on new node
copyEventListeners(el, nel);
// remove user data from old node
Hashtable data = removeUserDataTable(el);
// remove old node from parent if any
Node parent = el.getParentNode();
Node nextSib = el.getNextSibling();
if (parent != null) {
parent.removeChild(el);
}
// move children to new node
Node child = el.getFirstChild();
while (child != null) {
el.removeChild(child);
nel.appendChild(child);
child = el.getFirstChild();
}
// move specified attributes to new node
nel.moveSpecifiedAttributes(el);
// attach user data to new node
setUserDataTable(nel, data);
// and fire user data NODE_RENAMED event
callUserDataHandlers(el, nel,
UserDataHandler.NODE_RENAMED);
// insert new node where old one was
if (parent != null) {
parent.insertBefore(nel, nextSib);
}
el = nel;
}
}
// fire ElementNameChanged event
renamedElement((Element) n, el);
return el;
}
case ATTRIBUTE_NODE: {
AttrImpl at = (AttrImpl) n;
// dettach attr from element
Element el = at.getOwnerElement();
if (el != null) {
el.removeAttributeNode(at);
}
if (n instanceof AttrNSImpl) {
((AttrNSImpl) at).rename(namespaceURI, name);
// reattach attr to element
if (el != null) {
el.setAttributeNodeNS(at);
}
// fire user data NODE_RENAMED event
callUserDataHandlers(at, null, UserDataHandler.NODE_RENAMED);
}
else {
if (namespaceURI == null) {
at.rename(name);
// reattach attr to element
if (el != null) {
el.setAttributeNode(at);
}
// fire user data NODE_RENAMED event
callUserDataHandlers(at, null, UserDataHandler.NODE_RENAMED);
}
else {
// we need to create a new object
AttrNSImpl nat = new AttrNSImpl(this, namespaceURI, name);
// register event listeners on new node
copyEventListeners(at, nat);
// remove user data from old node
Hashtable data = removeUserDataTable(at);
// move children to new node
Node child = at.getFirstChild();
while (child != null) {
at.removeChild(child);
nat.appendChild(child);
child = at.getFirstChild();
}
// attach user data to new node
setUserDataTable(nat, data);
// and fire user data NODE_RENAMED event
callUserDataHandlers(at, nat, UserDataHandler.NODE_RENAMED);
// reattach attr to element
if (el != null) {
el.setAttributeNode(nat);
}
at = nat;
}
}
// fire AttributeNameChanged event
renamedAttrNode((Attr) n, at);
return at;
}
default: {
String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
}
}
}
DOM Level 3 WD - Experimental.
Renaming node |
void renamedAttrNode(Attr oldAt,
Attr newAt) {
}
A method to be called when an attribute node has been renamed |
void renamedElement(Element oldEl,
Element newEl) {
}
A method to be called when an element has been renamed |
public Node replaceChild(Node newChild,
Node oldChild) throws DOMException {
// Adopt orphan doctypes
if (newChild.getOwnerDocument() == null &&
newChild instanceof DocumentTypeImpl) {
((DocumentTypeImpl) newChild).ownerDocument = this;
}
if (errorChecking &&((docType != null &&
oldChild.getNodeType() != Node.DOCUMENT_TYPE_NODE &&
newChild.getNodeType() == Node.DOCUMENT_TYPE_NODE)
|| (docElement != null &&
oldChild.getNodeType() != Node.ELEMENT_NODE &&
newChild.getNodeType() == Node.ELEMENT_NODE))) {
throw new DOMException(
DOMException.HIERARCHY_REQUEST_ERR,
DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "HIERARCHY_REQUEST_ERR", null));
}
super.replaceChild(newChild, oldChild);
int type = oldChild.getNodeType();
if(type == Node.ELEMENT_NODE) {
docElement = (ElementImpl)newChild;
}
else if (type == Node.DOCUMENT_TYPE_NODE) {
docType = (DocumentTypeImpl)newChild;
}
return oldChild;
}
Since we cache the docElement (and, currently, docType),
replaceChild has to update the cache
REVISIT: According to the spec it is not allowed to alter neither the
document element nor the document type in any way |
void replacedCharacterData(NodeImpl node,
String oldvalue,
String value) {
}
method to be called when a character data node has been replaced. |
void replacedNode(NodeImpl node) {
}
A method to be called when a node has been replaced in the tree. |
void replacedText(CharacterDataImpl node) {
}
A method to be called when some text was changed in a text node,
so that live objects can be notified. |
void replacingData(NodeImpl node) {
}
A method to be called when a character data node is about to be replaced |
void replacingNode(NodeImpl node) {
}
A method to be called when a node is about to be replaced in the tree. |
public String saveXML(Node node) throws
|