Example usage for org.apache.commons.jxpath Pointer getNode

List of usage examples for org.apache.commons.jxpath Pointer getNode

Introduction

In this page you can find the example usage for org.apache.commons.jxpath Pointer getNode.

Prototype

Object getNode();

Source Link

Document

Returns the raw value of the object, property or collection element this pointer represents.

Usage

From source file:org.chiba.xml.xforms.Container.java

/**
 * removes an EventListener//from w  w w .j  a v  a  2  s .  co m
 *
 * @param targetId      the event target
 * @param eventType     the type of Event
 * @param eventListener the listener
 * @param useCapture    true, if capture should be used for this Event
 * @throws XFormsException if eventtarget cannot be found
 */
public void removeEventListener(String targetId, String eventType, EventListener eventListener,
        boolean useCapture) throws XFormsException {
    if (this.rootContext != null) {
        Pointer pointer = this.rootContext.getPointer("//*[@id='" + targetId + "']");

        if (pointer != null) {
            EventTarget eventTarget = (EventTarget) pointer.getNode();
            eventTarget.removeEventListener(eventType, eventListener, useCapture);

            return;
        }
    }

    throw new XFormsException("event target '" + targetId + "' not found");
}

From source file:org.chiba.xml.xforms.Container.java

/**
 * dispatches an DOM Event/*from ww  w . j  a v a 2  s .  c  o m*/
 *
 * @param targetId  the target Node for this Event
 * @param eventType the type of Event
 * @param info      an additional info object
 * @return true, if Event was cancelled by an Listener
 * @throws XFormsException if target Node cannot be found
 */
public boolean dispatch(String targetId, String eventType, Object info) throws XFormsException {
    if (this.rootContext != null) {
        Pointer pointer = this.rootContext.getPointer("//*[@id='" + targetId + "']");

        if (pointer != null) {
            EventTarget eventTarget = (EventTarget) pointer.getNode();

            return dispatch(eventTarget, eventType, info);
        }
    }

    throw new XFormsException("event target '" + targetId + "' not found");
}

From source file:org.chiba.xml.xforms.core.Instance.java

/**
 * this method lets you access the state of individual instance data nodes.
 * each node has an associated ModelItem object which holds the current
 * status of readonly, required, validity, relevant. it also annotates the
 * DOM node with type information.//  w w w .j a va 2 s.  c  o m
 * <p/>
 * When an ModelItem does not exist already it will be created and attached
 * as useroject to its corresponding node in the instancedata.
 *
 * @param locationPath - an absolute location path pointing to some node in
 * this instance
 * @return the ModelItem for the specified node
 */
public ModelItem getModelItem(String locationPath) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(this + " get model item for locationPath '" + locationPath + "'");
    }

    // ensure that node exists since getPointer is buggy
    if (!existsNode(locationPath)) {
        return null;
    }

    // lookup pointer, node, item
    this.instanceContext.getVariables().declareVariable("contextmodel", this.model.getId());
    Pointer pointer = this.instanceContext.getPointer(locationPath);
    this.instanceContext.getVariables().undeclareVariable("contextmodel");

    NodeImpl node = (NodeImpl) pointer.getNode();
    ModelItem item = (ModelItem) node.getUserData();

    if (item == null) {
        // create item
        item = createModelItem(node);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(this + " get model item: created item for path '" + pointer + "'");
        }
    }

    return item;
}

From source file:org.chiba.xml.xforms.core.Instance.java

/**
 * Returns an iterator over the specified model items.
 *
 * @param path the path selecting a set of model items.
 * @param deep include attributes and children or not.
 * @return an iterator over the specified model items.
 *//* w ww .  ja  v  a 2  s  .  c  o m*/
public Iterator iterateModelItems(String path, boolean deep) {
    // hack 1: ensure that node exists since JXPath's getPointer() is buggy
    if (!existsNode(path)) {
        return null;
    }

    // create list, fill and iterate it
    // todo: optimize with live iterator
    List list = new ArrayList();
    Pointer pointer;
    Object nested;
    NodeImpl node;
    Iterator iterator = this.instanceContext.iteratePointers(path);
    while (iterator.hasNext()) {
        pointer = (Pointer) iterator.next();

        // hack 2: when path is a plain 'instance(...)' function call without
        // any following path step, JXPath wraps the actual node pointer
        // with a fairly useless bean pointer
        if (pointer instanceof org.apache.commons.jxpath.ri.model.beans.BeanPointer) {
            nested = pointer.getNode();
            if (nested instanceof org.apache.commons.jxpath.ri.model.dom.DOMNodePointer) {
                pointer = (Pointer) nested;
            }
        }

        node = (NodeImpl) pointer.getNode();
        listModelItems(list, node, deep);
    }

    return list.iterator();
}

From source file:org.chiba.xml.xforms.core.Model.java

private void loadLinkedSchemas(List list) throws XFormsException {
    String schemaURI = null;/*w  w  w. ja  v a2s.c  o m*/
    try {
        String schemaAttribute = getXFormsAttribute("schema");
        if (schemaAttribute != null) {
            StringTokenizer tokenizer = new StringTokenizer(schemaAttribute, " ");
            XSModel schema = null;

            while (tokenizer.hasMoreTokens()) {
                schemaURI = tokenizer.nextToken();

                if (schemaURI.startsWith("#")) {
                    // lookup fragment
                    String id = schemaURI.substring(1);
                    Pointer pointer = this.container.getRootContext().getPointer("//*[@id='" + id + "']");
                    Element element = (Element) pointer.getNode();
                    schema = loadSchema(element);
                } else {
                    // resolve URI
                    schema = loadSchema(schemaURI);
                }

                if (schema == null) {
                    throw new NullPointerException("resource not found");
                }
                list.add(schema);
            }
        }
    } catch (Exception e) {
        Map props = new HashMap(1);
        props.put(XFormsEventNames.RESOURCE_URI_PROPERTY, schemaURI);
        throw new XFormsLinkException("could not load linked schema", this.target, props);
    }
}

From source file:org.chiba.xml.xforms.Instance.java

private Node getFinalCollectionMember(String path) {
    // instantiate cache lazily
    if (this.finalMembers == null) {
        this.finalMembers = new HashMap();
    }//from  ww  w. ja v  a  2s  .co  m

    // lookup final collection member
    Node finalMember = (Node) this.finalMembers.get(path);
    if (finalMember != null) {
        // cache hit
        return finalMember;
    }

    // search final collection member
    Pointer finalPointer = getLastPointer(getOriginalContext(), path);

    if (finalPointer == null) {
        String genericPath = PathUtil.removePredicates(path);
        finalPointer = getLastPointer(getOriginalContext(), genericPath);

        // todo: if finalPointer == null throw exception
    }

    // obtain and cache final collection member
    finalMember = (Node) finalPointer.getNode();
    this.finalMembers.put(path, finalMember);

    return finalMember;
}

From source file:org.chiba.xml.xforms.Model.java

private void loadLinkedSchemas(List list) throws XFormsException {
    String schemaURI = null;// w  ww.  j av a 2  s  .c  om
    try {
        String schemaLocations = this.element.getAttributeNS(NamespaceCtx.XFORMS_NS, "schema");
        StringTokenizer tokenizer = new StringTokenizer(schemaLocations, " ");
        XSModel schema = null;

        while (tokenizer.hasMoreTokens()) {
            schemaURI = tokenizer.nextToken();

            if (schemaURI.startsWith("#")) {
                // lookup fragment
                String id = schemaURI.substring(1);
                Pointer pointer = this.container.getRootContext().getPointer("//*[@id='" + id + "']");
                Element element = (Element) pointer.getNode();
                schema = loadSchema(element);
            } else {
                // resolve URI
                schema = loadSchema(schemaURI);
            }

            if (schema == null) {
                throw new NullPointerException("resource not found");
            }
            list.add(schema);
        }
    } catch (Exception e) {
        throw new XFormsLinkException("could not load linked schema", this.target, schemaURI);
    }
}

From source file:org.chiba.xml.xforms.xpath.test.JXPathTest.java

/**
 * Tests element node access.//from   ww w  .j a  v  a2 s . c om
 *
 * @throws Exception if any error occurred during the test.
 */
public void testGetElementNode() throws Exception {
    Pointer pointer = this.context.getPointer("//my:order/my:item");
    assertTrue(org.w3c.dom.Element.class.isAssignableFrom(pointer.getNode().getClass()));
}

From source file:org.chiba.xml.xforms.xpath.test.JXPathTest.java

/**
 * Tests attribute node access./* ww  w . jav a  2s.  c o  m*/
 *
 * @throws Exception if any error occurred during the test.
 */
public void testGetAttrNode() throws Exception {
    Pointer pointer = this.context.getPointer("//my:order/@my:money");
    assertTrue(org.w3c.dom.Attr.class.isAssignableFrom(pointer.getNode().getClass()));
}

From source file:org.firesoa.common.jxpath.JXPathTestCase.java

protected void assertXPathNodeType(JXPathContext ctx, String xpath, Class clazz) {
    ctx.setLenient(false);//from www  . j  a  va  2s . co m
    Pointer actual = ctx.getPointer(xpath);
    assertTrue("Evaluating <" + xpath + "> = " + actual.getNode().getClass(),
            clazz.isAssignableFrom(actual.getNode().getClass()));
}