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

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

Introduction

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

Prototype

public Object getValue() 

Source Link

Document

By default, returns getNode(), can be overridden to return a "canonical" value, like for instance a DOM element should return its string value.

Usage

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

public Object getValue() {
    if (node instanceof Document) {
        return node;
    }//from  www  .j a  v  a 2 s .  c o  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();
}

From source file:org.onecmdb.core.utils.xpath.generator.XMLContentGenerator.java

private void fillBeanMap(HashMap<String, CiBean> map, CiBean currentBean, NodePointer root, NodePointer p) {
    // Get the attribute NodePointer name.
    NodePointer childToRoot = getChildToRoot(root, p);

    // Not a child of root, don't know what to do..
    if (childToRoot == null) {
        return;// w w w  . ja  v a 2s.c  om
    }

    // add the value.
    Object value = childToRoot.getValue();

    if (value instanceof AttributeValueContext) {
        AttributeValueContext attrValue = (AttributeValueContext) value;
        value = attrValue.getProperty("iValue");
    }

    if (value instanceof InstanceContext) {
        InstanceContext instance = (InstanceContext) value;
        String alias = instance.getProperty("alias").toString();
        CiBean instanceBean = map.get(alias);
        if (instanceBean == null) {
            instanceBean = new CiBean();
            instanceBean.setDerivedFrom(instance.getProperty("derivedFrom").toString());
            instanceBean.setAlias(alias);
            instanceBean.setDisplayName(instance.getNewProperty("displayName").toString());
            instanceBean.setTemplate(false);

            instancesBeans.add(instanceBean);
        }

        String attAlias = childToRoot.getName().toString();
        if (!isInternalState(attAlias)) {
            ValueBean vBean = new ValueBean();
            vBean.setAlias(attAlias);
            vBean.setValue(instanceBean.getAlias());
            vBean.setComplexValue(true);

            currentBean.addAttributeValue(vBean);
            map.put(alias, instanceBean);
        }

        fillBeanMap(map, instanceBean, childToRoot, p);

    } else {
        String attAlias = childToRoot.getName().toString();
        if (!isInternalState(attAlias)) {
            ValueBean vBean = new ValueBean();
            vBean.setAlias(attAlias);
            if (value != null) {
                vBean.setValue(value.toString());
            }
            currentBean.addAttributeValue(vBean);
        }
    }

}

From source file:org.onecmdb.core.utils.xpath.generator.XMLContentGenerator.java

private StringBuffer generateXMLTagForAttribute(PrintWriter text, NodePointer root, NodePointer p) {
    // Get the attribute NodePointer name.
    NodePointer childToRoot = getChildToRoot(root, p);

    StringBuffer sb = new StringBuffer();

    // Not a child of root, don't know what to do..
    if (childToRoot == null) {
        return (sb);
    }/*from   w w w  .  ja  v  a2 s  .c  o m*/

    // start tag for attribute name
    sb.append("<" + childToRoot.getName() + ">\n");

    // add the value.
    Object value = childToRoot.getValue();
    if (value instanceof InstanceContext) {

    } else {
        sb.append("\t" + value.toString() + "\n");
    }

    // End tag for attribute name
    sb.append("</" + childToRoot.getName() + ">\n");

    return (sb);
}