Example usage for org.apache.commons.jxpath.ri.model NodePointer getImmediateNode

List of usage examples for org.apache.commons.jxpath.ri.model NodePointer getImmediateNode

Introduction

In this page you can find the example usage for org.apache.commons.jxpath.ri.model NodePointer getImmediateNode.

Prototype

public abstract Object getImmediateNode();

Source Link

Document

Returns the object the pointer points to; does not convert it to a "canonical" type.

Usage

From source file:org.firesoa.common.jxpath.model.dom4j.Dom4JNodePointer.java

public Object getValue() {
    if (node instanceof Document) {
        return node;
    }/*  w  ww .  j  a  v  a2 s. co m*/
    if (node instanceof Element) {
        StringBuffer buf = new StringBuffer();
        for (NodeIterator children = childIterator(null, false, null); children
                .setPosition(children.getPosition() + 1);) {
            NodePointer ptr = children.getNodePointer();
            if (ptr.getImmediateNode() instanceof Element || ptr.getImmediateNode() instanceof Text) {
                buf.append(ptr.getValue());
            }
        }
        return buf.toString();
    }
    if (node instanceof Comment) {
        String text = ((Comment) node).getText();
        if (text != null) {
            text = text.trim();
        }
        return text;
    }
    String result = null;
    if (node instanceof Text) {
        result = ((Text) node).getText();
    }
    if (node instanceof ProcessingInstruction) {
        result = ((ProcessingInstruction) node).getStringValue();//TODO ?
    }
    boolean trim = !"preserve".equals(findEnclosingAttribute(node, "space", Namespace.XML_NAMESPACE));
    return result != null && trim ? result.trim() : result;

    //      if ((node instanceof org.dom4j.CharacterData
    //            || node instanceof Attribute || node instanceof DocumentType
    //            || node instanceof Entity || node instanceof ProcessingInstruction)) {
    //         return ((Node)node).getText();
    //      }else{
    //         if (node instanceof Document){
    //            ((Document)node).getText();
    //         }else if (node instanceof Element){
    //            Element elm = (Element)node;
    //            return elm.getText();
    //         }
    //      }
    //        return node.toString();
}