Example usage for org.w3c.dom Node ENTITY_NODE

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

Introduction

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

Prototype

short ENTITY_NODE

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

Click Source Link

Document

The node is an Entity.

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://from  ww  w .  j a va 2 s  .  c  o m
        return null;
    }
}

From source file:Main.java

/**
 * based on public Java5 javadoc of org.w3c.dom.Node.getTextContent method
 *///from   w w w.  j ava2 s .c  o m
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

/**
 * Convert a node type to a string. For debug purpose only.
 * //from  w ww  .  ja va2  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://from  w  w w  . j  a v a2  s. c  om
        return null;
    }
}

From source file:Main.java

/**
 * returns the Node Type As String/*from   w  w w .  j  ava 2  s. com*/
 * @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

/**
 * Gets Node type String for a given node type constant
 *//*from   w  w  w . java 2s . com*/

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:Main.java

public String getNodeType(Node node) {
    String type;//from  w  w  w  .j av a2  s .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;
}

From source file:Main.java

/**
 * Searches the node for content of type Long. If non-long content is found,
 * it logs a warning and returns null.//from  w  ww. j  a v a 2s.c o  m
 */
public static String extractStringFromElement(Node element) {
    if (element == null) {
        return null;
    } else if (element.getFirstChild() == null) {
        return null;
    } else if (element.getFirstChild().getNodeValue() == null) {
        return null;
    } else {
        // Get all the children
        NodeList children = element.getChildNodes();
        StringBuffer output = new StringBuffer();
        for (int n = 0; n < children.getLength(); n++) {
            Node child = children.item(n);
            if (child.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
                output.append(child.getFirstChild().getNodeValue());
            } else if (child.getNodeType() == Node.CDATA_SECTION_NODE) {
                output.append(child.getFirstChild().getNodeValue());
            } else if (child.getNodeType() == Node.ENTITY_NODE) {
                output.append(child.getFirstChild().getNodeValue());
            } else if (child.getNodeType() == Node.TEXT_NODE) {
                output.append(child.getNodeValue());
            }
        }
        return output.toString().trim();
    }
}

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 w  w  w.j a  v a  2s . c o m*/
    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:MainClass.java

public void processNode(Node node, String spacer) throws IOException {
    if (node == null)
        return;//from   ww  w .j ava 2s.  c  o  m
    switch (node.getNodeType()) {
    case Node.ELEMENT_NODE:
        String name = node.getNodeName();
        System.out.print(spacer + "<" + name);
        NamedNodeMap nnm = node.getAttributes();
        for (int i = 0; i < nnm.getLength(); i++) {
            Node current = nnm.item(i);
            System.out.print(" " + current.getNodeName() + "= " + current.getNodeValue());
        }
        System.out.print(">");
        NodeList nl = node.getChildNodes();
        if (nl != null) {
            for (int i = 0; i < nl.getLength(); i++) {
                processNode(nl.item(i), "");
            }
        }
        System.out.println(spacer + "</" + name + ">");
        break;
    case Node.TEXT_NODE:
        System.out.print(node.getNodeValue());
        break;
    case Node.CDATA_SECTION_NODE:
        System.out.print("" + node.getNodeValue() + "");
        break;
    case Node.ENTITY_REFERENCE_NODE:
        System.out.print("&" + node.getNodeName() + ";");
        break;
    case Node.ENTITY_NODE:
        System.out.print("<ENTITY: " + node.getNodeName() + "> </" + node.getNodeName() + "/>");
        break;
    case Node.DOCUMENT_NODE:
        NodeList nodes = node.getChildNodes();
        if (nodes != null) {
            for (int i = 0; i < nodes.getLength(); i++) {
                processNode(nodes.item(i), "");
            }
        }
        break;
    case Node.DOCUMENT_TYPE_NODE:
        DocumentType docType = (DocumentType) node;
        System.out.print("<!DOCTYPE " + docType.getName());
        if (docType.getPublicId() != null) {
            System.out.print(" PUBLIC " + docType.getPublicId() + " ");
        } else {
            System.out.print(" SYSTEM ");
        }
        System.out.println(" " + docType.getSystemId() + ">");
        break;
    default:
        break;
    }
}