use of org.w3c.dom.DOMException in project robovm by robovm.
the class RemoveNamedItemNS method testRemoveNamedItemNS2.
public void testRemoveNamedItemNS2() throws Throwable {
String namespaceURI = "http://www.usa.com";
String localName = "domest";
Document doc;
NodeList elementList;
Node testAddress;
NamedNodeMap attributes;
doc = (Document) load("staffNS", builder);
elementList = doc.getElementsByTagName("address");
testAddress = elementList.item(1);
attributes = testAddress.getAttributes();
{
boolean success = false;
try {
attributes.removeNamedItemNS(namespaceURI, localName);
} catch (DOMException ex) {
success = (ex.code == DOMException.NOT_FOUND_ERR);
}
assertTrue("throw_NOT_FOUND_ERR", success);
}
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class DocumentImpl method adoptNode.
/**
* Detaches the node from its parent (if any) and changes its document to
* this document. The node's subtree and attributes will remain attached,
* but their document will be changed to this document.
*/
public Node adoptNode(Node node) {
if (!(node instanceof NodeImpl)) {
// the API specifies this quiet failure
return null;
}
NodeImpl nodeImpl = (NodeImpl) node;
switch(nodeImpl.getNodeType()) {
case Node.ATTRIBUTE_NODE:
AttrImpl attr = (AttrImpl) node;
if (attr.ownerElement != null) {
attr.ownerElement.removeAttributeNode(attr);
}
break;
case Node.DOCUMENT_FRAGMENT_NODE:
case Node.ENTITY_REFERENCE_NODE:
case Node.PROCESSING_INSTRUCTION_NODE:
case Node.TEXT_NODE:
case Node.CDATA_SECTION_NODE:
case Node.COMMENT_NODE:
case Node.ELEMENT_NODE:
break;
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
case Node.ENTITY_NODE:
case Node.NOTATION_NODE:
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot adopt nodes of type " + nodeImpl.getNodeType());
default:
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Unsupported node type " + node.getNodeType());
}
Node parent = nodeImpl.getParentNode();
if (parent != null) {
parent.removeChild(nodeImpl);
}
changeDocumentToThis(nodeImpl);
notifyUserDataHandlers(UserDataHandler.NODE_ADOPTED, node, null);
return nodeImpl;
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class DocumentImpl method shallowCopy.
/**
* Returns a shallow copy of the given node. If the node is an element node,
* its attributes are always copied.
*
* @param node a node belonging to any document or DOM implementation.
* @param operation the operation type to use when notifying user data
* handlers of copied element attributes. It is the caller's
* responsibility to notify user data handlers of the returned node.
* @return a new node whose document is this document and whose DOM
* implementation is this DOM implementation.
*/
private NodeImpl shallowCopy(short operation, Node node) {
switch(node.getNodeType()) {
case Node.ATTRIBUTE_NODE:
AttrImpl attr = (AttrImpl) node;
AttrImpl attrCopy;
if (attr.namespaceAware) {
attrCopy = createAttributeNS(attr.getNamespaceURI(), attr.getLocalName());
attrCopy.setPrefix(attr.getPrefix());
} else {
attrCopy = createAttribute(attr.getName());
}
attrCopy.setNodeValue(attr.getValue());
return attrCopy;
case Node.CDATA_SECTION_NODE:
return createCDATASection(((CharacterData) node).getData());
case Node.COMMENT_NODE:
return createComment(((Comment) node).getData());
case Node.DOCUMENT_FRAGMENT_NODE:
return createDocumentFragment();
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_TYPE_NODE:
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot copy node of type " + node.getNodeType());
case Node.ELEMENT_NODE:
ElementImpl element = (ElementImpl) node;
ElementImpl elementCopy;
if (element.namespaceAware) {
elementCopy = createElementNS(element.getNamespaceURI(), element.getLocalName());
elementCopy.setPrefix(element.getPrefix());
} else {
elementCopy = createElement(element.getTagName());
}
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
AttrImpl elementAttr = (AttrImpl) attributes.item(i);
AttrImpl elementAttrCopy = (AttrImpl) shallowCopy(operation, elementAttr);
notifyUserDataHandlers(operation, elementAttr, elementAttrCopy);
if (elementAttr.namespaceAware) {
elementCopy.setAttributeNodeNS(elementAttrCopy);
} else {
elementCopy.setAttributeNode(elementAttrCopy);
}
}
return elementCopy;
case Node.ENTITY_NODE:
case Node.NOTATION_NODE:
// TODO: implement this when we support these node types
throw new UnsupportedOperationException();
case Node.ENTITY_REFERENCE_NODE:
/*
* When we support entities in the doctype, this will need to
* behave differently for clones vs. imports. Clones copy
* entities by value, copying the referenced subtree from the
* original document. Imports copy entities by reference,
* possibly referring to a different subtree in the new
* document.
*/
return createEntityReference(node.getNodeName());
case Node.PROCESSING_INSTRUCTION_NODE:
ProcessingInstruction pi = (ProcessingInstruction) node;
return createProcessingInstruction(pi.getTarget(), pi.getData());
case Node.TEXT_NODE:
return createTextNode(((Text) node).getData());
default:
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Unsupported node type " + node.getNodeType());
}
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class CreateAttributeNS method testCreateAttributeNS4.
public void testCreateAttributeNS4() throws Throwable {
String namespaceURI = "http://www.w3.org/XML/1998/namespaces";
String qualifiedName = "xml:attr1";
Document doc;
doc = (Document) load("staffNS", builder);
{
boolean success = false;
try {
doc.createAttributeNS(namespaceURI, qualifiedName);
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class CreateAttributeNS method testCreateAttributeNS1.
/**
* Runs the test case.
*
* @throws Throwable
* Any uncaught exception causes test to fail
*/
public void testCreateAttributeNS1() throws Throwable {
String namespaceURI = "http://www.ecommerce.org/";
String malformedName = "prefix::local";
Document doc;
doc = (Document) load("staffNS", builder);
{
boolean success = false;
try {
doc.createAttributeNS(namespaceURI, malformedName);
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("throw_NAMESPACE_ERR", success);
}
}
Aggregations