List of usage examples for org.w3c.dom DOMException DOMException
public DOMException(short code, String message)
From source file:org.structr.web.entity.dom.DOMNode.java
@Override public Node removeChild(final Node node) throws DOMException { checkWriteAccess();/*from ww w .j a v a 2 s . c o m*/ checkSameDocument(node); checkIsChild(node); try { treeRemoveChild((DOMNode) node); } catch (FrameworkException fex) { throw new DOMException(DOMException.INVALID_STATE_ERR, fex.toString()); } return node; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLDocument.java
/** * Implementation of the {@link org.w3c.dom.events.DocumentEvent} interface's * {@link org.w3c.dom.events.DocumentEvent#createEvent(String)} method. The method creates an * uninitialized event of the specified type. * * @see <a href="http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-DocumentEvent">DocumentEvent</a> * @param eventType the event type to create * @return an event object for the specified type * @throws DOMException if the event type is not supported (will have a type of * DOMException.NOT_SUPPORTED_ERR) *//*w w w.j a va 2s . c om*/ @JsxFunction public Event createEvent(final String eventType) throws DOMException { Class<? extends Event> clazz = null; clazz = SUPPORTED_DOM2_EVENT_TYPE_MAP.get(eventType); if (clazz == null) { clazz = SUPPORTED_DOM3_EVENT_TYPE_MAP.get(eventType); } if (clazz == null) { if ("Events".equals(eventType) || "KeyEvents".equals(eventType) && getBrowserVersion().hasFeature(EVENT_TYPE_KEY_EVENTS) || "HashChangeEvent".equals(eventType) && getBrowserVersion().hasFeature(EVENT_TYPE_HASHCHANGEEVENT) || "BeforeUnloadEvent".equals(eventType) && getBrowserVersion().hasFeature(EVENT_TYPE_BEFOREUNLOADEVENT) || "PointerEvent".equals(eventType) && getBrowserVersion().hasFeature(EVENT_TYPE_POINTEREVENT) || "PopStateEvent".equals(eventType) || "ProgressEvent".equals(eventType) && getBrowserVersion().hasFeature(EVENT_TYPE_PROGRESSEVENT) || "XMLHttpRequestProgressEvent".equals(eventType) && getBrowserVersion().hasFeature(EVENT_TYPE_XMLHTTPREQUESTPROGRESSEVENT)) { clazz = SUPPORTED_VENDOR_EVENT_TYPE_MAP.get(eventType); } } if (clazz == null) { Context.throwAsScriptRuntimeEx( new DOMException(DOMException.NOT_SUPPORTED_ERR, "Event Type is not supported: " + eventType)); return null; // to stop eclipse warning } try { final Event event = clazz.newInstance(); event.setParentScope(getWindow()); event.setPrototype(getPrototype(clazz)); event.eventCreated(); return event; } catch (final InstantiationException e) { throw Context.reportRuntimeError("Failed to instantiate event: class ='" + clazz.getName() + "' for event type of '" + eventType + "': " + e.getMessage()); } catch (final IllegalAccessException e) { throw Context.reportRuntimeError("Failed to instantiate event: class ='" + clazz.getName() + "' for event type of '" + eventType + "': " + e.getMessage()); } }
From source file:com.gargoylesoftware.htmlunit.html.HtmlPage.java
/** * {@inheritDoc}/*from w ww. ja va2s . co m*/ */ @Override protected void checkChildHierarchy(final org.w3c.dom.Node newChild) throws DOMException { if (newChild instanceof Element) { if (getDocumentElement() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child Element."); } } else if (newChild instanceof DocumentType) { if (getDoctype() != null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may only have a single child DocumentType."); } } else if (!((newChild instanceof Comment) || (newChild instanceof ProcessingInstruction))) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "The Document may not have a child of this type: " + newChild.getNodeType()); } super.checkChildHierarchy(newChild); }
From source file:org.alfresco.repo.template.XSLTProcessorMethodInvoker.java
public Object invokeMethod(final String id, Object[] arguments) throws Exception { if (!PROCESSOR_METHODS.containsKey(id)) { throw new NullPointerException("unable to find method " + id); }/*from w w w.j av a 2 s. c o m*/ final TemplateProcessorMethod method = PROCESSOR_METHODS.get(id); arguments = this.convertArguments(arguments); log.debug("invoking " + id + " with " + arguments.length); Object result = method.exec(arguments); log.debug(id + " returned a " + result); if (result == null) { return null; } else if (result.getClass().isArray() && Node.class.isAssignableFrom(result.getClass().getComponentType())) { log.debug("converting " + result + " to a node iterator"); final Node[] array = (Node[]) result; return new NodeIterator() { private int index = 0; private boolean detached = false; public void detach() { if (log.isDebugEnabled()) log.debug("detaching NodeIterator"); this.detached = true; } public boolean getExpandEntityReferences() { return true; } public int getWhatToShow() { return NodeFilter.SHOW_ALL; } public Node getRoot() { return (array.length == 0 ? null : array[0].getOwnerDocument().getDocumentElement()); } public NodeFilter getFilter() { return new NodeFilter() { public short acceptNode(final Node n) { return NodeFilter.FILTER_ACCEPT; } }; } public Node nextNode() throws DOMException { if (log.isDebugEnabled()) log.debug("NodeIterator.nextNode(" + index + ")"); if (this.detached) throw new DOMException(DOMException.INVALID_STATE_ERR, null); return index == array.length ? null : array[index++]; } public Node previousNode() throws DOMException { if (log.isDebugEnabled()) log.debug("NodeIterator.previousNode(" + index + ")"); if (this.detached) throw new DOMException(DOMException.INVALID_STATE_ERR, null); return index == -1 ? null : array[index--]; } }; } else if (result instanceof String || result instanceof Number || result instanceof Node) { log.debug("returning " + result + " as is"); return result; } else { throw new IllegalArgumentException("unable to convert " + result.getClass().getName()); } }
From source file:org.apache.axis.message.NodeImpl.java
/** * The value of this node, depending on its type; see the table above. * When it is defined to be <code>null</code>, setting it has no effect. * /*from w w w .j ava 2 s.c o m*/ * @throws org.w3c.dom.DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly. * @throws org.w3c.dom.DOMException DOMSTRING_SIZE_ERR: Raised when it would return more characters than * fit in a <code>DOMString</code> variable on the implementation * platform. */ public void setNodeValue(String nodeValue) throws DOMException { throw new DOMException(DOMException.NO_DATA_ALLOWED_ERR, "Cannot use TextNode.set in " + this); }
From source file:org.apache.axis.message.NodeImpl.java
/** * Adds the node <code>newChild</code> to the end of the list of children * of this node. If the <code>newChild</code> is already in the tree, it * is first removed.//from ww w .ja v a 2 s .co m * * @param newChild The node to add.If it is a * <code>DocumentFragment</code> object, the entire contents of the * document fragment are moved into the child list of this node * @return The node added. * @throws org.w3c.dom.DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not * allow children of the type of the <code>newChild</code> node, or if * the node to append is one of this node's ancestors or this node * itself. * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created * from a different document than the one that created this node. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly or * if the previous parent of the node being inserted is readonly. * */ public Node appendChild(Node newChild) throws DOMException { if (newChild == null) { throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, "Can't append a null node."); } initializeChildren(); // per DOM spec - must remove from tree. If newChild.parent == null, // detachNode() does nothing. So this shouldn't hurt performace of // serializers. ((NodeImpl) newChild).detachNode(); children.add(newChild); ((NodeImpl) newChild).parent = this; setDirty(); return newChild; }
From source file:org.apache.axis.message.NodeImpl.java
/** * Removes the child node indicated by <code>oldChild</code> from the list * of children, and returns it./*w w w . j a va 2s . c o m*/ * * @param oldChild The node being removed. * @return The node removed. * @throws org.w3c.dom.DOMException NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly. * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of * this node. */ public Node removeChild(Node oldChild) throws DOMException { if (removeNodeFromChildList((NodeImpl) oldChild)) { setDirty(); return oldChild; } throw new DOMException(DOMException.NOT_FOUND_ERR, "NodeImpl Not found"); }
From source file:org.apache.axis.message.NodeImpl.java
/** * Replaces the child node <code>oldChild</code> with <code>newChild</code> * in the list of children, and returns the <code>oldChild</code> node. * <br>If <code>newChild</code> is a <code>DocumentFragment</code> object, * <code>oldChild</code> is replaced by all of the * <code>DocumentFragment</code> children, which are inserted in the * same order. If the <code>newChild</code> is already in the tree, it * is first removed./*from w ww. jav a2 s. c o m*/ * * @param newChild The new node to put in the child list. * @param oldChild The node being replaced in the list. * @return The node replaced. * @throws org.w3c.dom.DOMException HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not * allow children of the type of the <code>newChild</code> node, or if * the node to put in is one of this node's ancestors or this node * itself. * <br>WRONG_DOCUMENT_ERR: Raised if <code>newChild</code> was created * from a different document than the one that created this node. * <br>NO_MODIFICATION_ALLOWED_ERR: Raised if this node or the parent of * the new node is readonly. * <br>NOT_FOUND_ERR: Raised if <code>oldChild</code> is not a child of * this node. */ public Node replaceChild(Node newChild, Node oldChild) throws DOMException { initializeChildren(); int position = children.indexOf(oldChild); if (position < 0) { throw new DOMException(DOMException.NOT_FOUND_ERR, "NodeImpl Not found"); } children.remove(position); children.add(position, newChild); setDirty(); return oldChild; }
From source file:org.apache.axis.message.SOAPHeader.java
public Node appendChild(Node newChild) throws DOMException { SOAPHeaderElement headerElement = null; if (newChild instanceof SOAPHeaderElement) headerElement = (SOAPHeaderElement) newChild; else/*from w w w .java 2s. c o m*/ headerElement = new SOAPHeaderElement((Element) newChild); try { addChildElement(headerElement); } catch (SOAPException e) { throw new DOMException(DOMException.INVALID_STATE_ERR, e.toString()); } return headerElement; }
From source file:org.apache.xml.security.signature.Manifest.java
/** * Constructor Manifest/*from www . ja v a 2s . co m*/ * * @param element * @param baseURI * @throws XMLSecurityException */ public Manifest(Element element, String baseURI) throws XMLSecurityException { super(element, baseURI); // check out Reference children this.referencesEl = XMLUtils.selectDsNodes(this.constructionElement.getFirstChild(), Constants._TAG_REFERENCE); int le = this.referencesEl.length; if (le == 0) { // At least one Reference must be present. Bad. Object exArgs[] = { Constants._TAG_REFERENCE, Constants._TAG_MANIFEST }; throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, I18n.translate("xml.WrongContent", exArgs)); } // create List this.references = new ArrayList<Reference>(le); for (int i = 0; i < le; i++) { this.references.add(null); } }