Example usage for org.dom4j Element setData

List of usage examples for org.dom4j Element setData

Introduction

In this page you can find the example usage for org.dom4j Element setData.

Prototype

void setData(Object data);

Source Link

Document

Sets the data value of this element if this element supports data binding or calls #setText if it doesn't

Usage

From source file:com.arc.xml.AbstractBuilder.java

License:Open Source License

/**
 * Process an element.//from  www  .  j a  v  a  2  s .  c  om
 * @param e the element
 * @param binding the binding definition for the element's parent.
 * @return the constructed object, which is also the value of the data property of the element.
 */
@Override
public Object build(Element e, IBinding binding, IBuilder parentBuilder) throws SAXException {
    startNewInstance(e);
    doAttributes(e, binding);
    try {
        beginChildren(e);
        List<Element> kids = Cast.toType(e.elements());
        for (Element kid : kids) {
            doChild(kid, binding);
        }
        // Here we decorate the element with the constructed object.
        Object data = null;
        try {
            data = returnObject();
            e.setData(data);
        } catch (SAXParseException x) {
            throw x;
        } catch (SAXException x) {
            Exception ex = x;
            if (x.getException() != null)
                ex = x.getException();
            error(e, ex.getMessage(), ex);
        }
        return data;
    } finally {
        cleanup(); // if any cleanup to do.
    }
}

From source file:org.orbeon.oxf.xforms.InstanceData.java

License:Open Source License

public static <A extends Node> A remove(A node) {

    // We can't store data on the Document object. Use root element instead.
    Node adjustedNode = node;/*from  w w w.  j a v a 2 s.  c  om*/
    if (node instanceof Document)
        adjustedNode = ((Document) node).getRootElement();

    if (adjustedNode instanceof Element) {
        final Element element = (Element) adjustedNode;

        // Handle current element
        element.setData(null);

        // Handle attributes
        for (Object o : element.attributes()) {
            final Attribute attribute = (Attribute) o;
            remove(attribute);
        }
        // Handle children elements
        for (Object o : element.elements()) {
            final Element childElement = (Element) o;
            remove(childElement);
        }

    } else if (adjustedNode instanceof Attribute) {
        ((Attribute) adjustedNode).setData(null);
    } else {
        // TODO: other node types once we update to handling text nodes correctly. But it looks like Text does not support data.
    }

    return node;
}

From source file:org.orbeon.oxf.xforms.InstanceData.java

License:Open Source License

private static InstanceData createNewInstanceData(Node node) {
    final InstanceData instanceData;
    if (node instanceof Element) {
        final Element element = (Element) node;
        instanceData = InstanceData.createNewInstanceData(element.getData());
        element.setData(instanceData);
    } else if (node instanceof Attribute) {
        final Attribute attribute = (Attribute) node;
        instanceData = InstanceData.createNewInstanceData(attribute.getData());
        attribute.setData(instanceData);
    } else if (node instanceof Document) {
        // We can't store data on the Document object. Use root element instead.
        final Element element = ((Document) node).getRootElement();
        instanceData = InstanceData.createNewInstanceData(element.getData());
        element.setData(instanceData);//from  w  ww.j av  a 2  s  . c  o m
    } else {
        // No other node type is supported
        throw new OXFException("Cannot create InstanceData on node type: " + node.getNodeTypeName());
    }
    return instanceData;
}

From source file:org.orbeon.oxf.xml.dom4j.NonLazyUserDataElement.java

License:Open Source License

protected org.dom4j.Element createElement(final org.dom4j.QName qName) {
    final DocumentFactory factory = NonLazyUserDataDocumentFactory.getInstance();
    final org.dom4j.Element ret = factory.createElement(qName);
    final Object dta = getCopyOfUserData();
    ret.setData(dta);
    return ret;/*w ww.ja  v a2  s  .  c  o m*/
}