Example usage for org.w3c.dom Element getUserData

List of usage examples for org.w3c.dom Element getUserData

Introduction

In this page you can find the example usage for org.w3c.dom Element getUserData.

Prototype

public Object getUserData(String key);

Source Link

Document

Retrieves the object associated to a key on a this node.

Usage

From source file:de.betterform.xml.xforms.xpath.saxon.function.XFormsFunction.java

protected Container getContainer(XPathContext xpathContext) {
    Item item = xpathContext.getContextItem();
    Node n = (Node) ((NodeWrapper) item).getUnderlyingNode();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("context node: " + n.getNodeName());
    }/*from  w  w w .  ja va 2s  .  com*/

    Element root = n.getOwnerDocument().getDocumentElement();
    Object container = root.getUserData("container");
    if (container instanceof Container) {
        return (Container) container;
    } else {
        return null;
    }
}

From source file:de.betterform.xml.xforms.action.MessageAction.java

private String evaluateMessageContent() throws XFormsException {
    String message = "";
    if (this.element.hasChildNodes()) {
        NodeList childNodes = this.element.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node node = childNodes.item(i);
            switch (node.getNodeType()) {
            case Node.TEXT_NODE:
                message += node.getTextContent();
                break;
            case Node.ELEMENT_NODE:
                Element element = (Element) node;
                Object userData = element.getUserData("");
                if ((userData != null) && userData instanceof Output) {
                    Output output = (Output) userData;
                    message += (String) output.computeValueAttribute();
                }//from  w  ww . j av a2  s  .  c  o m
                break;
            }
        }
    }
    return message;

}

From source file:org.solmix.runtime.support.spring.ContainerDefinitionParser.java

@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext ctx) {
    String container = null;//  www. j  av a  2 s. com
    try {
        container = (String) element.getUserData("ID");
    } catch (Throwable t) {
        // ignore
    }
    if (container == null) {
        container = element.getAttribute("name");

        if (StringUtils.isEmpty(container)) {
            container = Container.DEFAULT_CONTAINER_ID + ".config" + counter.getAndIncrement();
        } else {
            container = container + ".config";
        }
        try {
            element.setUserData("ID", container, null);
        } catch (Throwable t) {
            // maybe no DOM level 3, ignore, but, may have issues with the
            // counter
        }
    }
    return container;
}

From source file:de.betterform.connector.ConnectorFactory.java

private String evalXPath(Element element, String valueTemplate) throws XFormsException {
    XFormsElement xElement = (XFormsElement) element.getUserData("");
    String xpath;/*from ww w.j a  va 2 s .  c o m*/

    if (XPathUtil.hasInstanceFunction(valueTemplate)) {
        xpath = valueTemplate;
    } else {
        String path;
        if (xElement instanceof AbstractBoundAction) {
            path = ((AbstractBoundAction) xElement).getLocationPath();
        } else if (xElement instanceof Submission) {
            path = ((Submission) xElement).getLocationPath();
        } else {
            LOGGER.warn(
                    "no AVT processing for this element implemented - returning default instance root as context path");
            path = "instance('default')";
        }
        xpath = evalJoinedXPath(path, valueTemplate);
    }
    return XPathCache.getInstance().evaluateAsString(xElement.getModel().getDefaultInstance().getRootContext(),
            xpath);
}

From source file:de.betterform.xml.xforms.action.UnloadAction.java

private void destroyembeddedModels(Element targetElem) throws XFormsException {
    NodeList childNodes = targetElem.getChildNodes();

    for (int index = 0; index < childNodes.getLength(); index++) {
        Node node = childNodes.item(index);

        if (node.getNodeType() == Node.ELEMENT_NODE) {
            Element elementImpl = (Element) node;

            String name = elementImpl.getLocalName();
            String uri = elementImpl.getNamespaceURI();

            if (NamespaceConstants.XFORMS_NS.equals(uri) && name.equals(XFormsConstants.MODEL)) {
                Model model = (Model) elementImpl.getUserData("");
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("dispatch 'model-destruct' event to embedded model: " + model.getId());
                    ;// ww  w .jav a  2 s .  com
                }

                // do not dispatch model-destruct to avoid problems in lifecycle
                // TODO: review: this.container.dispatch(model.getTarget(), XFormsEventNames.MODEL_DESTRUCT, null);
                model.dispose();
                this.container.removeModel(model);
                model = null;
            } else {
                destroyembeddedModels(elementImpl);
            }
        }
    }
}

From source file:de.betterform.xml.xforms.action.AbstractAction.java

/**
 * checks @while and/or @if Attributes before actually executing the Action.
 * @param actionEl the Action Element to trigger
 * @throws XFormsException//from   w w w  .  ja  v  a  2s .co  m
 */
protected void performConditional(Element actionEl) throws XFormsException {
    final XFormsAction action = (XFormsAction) actionEl.getUserData("");
    final String whileCondition = XFormsElement.getXFormsAttribute(actionEl, XFormsConstants.WHILE_ATTRIBUTE);

    if (whileCondition == null) {
        if (execute((AbstractAction) action)) {
            action.perform();
        }
    } else {
        while (evalCondition(whileCondition)) {
            if (execute((AbstractAction) action)) {
                action.perform();
            } else {
                break;
            }
        }
    }
}

From source file:de.betterform.xml.xforms.XFormsElement.java

public XFormsElement getEnclosingXFormsContainer() {
    Node currentNode = this.getElement();
    XFormsElement enclosingContainer = null;
    while (true) {
        Node parentNode = currentNode.getParentNode();

        if (parentNode == null) {
            break;
        }/* w  w  w.  j a v a  2 s.  c om*/

        if (!(parentNode instanceof Element)) {
            break;
        }

        Element elementImpl = (Element) parentNode;
        Object containerObject = elementImpl.getUserData("");
        if (containerObject instanceof Group || containerObject instanceof Switch
                || containerObject instanceof Repeat) {
            enclosingContainer = (XFormsElement) containerObject;
            break;
        }
        currentNode = parentNode;
    }
    return enclosingContainer;

}

From source file:de.betterform.xml.xforms.XFormsElement.java

/**
 * Returns the enclosing binding element of the specified xforms element.
 *
 * @param xFormsElement the xforms element.
 * @param returnBind if true returns the bind that corresponds to the UI control instead of the UI control itself
 * @return the enclosing binding element of the specified xforms element or
 * <code>null</code> if there is no enclosing binding element.
 *///from  w  w  w . j a  v a2  s .com

public Binding getEnclosingBinding(XFormsElement xFormsElement, boolean returnBind) {
    Binding enclosingBinding = null;
    Container container = xFormsElement.getContainerObject();
    Node currentNode = xFormsElement.getElement();
    String modelId = xFormsElement.getModel().getId();

    while (true) {
        Node parentNode = currentNode.getParentNode();

        if (parentNode == null) {
            break;
        }

        if (!(parentNode instanceof Element)) {
            break;
        }

        Element elementImpl = (Element) parentNode;
        Object o = elementImpl.getUserData("");

        if (BindingResolver.hasModelBinding(elementImpl)) {
            Binding binding = (Binding) o;

            if (binding.getModelId().equals(modelId)) {
                String bindId = binding.getBindingId();
                if (returnBind) {
                    enclosingBinding = (Binding) container.lookup(bindId);
                } else {
                    enclosingBinding = binding;
                }
                break;
            }
        }

        Binding enclosingUIBinding = getEnclosingUIBinding(elementImpl, o, modelId);
        if (enclosingUIBinding != null) {
            enclosingBinding = enclosingUIBinding;
            break;
        }
        currentNode = parentNode;
    }

    return enclosingBinding;
}

From source file:de.betterform.xml.xforms.ui.Repeat.java

private void registerChildren(Node parent) {
    NodeList childNodes = parent.getChildNodes();

    for (int index = 0; index < childNodes.getLength(); index++) {
        Node node = childNodes.item(index);

        if (node instanceof Element) {
            Element elementImpl = (Element) node;
            XFormsElement xFormsElement = (XFormsElement) elementImpl.getUserData("");

            if (xFormsElement != null) {
                // register current (action or ui) element
                xFormsElement.registerId();

                if (xFormsElement instanceof Repeat) {
                    // register *selected* repeat item only, if any
                    Repeat repeat = (Repeat) xFormsElement;
                    RepeatItem repeatItem = repeat.getRepeatItem(repeat.getIndex());

                    if (repeatItem != null) {
                        repeatItem.registerId();
                        registerChildren(repeatItem.getElement());
                    }//from   ww  w.ja  va2s  .c  om
                } else {
                    // register *all* children
                    registerChildren(xFormsElement.getElement());
                }
            } else {
                registerChildren(node);
            }
        }
    }
}

From source file:de.betterform.xml.xforms.model.bind.Bind.java

/**
 * Returns the enclosing element./*from   w w  w  .jav a  2 s.c  om*/
 *
 * @return the enclosing element.
 */
public Binding getEnclosingBinding() {
    Element parentElement = (Element) this.element.getParentNode();

    if (parentElement.getLocalName().equals(XFormsConstants.MODEL)) {
        return null;
    }

    return (Binding) parentElement.getUserData("");
}