Java Code Examples for org.w3c.dom.DOMException

The following examples show how to use org.w3c.dom.DOMException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: org.hl7.fhir.core   Source File: XLSXmlParser.java    License: Apache License 2.0 6 votes vote down vote up
private String readData(Element cell, int col, String s) throws DOMException, FHIRException  {
  List<Element> data = new ArrayList<Element>(); 
  XMLUtil.getNamedChildren(cell, "Data", data); // cell.getElementsByTagNameNS(XLS_NS, "Data");
  if (data.size() == 0)
    return "";
  check(data.size() == 1, "Multiple Data encountered ("+Integer.toString(data.size())+" @ col "+Integer.toString(col)+" - "+cell.getTextContent()+" ("+s+"))");
  Element d = data.get(0);
  String type = d.getAttributeNS(XLS_NS, "Type");
  if ("Boolean".equals(type)) {
    if (d.getTextContent().equals("1"))
      return "True";
    else
      return "False";
  } else if ("String".equals(type)) {
    return d.getTextContent();
  } else if ("Number".equals(type)) {
    return d.getTextContent();
  } else if ("DateTime".equals(type)) {
    return d.getTextContent();
  } else if ("Error".equals(type)) {
    return null;
  } else 
    throw new FHIRException("Cell Type is not known ("+d.getAttributeNodeNS(XLS_NS, "Type")+") in "+getLocation());
}
 
Example 2
Source Project: openjdk-8   Source File: ElementImpl.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Introduced in DOM Level 2. <p>
 *
 * Removes an attribute by local name and namespace URI. If the removed
 * attribute has a default value it is immediately replaced.
 * The replacing attribute has the same namespace URI and local name,
 * as well as the original prefix.<p>
 *
 * @param namespaceURI  The namespace URI of the attribute to remove.
 *
 * @param localName     The local name of the attribute to remove.
 * @throws                  NO_MODIFICATION_ALLOWED_ERR: Raised if this
 *                          node is readonly.
 * @since WD-DOM-Level-2-19990923
 */
public void removeAttributeNS(String namespaceURI, String localName) {

    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.safeRemoveNamedItemNS(namespaceURI, localName);

}
 
Example 3
Source Project: Extractor   Source File: QueryNodeXML.java    License: MIT License 6 votes vote down vote up
@Override
public byte[] repackData(byte[] context, byte[] data) {
    String xmldata = Globals.helpers.bytesToString(context);
    InputStream is = new ByteArrayInputStream(context);

    try { //copy payload to XML structure and rewrite xml to the query
        DocumentBuilder dBuilder = getsafeDB();
        Document doc = dBuilder.parse(is);
        doc.getDocumentElement().normalize();
        NodeList nList = doc.getElementsByTagName(setting[0]);
        nList.item(0).setTextContent(Globals.helpers.bytesToString(data));

        TransformerFactory tf = TransformerFactory.newInstance();
        Transformer transformer = tf.newTransformer();
        StringWriter writer = new StringWriter();
        transformer.transform(new DOMSource(doc), new StreamResult(writer));
        xmldata = writer.getBuffer().toString();
    } 
    catch (IOException | IllegalArgumentException | ParserConfigurationException | TransformerException | DOMException | SAXException e) {
        Globals.callbacks.printError("XML packing error: ");
        Globals.callbacks.printError(e.getMessage());
        xmldata = Globals.helpers.bytesToString(context);
    }
return xmldata.getBytes();
}
 
Example 4
Source Project: JDKSourceCode1.8   Source File: TreeWalkerImpl.java    License: MIT License 5 votes vote down vote up
/** Return the current Node. */
public void               setCurrentNode(Node node) {
    if (node == null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
          throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
    }

    fCurrentNode = node;
}
 
Example 5
Source Project: jdk1.8-source-analysis   Source File: CoreDocumentImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the given qualified name is legal with respect
 * to the version of XML to which this document must conform.
 *
 * @param prefix prefix of qualified name
 * @param local local part of qualified name
 */
protected final void checkQName(String prefix, String local) {
    if (!errorChecking) {
        return;
    }

    // check that both prefix and local part match NCName
    boolean validNCName = false;
    if (!xml11Version) {
        validNCName = (prefix == null || XMLChar.isValidNCName(prefix))
                && XMLChar.isValidNCName(local);
    }
    else {
        validNCName = (prefix == null || XML11Char.isXML11ValidNCName(prefix))
                && XML11Char.isXML11ValidNCName(local);
    }

    if (!validNCName) {
        // REVISIT: add qname parameter to the message
        String msg =
        DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "INVALID_CHARACTER_ERR",
                        null);
        throw new DOMException(DOMException.INVALID_CHARACTER_ERR, msg);
    }
}
 
Example 6
Source Project: openbd-core   Source File: XmlNodeHashtable.java    License: GNU General Public License v3.0 5 votes vote down vote up
protected cfData getXmlValue() {
	String nv = null;
	try {
		nv = nodeData.getNodeValue();
	} catch (DOMException ex) {
		// Just log it
		com.nary.Debug.printStackTrace(ex);
	}
	if (nv == null)
		return new cfStringData("");
	else
		return new cfStringData(nv.trim());
}
 
Example 7
Source Project: camunda-spin   Source File: DomXmlElement.java    License: Apache License 2.0 5 votes vote down vote up
public SpinXmlElement append(SpinXmlElement... childElements) {
  ensureNotNull("childElements", childElements);
  for (SpinXmlElement childElement : childElements) {
    ensureNotNull("childElement", childElement);
    DomXmlElement spinDomElement = ensureParamInstanceOf("childElement", childElement, DomXmlElement.class);
    adoptElement(spinDomElement);
    try {
      domElement.appendChild(spinDomElement.domElement);
    }
    catch (DOMException e) {
      throw LOG.unableToAppendElementInImplementation(this, childElement, e);
    }
  }
  return this;
}
 
Example 8
Source Project: Bytecoder   Source File: CoreDocumentImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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;

}
 
Example 9
Source Project: openjdk-8   Source File: CoreDocumentImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/** 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);
    }
}
 
Example 10
Source Project: webdsl   Source File: XMLUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void setValue( org.w3c.dom.Node n, String val){
	try{
		if(n.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE){
			n.setTextContent(val);
		} else {
			n.setNodeValue(val);
		}
	} catch(DOMException ex){
		Logger.error(ex);
	}
}
 
Example 11
/**
 * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
 * and will throw a {@code DOMException}.
 * @throws DOMException - always.
 */
public void setIdAttributeNode(Attr idAttr,
                               boolean isId)
                               throws DOMException {
    throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                           "Method not supported");
}
 
Example 12
Source Project: jdk8u60   Source File: IIOMetadataNode.java    License: GNU General Public License v2.0 4 votes vote down vote up
public Node setNamedItem(Node arg) {
    throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
                           "This NamedNodeMap is read-only!");
}
 
Example 13
/**
 * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
 * and will throw a {@code DOMException}.
 * @throws DOMException - always.
 */
public short compareDocumentPosition(Node other)
                                     throws DOMException {
    throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                           "Method not supported");
}
 
Example 14
Source Project: birt   Source File: AbstractStyle.java    License: Eclipse Public License 1.0 4 votes vote down vote up
public void setMaxWidth( String maxWidth ) throws DOMException
{
	throw createUnsupportedPropertyException( "text-decoration" );
}
 
Example 15
/**
 * 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;
}
 
Example 16
Source Project: lemminx   Source File: DOMDocument.java    License: Eclipse Public License 2.0 4 votes vote down vote up
@Override
public EntityReference createEntityReference(String name) throws DOMException {
	throw new UnsupportedOperationException();
}
 
Example 17
Source Project: JDKSourceCode1.8   Source File: DefaultNode.java    License: MIT License 4 votes vote down vote up
public Node appendChild(Node newChild) throws DOMException {
    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported");
}
 
Example 18
/**
 * Substring is more than a convenience function. In some
 * implementations of the DOM, where the stored data may exceed the
 * length that can be returned in a single string, the only way to
 * read it all is to extract it in chunks via this method.
 *
 * @param offset        Zero-based offset of first character to retrieve.
 * @param count Number of characters to retrieve.
 *
 * If the sum of offset and count exceeds the length, all characters
 * to end of data are returned.
 *
 * @throws DOMException(INDEX_SIZE_ERR) if offset is negative or
 * greater than length, or if count is negative.
 *
 * @throws DOMException(WSTRING_SIZE_ERR) In some implementations,
 * count may exceed the permitted length of strings. If so,
 * substring() will throw this DOMException advising the user to
 * instead retrieve the data in smaller chunks.
 */
public String substringData(int offset, int count)
    throws DOMException {

    if (needsSyncData()) {
        synchronizeData();
    }

    int length = data.length();
    if (count < 0 || offset < 0 || offset > length - 1) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null);
        throw new DOMException(DOMException.INDEX_SIZE_ERR, msg);
    }

    int tailIndex = Math.min(offset + count, length);

    return data.substring(offset, tailIndex);

}
 
Example 19
Source Project: openjdk-jdk9   Source File: AttrImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * The DOM doesn't clearly define what setValue(null) means. I've taken it
 * as "remove all children", which from outside should appear
 * similar to setting it to the empty string.
 */
public void setValue(String newvalue) {

    CoreDocumentImpl ownerDocument = ownerDocument();

    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);
    }

    Element ownerElement = getOwnerElement();
    String oldvalue = "";
    if (needsSyncData()) {
        synchronizeData();
    }
    if (needsSyncChildren()) {
        synchronizeChildren();
    }
    if (value != null) {
        if (ownerDocument.getMutationEvents()) {
            // Can no longer just discard the kids; they may have
            // event listeners waiting for them to disconnect.
            if (hasStringValue()) {
                oldvalue = (String) value;
                // create an actual text node as our child so
                // that we can use it in the event
                if (textNode == null) {
                    textNode = (TextImpl)
                        ownerDocument.createTextNode((String) value);
                }
                else {
                    textNode.data = (String) value;
                }
                value = textNode;
                textNode.isFirstChild(true);
                textNode.previousSibling = textNode;
                textNode.ownerNode = this;
                textNode.isOwned(true);
                hasStringValue(false);
                internalRemoveChild(textNode, true);
            }
            else {
                oldvalue = getValue();
                while (value != null) {
                    internalRemoveChild((Node) value, true);
                }
            }
        }
        else {
            if (hasStringValue()) {
                oldvalue = (String) value;
            }
            else {
                // simply discard children if any
                oldvalue = getValue();
                // remove ref from first child to last child
                ChildNode firstChild = (ChildNode) value;
                firstChild.previousSibling = null;
                firstChild.isFirstChild(false);
                firstChild.ownerNode = ownerDocument;
            }
            // then remove ref to current value
            value = null;
            needsSyncChildren(false);
        }
        if (isIdAttribute() && ownerElement != null) {
            ownerDocument.removeIdentifier(oldvalue);
        }
    }

    // Create and add the new one, generating only non-aggregate events
    // (There are no listeners on the new Text, but there may be
    // capture/bubble listeners on the Attr.
    // Note that aggregate events are NOT dispatched here,
    // since we need to combine the remove and insert.
    isSpecified(true);
    if (ownerDocument.getMutationEvents()) {
        // if there are any event handlers create a real node
        internalInsertBefore(ownerDocument.createTextNode(newvalue),
                             null, true);
        hasStringValue(false);
        // notify document
        ownerDocument.modifiedAttrValue(this, oldvalue);
    } else {
        // directly store the string
        value = newvalue;
        hasStringValue(true);
        changed();
    }
    if (isIdAttribute() && ownerElement != null) {
        ownerDocument.putIdentifier(newvalue, ownerElement);
    }

}
 
Example 20
Source Project: openjdk-jdk9   Source File: DocumentTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions = DOMException.class)
public void testCreateElementNeg() throws Exception {
    Document doc = createNewDocument();
    doc.createElement("!nc$%^*(!");
}
 
Example 21
Source Project: TencentKona-8   Source File: DefaultNode.java    License: GNU General Public License v2.0 4 votes vote down vote up
public String getNodeValue() throws DOMException {
    return null;
}
 
Example 22
Source Project: JDKSourceCode1.8   Source File: IIOMetadataNode.java    License: MIT License 4 votes vote down vote up
/**
 * This DOM Level 3 method is not supported for {@code IIOMetadataNode}
 * and will throw a {@code DOMException}.
 * @throws DOMException - always.
 */
public Object getFeature(String feature, String version)
                          throws DOMException {
    throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                           "Method not supported");
}
 
Example 23
Source Project: openjdk-jdk9   Source File: ElementImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setPrefix(String prefix) throws DOMException {
    element.setPrefix(prefix);
}
 
Example 24
Source Project: latexdraw   Source File: SVGDocument.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public DOMConfiguration getDomConfig() {
	throw new DOMException(DOMException.INVALID_ACCESS_ERR, ACTION_NOT_IMPLEMENTED);
}
 
Example 25
Source Project: jdk1.8-source-analysis   Source File: CoreDocumentImpl.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Call user data handlers to let them know the nodes they are related to
 * are being deleted. The alternative would be to do that on Node but
 * because the nodes are used as the keys we have a reference to them that
 * prevents them from being gc'ed until the document is. At the same time,
 * doing it here has the advantage of avoiding a finalize() method on Node,
 * which would affect all nodes and not just the ones that have a user
 * data.
 */
// Temporarily comment out this method, because
// 1. It seems that finalizers are not guaranteed to be called, so the
//    functionality is not implemented.
// 2. It affects the performance greatly in multi-thread environment.
// -SG
/*public void finalize() {
 if (userData == null) {
 return;
 }
 Enumeration nodes = userData.keys();
 while (nodes.hasMoreElements()) {
 Object node = nodes.nextElement();
 Hashtable t = (Hashtable) userData.get(node);
 if (t != null && !t.isEmpty()) {
 Enumeration keys = t.keys();
 while (keys.hasMoreElements()) {
 String key = (String) keys.nextElement();
 UserDataRecord r = (UserDataRecord) t.get(key);
 if (r.fHandler != null) {
 r.fHandler.handle(UserDataHandler.NODE_DELETED,
 key, r.fData, null, null);
 }
 }
 }
 }
 }*/

protected final void checkNamespaceWF( String qname, int colon1,
        int colon2) {

    if (!errorChecking) {
        return;
    }
    // it is an error for NCName to have more than one ':'
    // check if it is valid QName [Namespace in XML production 6]
    // :camera , nikon:camera:minolta, camera:
    if (colon1 == 0 || colon1 == qname.length() - 1 || colon2 != colon1) {
        String msg =
        DOMMessageFormatter.formatMessage(
                        DOMMessageFormatter.DOM_DOMAIN,
                        "NAMESPACE_ERR",
                        null);
        throw new DOMException(DOMException.NAMESPACE_ERR, msg);
    }
}
 
Example 26
Source Project: caja   Source File: NodeWrapper.java    License: Apache License 2.0 4 votes vote down vote up
public Node appendChild(Node arg0) throws DOMException {
  return membrane.wrap(
      underlying.appendChild(membrane.unwrap(arg0, Node.class)),
      Node.class);
}
 
Example 27
Source Project: latexdraw   Source File: SVGDocument.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getBaseURI() {
	throw new DOMException(DOMException.INVALID_ACCESS_ERR, ACTION_NOT_IMPLEMENTED);
}
 
Example 28
Source Project: hadoop   Source File: ConfigurationUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static void parseDocument(Configuration conf, Document doc) throws IOException {
  try {
    Element root = doc.getDocumentElement();
    if (!"configuration".equals(root.getTagName())) {
      throw new IOException("bad conf file: top-level element not <configuration>");
    }
    NodeList props = root.getChildNodes();
    for (int i = 0; i < props.getLength(); i++) {
      Node propNode = props.item(i);
      if (!(propNode instanceof Element)) {
        continue;
      }
      Element prop = (Element) propNode;
      if (!"property".equals(prop.getTagName())) {
        throw new IOException("bad conf file: element not <property>");
      }
      NodeList fields = prop.getChildNodes();
      String attr = null;
      String value = null;
      for (int j = 0; j < fields.getLength(); j++) {
        Node fieldNode = fields.item(j);
        if (!(fieldNode instanceof Element)) {
          continue;
        }
        Element field = (Element) fieldNode;
        if ("name".equals(field.getTagName()) && field.hasChildNodes()) {
          attr = ((Text) field.getFirstChild()).getData().trim();
        }
        if ("value".equals(field.getTagName()) && field.hasChildNodes()) {
          value = ((Text) field.getFirstChild()).getData();
        }
      }

      if (attr != null && value != null) {
        conf.set(attr, value);
      }
    }

  } catch (DOMException e) {
    throw new IOException(e);
  }
}
 
Example 29
Source Project: latexdraw   Source File: SVGText.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public String getWholeText() {
	throw new DOMException(DOMException.INVALID_ACCESS_ERR, SVGDocument.ACTION_NOT_IMPLEMENTED);
}
 
Example 30
Source Project: Bytecoder   Source File: AttributeMap.java    License: Apache License 2.0 4 votes vote down vote up
/***/
public Node removeNamedItem(String name)
    throws DOMException {
    return internalRemoveNamedItem(name, true);
}