use of org.w3c.dom.DOMException in project robovm by robovm.
the class ElementSetAttributeNS method testSetAttributeNS4.
public void testSetAttributeNS4() throws Throwable {
Document doc;
Element element;
String qualifiedName;
List<String> qualifiedNames = new ArrayList<String>();
qualifiedNames.add("/");
qualifiedNames.add("//");
qualifiedNames.add("\\");
qualifiedNames.add(";");
qualifiedNames.add("&");
qualifiedNames.add("*");
qualifiedNames.add("]]");
qualifiedNames.add(">");
qualifiedNames.add("<");
doc = (Document) load("staffNS", builder);
element = doc.createElementNS("http://www.w3.org/DOM/Test/L2", "dom:elem");
for (int indexN10058 = 0; indexN10058 < qualifiedNames.size(); indexN10058++) {
qualifiedName = (String) qualifiedNames.get(indexN10058);
{
boolean success = false;
try {
element.setAttributeNS("http://www.w3.org/DOM/Test/L2", qualifiedName, "test");
} catch (DOMException ex) {
success = (ex.code == DOMException.INVALID_CHARACTER_ERR);
}
assertTrue("elementsetattributens04", success);
}
}
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class ElementSetAttributeNS method testSetAttributeNS8.
public void testSetAttributeNS8() throws Throwable {
Document doc;
Element element;
doc = (Document) load("staffNS", builder);
element = doc.createElementNS("http://www.w3.org/DOMTest/level2", "dom:elem");
{
boolean success = false;
try {
element.setAttributeNS("http://www.w3.org/DOMTest/level2", "xmlns", "test");
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("elementsetattributens08_Err1", success);
}
{
boolean success = false;
try {
element.setAttributeNS("http://www.w3.org/DOMTest/level2", "xmlns:root", "test");
} catch (DOMException ex) {
success = (ex.code == DOMException.NAMESPACE_ERR);
}
assertTrue("elementsetattributens08_Err2", success);
}
}
use of org.w3c.dom.DOMException in project robovm by robovm.
the class DocumentImportNode method testImportNode7.
public void testImportNode7() throws Throwable {
Document doc;
DocumentType docType;
doc = (Document) load("staffNS", builder);
docType = doc.getDoctype();
{
boolean success = false;
try {
doc.importNode(docType, true);
} catch (DOMException ex) {
success = (ex.code == DOMException.NOT_SUPPORTED_ERR);
}
assertTrue("throw_NOT_SUPPORTED_ERR", success);
}
}
use of org.w3c.dom.DOMException in project XobotOS by xamarin.
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 XobotOS by xamarin.
the class InnerNodeImpl method insertChildAt.
/**
* Inserts {@code newChild} at {@code index}. If it is already child of
* another node, it is removed from there.
*/
Node insertChildAt(Node newChild, int index) throws DOMException {
if (newChild instanceof DocumentFragment) {
NodeList toAdd = newChild.getChildNodes();
for (int i = 0; i < toAdd.getLength(); i++) {
insertChildAt(toAdd.item(i), index + i);
}
return newChild;
}
LeafNodeImpl toInsert = (LeafNodeImpl) newChild;
if (toInsert.document != null && document != null && toInsert.document != document) {
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, null);
}
if (toInsert.isParentOf(this)) {
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, null);
}
if (toInsert.parent != null) {
int oldIndex = toInsert.index;
toInsert.parent.children.remove(oldIndex);
toInsert.parent.refreshIndices(oldIndex);
}
children.add(index, toInsert);
toInsert.parent = this;
refreshIndices(index);
return newChild;
}
Aggregations