Java Code Examples for org.w3c.dom.Node#toString()

The following examples show how to use org.w3c.dom.Node#toString() .
Example 1
Project: jdk1.8-source-analysis   File: W3CDomHandler.java    License: Apache License 2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 2
Project: TencentKona-8   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 3
Project: jdk8u60   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 4
Project: JDKSourceCode1.8   File: W3CDomHandler.java    License: MIT License 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 5
Project: openjdk-jdk8u   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 6
Project: openjdk-jdk8u-backup   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 7
Project: openjdk-jdk9   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 8
Project: Java8CN   File: W3CDomHandler.java    License: Apache License 2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 9
Project: hottub   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 10
Project: openjdk-8-source   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 11
Project: openjdk-8   File: W3CDomHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
public Element getElement(DOMResult r) {
    // JAXP spec is ambiguous about what really happens in this case,
    // so work defensively
    Node n = r.getNode();
    if( n instanceof Document ) {
        return ((Document)n).getDocumentElement();
    }
    if( n instanceof Element )
        return (Element)n;
    if( n instanceof DocumentFragment )
        return (Element)n.getChildNodes().item(0);

    // if the result object contains something strange,
    // it is not a user problem, but it is a JAXB provider's problem.
    // That's why we throw a runtime exception.
    throw new IllegalStateException(n.toString());
}
 
Example 12
Project: OpenAs2App   File: XMLUtil.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Map<String, String> mapAttributeNodes(NodeList nodes, String nodeName, String nodeKeyName, String nodeValueName) throws OpenAS2Exception {
    Map<String, String> attributes = new HashMap<String, String>();
    int nodeCount = nodes.getLength();
    Node attrNode;
    NamedNodeMap nodeAttributes;
    Node tmpNode;
    String attrName;
    String attrValue;

    for (int i = 0; i < nodeCount; i++) {
        attrNode = nodes.item(i);

        if (attrNode.getNodeName().equals(nodeName)) {
            nodeAttributes = attrNode.getAttributes();
            tmpNode = nodeAttributes.getNamedItem(nodeKeyName);

            if (tmpNode == null) {
                throw new OpenAS2Exception(attrNode.toString() + " does not have key attribute: " + nodeKeyName);
            }

            attrName = tmpNode.getNodeValue();
            tmpNode = nodeAttributes.getNamedItem(nodeValueName);

            if (tmpNode == null) {
                throw new OpenAS2Exception(attrNode.toString() + " does not have value attribute: " + nodeValueName);
            }

            attrValue = tmpNode.getNodeValue();
            attributes.put(attrName, attrValue);
        }
    }

    return attributes;
}
 
Example 13
Project: OpenAs2App   File: XMLUtil.java    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Map<String, String> mapAttributes(Node node, String[] requiredAttributes) throws OpenAS2Exception {
    Map<String, String> attributes = mapAttributes(node);
    String attrName;

    for (String requiredAttribute : requiredAttributes) {
        attrName = requiredAttribute;

        if (attributes.get(attrName) == null) {
            throw new OpenAS2Exception(node.toString() + " is missing required attribute: " + attrName);
        }
    }

    return attributes;
}
 
Example 14
Project: cs-actions   File: XmlUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static String nodeToString(Node node) throws TransformerException {

        if (node == null) {
            return EMPTY;
        } else if (node.getNodeType() == Node.ATTRIBUTE_NODE) {
            return node.toString();
        } else {
            return transformElementNode(node);
        }
    }
 
Example 15
Project: buck   File: MiniAapt.java    License: Apache License 2.0 5 votes vote down vote up
private Node verifyNodeHasTypeAttribute(Path valuesFile, Node node)
    throws ResourceParseException {
  Node typeNode = node.getAttributes().getNamedItem("type");
  if (typeNode == null || typeNode.getNodeValue().isEmpty()) {
    throw new ResourceParseException(
        "Error parsing file '%s', expected a 'type' attribute in: \n'%s'\n",
        valuesFile, node.toString());
  }
  return typeNode;
}
 
Example 16
Project: ph-schematron   File: LoggingPSValidationHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getAsString (@Nonnull final Node aNode)
{
  return XMLDebug.getNodeTypeAsString (aNode.getNodeType ()) + ": " + aNode.toString ();
}