Example usage for org.w3c.dom Node NOTATION_NODE

List of usage examples for org.w3c.dom Node NOTATION_NODE

Introduction

In this page you can find the example usage for org.w3c.dom Node NOTATION_NODE.

Prototype

short NOTATION_NODE

To view the source code for org.w3c.dom Node NOTATION_NODE.

Click Source Link

Document

The node is a Notation.

Usage

From source file:Main.java

public static String getTextContent(final Node node) {
    switch (node.getNodeType()) {
    case Node.ELEMENT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ENTITY_NODE:
    case Node.ENTITY_REFERENCE_NODE:
    case Node.DOCUMENT_FRAGMENT_NODE:
        return mergeTextContent(node.getChildNodes());
    case Node.TEXT_NODE:
    case Node.CDATA_SECTION_NODE:
    case Node.COMMENT_NODE:
    case Node.PROCESSING_INSTRUCTION_NODE:
        return node.getNodeValue();
    case Node.DOCUMENT_NODE:
    case Node.DOCUMENT_TYPE_NODE:
    case Node.NOTATION_NODE:
    default:/*w w  w .jav a  2  s.  c om*/
        return null;
    }
}

From source file:Main.java

/**
 * based on public Java5 javadoc of org.w3c.dom.Node.getTextContent method
 *///  w  ww .  j a va2 s  . c  om
public static String getTextContent(Node node) {
    switch (node.getNodeType()) {
    case Node.ELEMENT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ENTITY_NODE:
    case Node.ENTITY_REFERENCE_NODE:
    case Node.DOCUMENT_FRAGMENT_NODE:
        return mergeTextContent(node.getChildNodes());
    case Node.TEXT_NODE:
    case Node.CDATA_SECTION_NODE:
    case Node.COMMENT_NODE:
    case Node.PROCESSING_INSTRUCTION_NODE:
        return node.getNodeValue();
    case Node.DOCUMENT_NODE:
    case Node.DOCUMENT_TYPE_NODE:
    case Node.NOTATION_NODE:
    default:
        return null;
    }
}

From source file:Main.java

/**
 * returns the Node Type As String//from  ww w  . j av  a2  s.c o m
 * @param node
 * @param cftype 
 * @return
 */
public static String getTypeAsString(Node node, boolean cftype) {
    String suffix = cftype ? "" : "_NODE";

    switch (node.getNodeType()) {
    case Node.ATTRIBUTE_NODE:
        return "ATTRIBUTE" + suffix;
    case Node.CDATA_SECTION_NODE:
        return "CDATA_SECTION" + suffix;
    case Node.COMMENT_NODE:
        return "COMMENT" + suffix;
    case Node.DOCUMENT_FRAGMENT_NODE:
        return "DOCUMENT_FRAGMENT" + suffix;
    case Node.DOCUMENT_NODE:
        return "DOCUMENT" + suffix;
    case Node.DOCUMENT_TYPE_NODE:
        return "DOCUMENT_TYPE" + suffix;
    case Node.ELEMENT_NODE:
        return "ELEMENT" + suffix;
    case Node.ENTITY_NODE:
        return "ENTITY" + suffix;
    case Node.ENTITY_REFERENCE_NODE:
        return "ENTITY_REFERENCE" + suffix;
    case Node.NOTATION_NODE:
        return "NOTATION" + suffix;
    case Node.PROCESSING_INSTRUCTION_NODE:
        return "PROCESSING_INSTRUCTION" + suffix;
    case Node.TEXT_NODE:
        return "TEXT" + suffix;
    default:
        return "UNKNOW" + suffix;
    }
}

From source file:Main.java

/**
 * Convert a node type to a string. For debug purpose only.
 * //from  ww w  . j av  a 2  s . c o m
 * @param nodeType
 *            the node type
 * @return the string
 * @throws Exception
 *             the exception
 */
public static String nodeTypeToString(short nodeType) throws Exception {
    if (nodeType == Node.ELEMENT_NODE)
        return "ELEMENT_NODE";
    if (nodeType == Node.ATTRIBUTE_NODE)
        return "ATTRIBUTE_NODE";
    if (nodeType == Node.TEXT_NODE)
        return "TEXT_NODE";
    if (nodeType == Node.CDATA_SECTION_NODE)
        return "CDATA_SECTION_NODE";
    if (nodeType == Node.ENTITY_REFERENCE_NODE)
        return "ENTITY_REFERENCE_NODE";
    if (nodeType == Node.ENTITY_NODE)
        return "ENTITY_NODE";
    if (nodeType == Node.PROCESSING_INSTRUCTION_NODE)
        return "PROCESSING_INSTRUCTION_NODE";
    if (nodeType == Node.COMMENT_NODE)
        return "COMMENT_NODE";
    if (nodeType == Node.DOCUMENT_NODE)
        return "DOCUMENT_NODE";
    if (nodeType == Node.DOCUMENT_TYPE_NODE)
        return "DOCUMENT_TYPE_NODE";
    if (nodeType == Node.DOCUMENT_FRAGMENT_NODE)
        return "DOCUMENT_FRAGMENT_NODE";
    if (nodeType == Node.NOTATION_NODE)
        return "NOTATION_NODE";
    if (nodeType == Node.DOCUMENT_POSITION_DISCONNECTED)
        return "DOCUMENT_POSITION_DISCONNECTED";
    if (nodeType == Node.DOCUMENT_POSITION_PRECEDING)
        return "DOCUMENT_POSITION_PRECEDING";
    if (nodeType == Node.DOCUMENT_POSITION_FOLLOWING)
        return "DOCUMENT_POSITION_FOLLOWING";
    if (nodeType == Node.DOCUMENT_POSITION_CONTAINS)
        return "DOCUMENT_POSITION_CONTAINS";
    if (nodeType == Node.DOCUMENT_POSITION_CONTAINED_BY)
        return "DOCUMENT_POSITION_CONTAINED_BY";
    if (nodeType == Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC)
        return "DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC";

    throw new Exception("Unknown value : " + nodeType);
}

From source file:Main.java

private static String getTextContent(final Node node) {
    switch (node.getNodeType()) {
    case Node.ELEMENT_NODE:
    case Node.ATTRIBUTE_NODE:
    case Node.ENTITY_NODE:
    case Node.ENTITY_REFERENCE_NODE:
    case Node.DOCUMENT_FRAGMENT_NODE:
        return mergeTextContent(node.getChildNodes());
    case Node.TEXT_NODE:
    case Node.CDATA_SECTION_NODE:
    case Node.COMMENT_NODE:
    case Node.PROCESSING_INSTRUCTION_NODE:
        return node.getNodeValue();
    case Node.DOCUMENT_NODE:
    case Node.DOCUMENT_TYPE_NODE:
    case Node.NOTATION_NODE:
    default:// w  ww.  j av  a 2s  .  c o  m
        return null;
    }
}

From source file:Main.java

/**
 * Gets Node type String for a given node type constant
 *//*from  w  w w  .j ava 2  s  .co m*/

public static String getNodeTypeStr(int nodeType)

{

    switch (nodeType)

    {

    case Node.ATTRIBUTE_NODE:

        return "ATTRIBUTE_NODE ";

    case Node.CDATA_SECTION_NODE:

        return "CDATA_SECTION_NODE";

    case Node.COMMENT_NODE:

        return "COMMENT_NODE";

    case Node.DOCUMENT_FRAGMENT_NODE:

        return "DOCUMENT_FRAGMENT_NODE";

    case Node.DOCUMENT_TYPE_NODE:

        return "DOCUMENT_TYPE_NODE";

    case Node.ELEMENT_NODE:

        return "ELEMENT_NODE";

    case Node.ENTITY_NODE:

        return "ENTITY_NODE";

    case Node.ENTITY_REFERENCE_NODE:

        return "ENTITY_REFERENCE_NODE";

    case Node.NOTATION_NODE:

        return "NOTATION_NODE";

    case Node.PROCESSING_INSTRUCTION_NODE:

        return "PROCESSING_INSTRUCTION_NODE";

    case Node.TEXT_NODE:

        return "TEXT_NODE";

    case Node.DOCUMENT_NODE:

        return "DOCUMENT_NODE";

    default:

        return "UN-INDENTIFIED NODE";

    }

}

From source file:DOMDump.java

private static void dumpLoop(Node node, String indent) {
    switch (node.getNodeType()) {
    case Node.CDATA_SECTION_NODE:
        System.out.println(indent + "CDATA_SECTION_NODE");
        break;//from  www .  j  a  va 2s. com
    case Node.COMMENT_NODE:
        System.out.println(indent + "COMMENT_NODE");
        break;
    case Node.DOCUMENT_FRAGMENT_NODE:
        System.out.println(indent + "DOCUMENT_FRAGMENT_NODE");
        break;
    case Node.DOCUMENT_NODE:
        System.out.println(indent + "DOCUMENT_NODE");
        break;
    case Node.DOCUMENT_TYPE_NODE:
        System.out.println(indent + "DOCUMENT_TYPE_NODE");
        break;
    case Node.ELEMENT_NODE:
        System.out.println(indent + "ELEMENT_NODE");
        break;
    case Node.ENTITY_NODE:
        System.out.println(indent + "ENTITY_NODE");
        break;
    case Node.ENTITY_REFERENCE_NODE:
        System.out.println(indent + "ENTITY_REFERENCE_NODE");
        break;
    case Node.NOTATION_NODE:
        System.out.println(indent + "NOTATION_NODE");
        break;
    case Node.PROCESSING_INSTRUCTION_NODE:
        System.out.println(indent + "PROCESSING_INSTRUCTION_NODE");
        break;
    case Node.TEXT_NODE:
        System.out.print(indent + "TEXT_NODE");
        System.out.println(" : " + node.getTextContent());
        break;
    default:
        System.out.println(indent + "Unknown node");
        break;
    }

    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        dumpLoop(list.item(i), indent + "   ");
    }
}

From source file:Main.java

/**
 * Clone given Node into target Document. If targe is null, same Document will be used.
 * If deep is specified, all children below will also be cloned.
 *//*w  ww.jav a  2s . co  m*/
public final static Node cloneNode(Node node, Document target, boolean deep) throws DOMException {
    if ((target == null) || (node.getOwnerDocument() == target)) {
        // same Document
        return node.cloneNode(deep);
    } else {
        //DOM level 2 provides this in Document, so once xalan switches to that,
        //we can take out all the below and just call target.importNode(node, deep);
        //For now, we implement based on the javadocs for importNode
        Node newNode;
        int nodeType = node.getNodeType();

        switch (nodeType) {
        case Node.ATTRIBUTE_NODE:
            newNode = target.createAttribute(node.getNodeName());

            break;

        case Node.DOCUMENT_FRAGMENT_NODE:
            newNode = target.createDocumentFragment();

            break;

        case Node.ELEMENT_NODE:

            Element newElement = target.createElement(node.getNodeName());
            NamedNodeMap nodeAttr = node.getAttributes();

            if (nodeAttr != null) {
                for (int i = 0; i < nodeAttr.getLength(); i++) {
                    Attr attr = (Attr) nodeAttr.item(i);

                    if (attr.getSpecified()) {
                        Attr newAttr = (Attr) cloneNode(attr, target, true);
                        newElement.setAttributeNode(newAttr);
                    }
                }
            }

            newNode = newElement;

            break;

        case Node.ENTITY_REFERENCE_NODE:
            newNode = target.createEntityReference(node.getNodeName());

            break;

        case Node.PROCESSING_INSTRUCTION_NODE:
            newNode = target.createProcessingInstruction(node.getNodeName(), node.getNodeValue());

            break;

        case Node.TEXT_NODE:
            newNode = target.createTextNode(node.getNodeValue());

            break;

        case Node.CDATA_SECTION_NODE:
            newNode = target.createCDATASection(node.getNodeValue());

            break;

        case Node.COMMENT_NODE:
            newNode = target.createComment(node.getNodeValue());

            break;

        case Node.NOTATION_NODE:
        case Node.ENTITY_NODE:
        case Node.DOCUMENT_TYPE_NODE:
        case Node.DOCUMENT_NODE:
        default:
            throw new IllegalArgumentException("Importing of " + node + " not supported yet");
        }

        if (deep) {
            for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
                newNode.appendChild(cloneNode(child, target, true));
            }
        }

        return newNode;
    }
}

From source file:Main.java

/**
 * Clone given Node into target Document. If targe is null, same Document will be used.
 * If deep is specified, all children below will also be cloned.
 *//* w ww.ja  v a  2s . c om*/
public static Node cloneNode(Node node, Document target, boolean deep) throws DOMException {
    if (target == null || node.getOwnerDocument() == target)
        // same Document
        return node.cloneNode(deep);
    else {
        //DOM level 2 provides this in Document, so once xalan switches to that,
        //we can take out all the below and just call target.importNode(node, deep);
        //For now, we implement based on the javadocs for importNode
        Node newNode;
        int nodeType = node.getNodeType();

        switch (nodeType) {
        case Node.ATTRIBUTE_NODE:
            newNode = target.createAttribute(node.getNodeName());

            break;

        case Node.DOCUMENT_FRAGMENT_NODE:
            newNode = target.createDocumentFragment();

            break;

        case Node.ELEMENT_NODE:

            Element newElement = target.createElement(node.getNodeName());
            NamedNodeMap nodeAttr = node.getAttributes();

            if (nodeAttr != null)
                for (int i = 0; i < nodeAttr.getLength(); i++) {
                    Attr attr = (Attr) nodeAttr.item(i);

                    if (attr.getSpecified()) {
                        Attr newAttr = (Attr) cloneNode(attr, target, true);
                        newElement.setAttributeNode(newAttr);
                    }
                }

            newNode = newElement;

            break;

        case Node.ENTITY_REFERENCE_NODE:
            newNode = target.createEntityReference(node.getNodeName());

            break;

        case Node.PROCESSING_INSTRUCTION_NODE:
            newNode = target.createProcessingInstruction(node.getNodeName(), node.getNodeValue());

            break;

        case Node.TEXT_NODE:
            newNode = target.createTextNode(node.getNodeValue());

            break;

        case Node.CDATA_SECTION_NODE:
            newNode = target.createCDATASection(node.getNodeValue());

            break;

        case Node.COMMENT_NODE:
            newNode = target.createComment(node.getNodeValue());

            break;

        case Node.NOTATION_NODE:
        case Node.ENTITY_NODE:
        case Node.DOCUMENT_TYPE_NODE:
        case Node.DOCUMENT_NODE:
        default:
            throw new IllegalArgumentException("Importing of " + node + " not supported yet");
        }

        if (deep)
            for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling())
                newNode.appendChild(cloneNode(child, target, true));

        return newNode;
    }
}

From source file:Main.java

public String getNodeType(Node node) {
    String type;/*ww  w  .  j a  v  a2s  . c  o  m*/

    switch (node.getNodeType()) {
    case Node.ELEMENT_NODE: {
        type = "Element";
        break;
    }
    case Node.ATTRIBUTE_NODE: {
        type = "Attribute";
        break;
    }
    case Node.TEXT_NODE: {
        type = "Text";
        break;
    }
    case Node.CDATA_SECTION_NODE: {
        type = "CData section";
        break;
    }
    case Node.ENTITY_REFERENCE_NODE: {
        type = "Entity reference";
        break;
    }
    case Node.ENTITY_NODE: {
        type = "Entity";
        break;
    }
    case Node.PROCESSING_INSTRUCTION_NODE: {
        type = "Processing instruction";
        break;
    }
    case Node.COMMENT_NODE: {
        type = "Comment";
        break;
    }
    case Node.DOCUMENT_NODE: {
        type = "Document";
        break;
    }
    case Node.DOCUMENT_TYPE_NODE: {
        type = "Document type";
        break;
    }
    case Node.DOCUMENT_FRAGMENT_NODE: {
        type = "Document fragment";
        break;
    }
    case Node.NOTATION_NODE: {
        type = "Notation";
        break;
    }
    default: {
        type = "???";
        break;
    }
    }
    return type;
}