Methods Summary |
---|
org.w3c.dom.Node | cloneNode(org.w3c.dom.Node node, boolean deep)Clones a node and (if requested) its children. The source node(s) may
have been created by a different DocumentImpl or even DOM implementation.
Node target;
switch (node.getNodeType()) {
case Node.ATTRIBUTE_NODE: {
Attr source = (Attr)node;
target = createAttributeNS(source.getNamespaceURI(), source.getLocalName());
target.setPrefix(source.getPrefix());
target.setNodeValue(source.getNodeValue());
break;
}
case Node.CDATA_SECTION_NODE: {
CharacterData source = (CharacterData)node;
target = createCDATASection(source.getData());
break;
}
case Node.COMMENT_NODE: {
Comment source = (Comment)node;
target = createComment(source.getData());
break;
}
case Node.DOCUMENT_FRAGMENT_NODE: {
// Source is irrelevant in this case.
target = createDocumentFragment();
break;
}
case Node.DOCUMENT_NODE: {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot clone a Document node");
}
case Node.DOCUMENT_TYPE_NODE: {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot clone a DocumentType node");
}
case Node.ELEMENT_NODE: {
Element source = (Element)node;
target = createElementNS(source.getNamespaceURI(), source.getLocalName());
target.setPrefix(source.getPrefix());
NamedNodeMap map = source.getAttributes();
for (int i = 0; i < map.getLength(); i++) {
Attr attr = (Attr)map.item(i);
((Element)target).setAttributeNodeNS((Attr)cloneNode(attr, deep));
}
break;
}
case Node.ENTITY_NODE: {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot clone an Entity node");
}
case Node.ENTITY_REFERENCE_NODE: {
EntityReference source = (EntityReference)node;
target = createEntityReference(source.getNodeName());
break;
}
case Node.NOTATION_NODE: {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot clone a Notation node");
}
case Node.PROCESSING_INSTRUCTION_NODE: {
ProcessingInstruction source = (ProcessingInstruction)node;
target = createProcessingInstruction(source.getTarget(), source.getData());
break;
}
case Node.TEXT_NODE: {
Text source = (Text)node;
target = createTextNode(source.getData());
break;
}
default: {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot clone unknown node type " + node.getNodeType() + " (" + node.getClass().getSimpleName() + ")");
}
}
if (deep) {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node child = cloneNode(list.item(i), deep);
target.appendChild(child);
}
}
return target;
|
public AttrImpl | createAttribute(java.lang.String name)
return new AttrImpl(this, name);
|
public org.w3c.dom.Attr | createAttributeNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
return new AttrImpl(this, namespaceURI, qualifiedName);
|
public org.w3c.dom.CDATASection | createCDATASection(java.lang.String data)
return new CDATASectionImpl(this, data);
|
public org.w3c.dom.Comment | createComment(java.lang.String data)
return new CommentImpl(this, data);
|
public org.w3c.dom.DocumentFragment | createDocumentFragment()
return new DocumentFragmentImpl(this);
|
public org.w3c.dom.Element | createElement(java.lang.String tagName)
return new ElementImpl(this, tagName);
|
public org.w3c.dom.Element | createElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
return new ElementImpl(this, namespaceURI, qualifiedName);
|
public org.w3c.dom.EntityReference | createEntityReference(java.lang.String name)
return new EntityReferenceImpl(this, name);
|
public org.w3c.dom.ProcessingInstruction | createProcessingInstruction(java.lang.String target, java.lang.String data)
return new ProcessingInstructionImpl(this, target, data);
|
public org.w3c.dom.Text | createTextNode(java.lang.String data)
return new TextImpl(this, data);
|
public org.w3c.dom.DocumentType | getDoctype()
for (int i = 0; i < children.size(); i++) {
if (children.get(i) instanceof DocumentType) {
return (DocumentType) children.get(i);
}
}
return null;
|
public org.w3c.dom.Element | getDocumentElement()
for (int i = 0; i < children.size(); i++) {
if (children.get(i) instanceof Element) {
return (Element) children.get(i);
}
}
return null;
|
public org.w3c.dom.Element | getElementById(java.lang.String elementId)
ElementImpl root = (ElementImpl) getDocumentElement();
return (root == null ? null : root.getElementById(elementId));
|
public org.w3c.dom.NodeList | getElementsByTagName(java.lang.String tagname)
ElementImpl root = (ElementImpl) getDocumentElement();
return (root == null ? new NodeListImpl()
: root.getElementsByTagName(tagname));
|
public org.w3c.dom.NodeList | getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
ElementImpl root = (ElementImpl) getDocumentElement();
return (root == null ? new NodeListImpl() : root.getElementsByTagNameNS(
namespaceURI, localName));
|
public org.w3c.dom.DOMImplementation | getImplementation()
return domImplementation;
|
public java.lang.String | getNodeName()
return "#document";
|
public short | getNodeType()
return Node.DOCUMENT_NODE;
|
public org.w3c.dom.Node | importNode(org.w3c.dom.Node importedNode, boolean deep)
return cloneNode(importedNode, deep);
|
public org.w3c.dom.Node | insertChildAt(org.w3c.dom.Node newChild, int index)
// Make sure we have at most one root element and one DTD element.
if (newChild instanceof Element && getDocumentElement() != null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
"Only one root element allowed");
} else if (newChild instanceof DocumentType && getDoctype() != null) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
"Only one DOCTYPE element allowed");
}
return super.insertChildAt(newChild, index);
|
static boolean | isXMLIdentifier(java.lang.String s)
if (s.length() == 0) {
return false;
}
if (!isXMLIdentifierStart(s.charAt(0))) {
return false;
}
for (int i = 1; i < s.length(); i++) {
if (!isXMLIdentifierPart(s.charAt(i))) {
return false;
}
}
return true;
|
private static boolean | isXMLIdentifierPart(char c)
return isXMLIdentifierStart(c) || (c >= '0" && c <= '9") || (c == '-") || (c == '.");
|
private static boolean | isXMLIdentifierStart(char c)
return (c >= 'A" && c <= 'Z") || (c >= 'a" && c <= 'z") || (c == '_");
|