/** * Concatenate additional characters onto the end of the data * stored in this node. Note that this, and insert(), are the paths * by which a DOM could wind up accumulating more data than the * language's strings can easily handle. (See above discussion.) * * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is readonly. */ public void appendData(String data) { if (isReadOnly()) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } if (data == null) { return; } if (needsSyncData()) { synchronizeData(); } setNodeValue(this.data + data); }
/** * Obtains DOMImpementaton interface providing a number of methods for performing * operations that are independent of any particular DOM instance. * * @throw DOMException <code>NOT_SUPPORTED_ERR</code> if cannot get DOMImplementation * @throw FactoryConfigurationError Application developers should never need to directly catch errors of this type. * * @return DOMImplementation implementation */ private static DOMImplementation getDOMImplementation() throws DOMException { //can be made public DocumentBuilderFactory factory = getFactory(false, false); try { return factory.newDocumentBuilder().getDOMImplementation(); } catch (ParserConfigurationException ex) { throw new DOMException( DOMException.NOT_SUPPORTED_ERR, "Cannot create parser satisfying configuration parameters" ); //NOI18N } catch (RuntimeException e) { // E.g. #36578, IllegalArgumentException. Try to recover gracefully. throw (DOMException) new DOMException(DOMException.NOT_SUPPORTED_ERR, e.toString()).initCause(e); } }
/** * Checks whether control needs to be returned to Digester. * * @param namespaceURI * the namespace URI * @param localName * the local name * @param qName * the qualified (prefixed) name * @throws SAXException * if the DOM implementation throws an exception */ @Override public void endElement(String namespaceURI, String localName, String qName) throws SAXException { try { if (depth == 0) { getDigester().getXMLReader().setContentHandler(oldContentHandler); getDigester().push(root); getDigester().endElement(namespaceURI, localName, qName); } top = top.getParentNode(); depth--; } catch (DOMException e) { throw new SAXException(e.getMessage(), e); } }
/** * Create and return a NodeIterator. The NodeIterator is * added to a list of NodeIterators so that it can be * removed to free up the DOM Nodes it references. * * @param root The root of the iterator. * @param whatToShow The whatToShow mask. * @param filter The NodeFilter installed. Null means no filter. * @param entityReferenceExpansion true to expand the contents of * EntityReference nodes * @since WD-DOM-Level-2-19990923 */ public NodeIterator createNodeIterator(Node root, int whatToShow, NodeFilter filter, boolean entityReferenceExpansion) { if (root == null) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null); throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg); } NodeIterator iterator = new NodeIteratorImpl(this, root, whatToShow, filter, entityReferenceExpansion); if (iterators == null) { iterators = new ArrayList<>(); } iterators.add(iterator); return iterator; }
/** * Remove the named attribute from this Element. If the removed Attribute * has a default value, it is immediately replaced thereby. * <P> * The default logic is actually implemented in NamedNodeMapImpl. * PR-DOM-Level-1-19980818 doesn't fully address the DTD, so some of this * behavior is likely to change in future versions. ????? * <P> * Note that this call "succeeds" even if no attribute by this name existed * -- unlike removeAttributeNode, which will throw a not-found exception in * that case. * * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if the node is * readonly. */ public void removeAttribute(String name) { if (ownerDocument.errorChecking && isReadOnly()) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } if (needsSyncData()) { synchronizeData(); } if (attributes == null) { return; } attributes.safeRemoveNamedItem(name); }
@Override public Attr createAttribute(String name) throws DOMException { boolean isQualifiedName = (name.indexOf(":") > 0); if (isQualifiedName) { String nsUri = null; String prefix = name.substring(0, name.indexOf(":")); //cannot do anything to resolve the URI if prefix is not //XMLNS. if (XMLNS.equals(prefix)) { nsUri = ElementImpl.XMLNS_URI; return createAttributeNS(nsUri, name); } } return document.createAttribute(name); }
private static DOMException newFeatureNotFoundError(String name) { String msg = DOMMessageFormatter.formatMessage ( DOMMessageFormatter.DOM_DOMAIN, "FEATURE_NOT_FOUND", new Object[] { name }); return new DOMException (DOMException.NOT_FOUND_ERR, msg); }
/** * Break a text node into two sibling nodes. (Note that if the current node * has no parent, they won't wind up as "siblings" -- they'll both be * orphans.) * * @param offset * The offset at which to split. If offset is at the end of the * available data, the second node will be empty. * * @return A reference to the new node (containing data after the offset * point). The original node will contain data up to that point. * * @throws DOMException(INDEX_SIZE_ERR) * if offset is <0 or >length. * * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) * if node is read-only. */ public Text splitText(int offset) throws DOMException { if (isReadOnly()) { throw new DOMException( DOMException.NO_MODIFICATION_ALLOWED_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null)); } if (needsSyncData()) { synchronizeData(); } if (offset < 0 || offset > data.length() ) { throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null)); } // split text into two separate nodes Text newText = getOwnerDocument().createTextNode(data.substring(offset)); setNodeValue(data.substring(0, offset)); // insert new text node Node parentNode = getParentNode(); if (parentNode != null) { parentNode.insertBefore(newText, nextSibling); } return newText; }
public void selectNodeContents(Node refNode) throws RangeException { if (fDocument.errorChecking) { if( fDetach) { throw new DOMException( DOMException.INVALID_STATE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null)); } if ( !isLegalContainer(refNode)) { throw new RangeExceptionImpl( RangeException.INVALID_NODE_TYPE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null)); } if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) { throw new DOMException( DOMException.WRONG_DOCUMENT_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null)); } } fStartContainer = refNode; fEndContainer = refNode; Node first = refNode.getFirstChild(); fStartOffset = 0; if (first == null) { fEndOffset = 0; } else { int i = 0; for (Node n = first; n!=null; n = n.getNextSibling()) { i++; } fEndOffset = i; } }
/** * 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. * <p> * 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 */ public Node insertBefore(Node newChild, Node refChild) throws DOMException { // Only one such child permitted int type = newChild.getNodeType(); if (errorChecking) { 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; }
/** * Replace a series of characters at the specified (zero-based) * offset with a new string, NOT necessarily of the same * length. Convenience method, equivalent to a delete followed by an * insert. Throws a DOMException if the specified offset is beyond * the end of the existing data. * * @param offset The offset at which to begin replacing. * * @param count The number of characters to remove, * interpreted as in the delete() method. * * @param data The new string to be inserted at offset in place of * the removed data. Note that the entire string will * be inserted -- the count parameter does not affect * insertion, and the new data may be longer or shorter * than the substring it replaces. * * @throws DOMException(INDEX_SIZE_ERR) if offset is negative or * greater than length, or if count is negative. * * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) if node is * readonly. */ public void replaceData(int offset, int count, String data) throws DOMException { CoreDocumentImpl ownerDocument = ownerDocument(); // The read-only check is done by deleteData() // ***** This could be more efficient w/r/t Mutation Events, // specifically by aggregating DOMAttrModified and // DOMSubtreeModified. But mutation events are // underspecified; I don't feel compelled // to deal with it right now. if (ownerDocument.errorChecking && isReadOnly()) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } if (needsSyncData()) { synchronizeData(); } //notify document ownerDocument.replacingData(this); // keep old value for document notification String oldvalue = this.data; internalDeleteData(offset, count, true); internalInsertData(offset, data, true); ownerDocument.replacedCharacterData(this, oldvalue, this.data); }
public Node insertBefore(org.w3c.dom.Node newChild, org.w3c.dom.Node refChild) throws DOMException { Node n = super.insertBefore(newChild, refChild); if (n instanceof Element) { if (getModel() == null || getModel().getStatus() != XDMModel.Status.PARSING) { consolidateNamespaces((Element)n); } } return n; }
/** For DOM2 support. */ public CoreDocumentImpl(DocumentType doctype, boolean grammarAccess) { this(grammarAccess); if (doctype != null) { DocumentTypeImpl doctypeImpl; try { doctypeImpl = (DocumentTypeImpl) doctype; } catch (ClassCastException e) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null); throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg); } doctypeImpl.ownerDocument = this; appendChild(doctype); } }
@Override public org.w3c.dom.Node importNode( org.w3c.dom.Node importedNode, boolean deep) throws DOMException { handleNewSource(); return document.importNode(importedNode, deep); }
/** * NON-DOM Factory method: creates an element definition. Element * definitions hold default attribute values. */ 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); }
public void setEnd(Node refNode, int offset) throws RangeException, DOMException { if (fDocument.errorChecking) { if (fDetach) { throw new DOMException( DOMException.INVALID_STATE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_STATE_ERR", null)); } if ( !isLegalContainer(refNode)) { throw new RangeExceptionImpl( RangeException.INVALID_NODE_TYPE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INVALID_NODE_TYPE_ERR", null)); } if ( fDocument != refNode.getOwnerDocument() && fDocument != refNode) { throw new DOMException( DOMException.WRONG_DOCUMENT_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null)); } } checkIndex(refNode, offset); fEndContainer = refNode; fEndOffset = offset; // If one boundary-point of a Range is set to have a root container // other // than the current one for the Range, the Range should be collapsed to // the new position. // The start position of a Range should never be after the end position. if (getCommonAncestorContainer() == null || (fStartContainer == fEndContainer && fEndOffset < fStartOffset)) { collapse(false); } }
/** * Sets the node value. * @throws DOMException(NO_MODIFICATION_ALLOWED_ERR) */ public void setNodeValue(String x) throws DOMException { if (ownerDocument.errorChecking && isReadOnly()) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null); throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, msg); } }
@Test(expectedExceptions = DOMException.class) public void testReplaceChildNeg() throws Exception { Document document = createDOM("Node04.xml"); Document doc2 = createNewDocument(); Element parentElement = (Element) document.getElementsByTagName("to").item(0); Element element = (Element) document.getElementsByTagName("sender").item(0); parentElement.replaceChild(createTestDocumentFragment(doc2), element); }
public void setEnd(TimeList end) throws DOMException { mElementTime.setEnd(end); }
@Override public void setPrefix(String arg0) throws DOMException { document.setPrefix(arg0); }
public void setIdAttributeNS(String namespaceURI, String localName, boolean makeId) throws DOMException{ throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported"); }
public void insertData( int offset, String arg ) throws DOMException { }
protected static ArrayList<Section> body(Document document, XPath xPath) throws XPathExpressionException, DOMException { NodeList nodeSections = (NodeList) xPath.compile("/article/body/sec").evaluate(document, XPathConstants.NODESET); ArrayList<Section> listSections = new ArrayList<Section>(); for (int i = 0; i < nodeSections.getLength(); i++) { Section section = new Section(); section.setType(""); Node nodeSection = nodeSections.item(i); sectionParsing(xPath, section, nodeSection); listSections.add(section); NodeList nodeSubSections = (NodeList) xPath.compile("sec").evaluate(nodeSection, XPathConstants.NODESET); if (nodeSubSections != null) { // set subsections ArrayList<Section> subListSections = new ArrayList<Section>(); section.setSecContent(subListSections); for (int ii = 0; ii < nodeSubSections.getLength(); ii++) { Section subSection = new Section(); subSection.setType("sub"); Node nodeSubSection = nodeSubSections.item(ii); sectionParsing(xPath, subSection, nodeSubSection); subListSections.add(subSection); NodeList nodeSubSubSections = (NodeList) xPath.compile("sec").evaluate(nodeSubSection, XPathConstants.NODESET); if (nodeSubSubSections != null) { //set subsubsections ArrayList<Section> subSubListSections = new ArrayList<Section>(); subSection.setSecContent(subSubListSections); for (int iii = 0; iii < nodeSubSubSections.getLength(); iii++) { Section subSubSection = new Section(); subSubSection.setType("subsub"); Node nodeSubSubSection = nodeSubSubSections.item(iii); sectionParsing(xPath, subSubSection, nodeSubSubSection); subSubListSections.add(subSubSection); } } } } } return listSections; }
public Node setNamedItem(Node arg) { throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR, "This NamedNodeMap is read-only!"); }
public void removeAttributeNS(String namespaceURI, String localName) throws DOMException { delegate.removeAttributeNS(namespaceURI, localName); }
public void deleteData( int offset, int count ) throws DOMException { }
/** * Introduced in DOM Level 2. <p> * * Creates an XML Document object of the specified type with its document * element. * * @param namespaceURI The namespace URI of the document * element to create, or null. * @param qualifiedName The qualified name of the document * element to create. * @param doctype The type of document to be created or null.<p> * * When doctype is not null, its * Node.ownerDocument attribute is set to * the document being created. * @return Document A new Document object. * @throws DOMException WRONG_DOCUMENT_ERR: Raised if doctype has * already been used with a different document. * @since WD-DOM-Level-2-19990923 */ public Document createDocument( String namespaceURI, String qualifiedName, DocumentType doctype) throws DOMException { if (doctype != null && doctype.getOwnerDocument() != null) { String msg = DOMMessageFormatter.formatMessage( DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null); throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg); } CoreDocumentImpl doc = new CoreDocumentImpl(doctype); Element e = doc.createElementNS(namespaceURI, qualifiedName); doc.appendChild(e); return doc; }
public void setType(String type) throws DOMException { this.setAttribute("type", type); }
public void setTitle(String title) throws DOMException { this.setAttribute(TITLE_ATTRIBUTE_NAME, title); }
public String getNodeValue() throws DOMException { return getData(); }
@Override public Attr getAttributeNodeNS(String namespaceURI, String localName) throws DOMException { return element.getAttributeNodeNS(namespaceURI, localName); }
/** * * * @see org.w3c.dom.Document */ @Override public final DocumentFragment createDocumentFragment() { throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); }
public org.w3c.dom.Node adoptNode(org.w3c.dom.Node node) throws org.w3c.dom.DOMException { throw new ROException(); }
void getTextContent(StringBuffer buf) throws DOMException { String content = getNodeValue(); if (content != null) { buf.append(content); } }
/** * Introduced in DOM Level 2. <p> * * Creates an XML Document object of the specified type with its document * element. * * @param namespaceURI The namespace URI of the document * element to create, or null. * @param qualifiedName The qualified name of the document * element to create. * @param doctype The type of document to be created or null.<p> * * When doctype is not null, its * Node.ownerDocument attribute is set to * the document being created. * @return Document A new Document object. * @throws DOMException WRONG_DOCUMENT_ERR: Raised if doctype has * already been used with a different document. * @since WD-DOM-Level-2-19990923 */ public Document createDocument(String namespaceURI, String qualifiedName, DocumentType doctype) throws DOMException { if(namespaceURI == null && qualifiedName == null && doctype == null){ //if namespaceURI, qualifiedName and doctype are null, returned document is empty with //no document element return new DocumentImpl(); } else if (doctype != null && doctype.getOwnerDocument() != null) { String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null); throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg); } DocumentImpl doc = new DocumentImpl(doctype); Element e = doc.createElementNS( namespaceURI, qualifiedName); doc.appendChild(e); return doc; }
@Test(dataProvider = "invalid-nsuri", expectedExceptions = DOMException.class) public void testCreateAttributeNSNeg(String namespaceURI, String name) throws Exception { Document document = createDOMWithNS("DocumentTest01.xml"); document.createAttributeNS(namespaceURI, name); }
@Override public Node removeNamedItem(String name) throws DOMException { return namedNodeMap.removeNamedItem(name); }
@Override public Document createDocument(String namespaceURI,String qualfiedName,DocumentType doctype) { // Could create a DTM... but why, when it'd have to be permanantly empty? throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); }
@Test(expectedExceptions = DOMException.class) public void testSetAttributeNeg() throws Exception { Document document = createDOM("ElementSample02.xml"); Element elemNode = document.createElement("pricetag2"); elemNode.setAttribute(null, null); }