org.w3c.dom.DOMException Java Examples

The following examples show how to use org.w3c.dom.DOMException. 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 File: ElementImpl.java    From openjdk-8 with 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 #2
Source File: QueryNodeXML.java    From Extractor with 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 #3
Source File: XLSXmlParser.java    From org.hl7.fhir.core with 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 #4
Source File: CoreDocumentImpl.java    From openjdk-8 with 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 #5
Source File: TreeWalkerImpl.java    From JDKSourceCode1.8 with 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 #6
Source File: IIOMetadataNode.java    From dragonwell8_jdk with GNU General Public License v2.0 5 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 void setIdAttributeNode(Attr idAttr,
                               boolean isId)
                               throws DOMException {
    throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                           "Method not supported");
}
 
Example #7
Source File: CoreDocumentImpl.java    From Bytecoder with 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 #8
Source File: XmlNodeHashtable.java    From openbd-core with 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 #9
Source File: XMLUtil.java    From webdsl with 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 #10
Source File: DomXmlElement.java    From camunda-spin with 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 #11
Source File: CoreDocumentImpl.java    From jdk1.8-source-analysis with 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 #12
Source File: DefaultNode.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public String getNodeValue() throws DOMException {
    return null;
}
 
Example #13
Source File: PSVIDOMImplementationImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
Example #14
Source File: IIOMetadataNode.java    From JDKSourceCode1.8 with 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 #15
Source File: DocumentTypeImpl.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Override public String getTextContent() throws DOMException {
    return null;
}
 
Example #16
Source File: DocumentTypeImpl.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public String getTextContent() throws DOMException {
    return null;
}
 
Example #17
Source File: DOMCharacterData.java    From lemminx with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public String substringData(int offset, int count) throws DOMException {
	throw new UnsupportedOperationException();
}
 
Example #18
Source File: AbstractStyle.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void setMaxWidth( String maxWidth ) throws DOMException
{
	throw createUnsupportedPropertyException( "text-decoration" );
}
 
Example #19
Source File: CharacterDataImpl.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 #20
Source File: DefaultNode.java    From JDKSourceCode1.8 with 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 #21
Source File: ElementImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void setPrefix(String prefix) throws DOMException {
    element.setPrefix(prefix);
}
 
Example #22
Source File: AttributeMap.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/***/
public Node removeNamedItem(String name)
    throws DOMException {
    return internalRemoveNamedItem(name, true);
}
 
Example #23
Source File: SVGDocument.java    From latexdraw with 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 #24
Source File: AbstractStyle.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
public void setPadding( String padding ) throws DOMException
{
	throw createUnsupportedPropertyException( "text-decoration" );
}
 
Example #25
Source File: CoreDocumentImpl.java    From jdk1.8-source-analysis with 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 File: DefaultNode.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void setTextContent(String textContent)throws DOMException{
    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Method not supported");
}
 
Example #27
Source File: NodeWrapper.java    From caja with 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 #28
Source File: SVGDocument.java    From latexdraw with 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 #29
Source File: ConfigurationUtils.java    From hadoop with 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 #30
Source File: SVGText.java    From latexdraw with 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);
}