Example usage for org.apache.commons.jxpath JXPathContext getValue

List of usage examples for org.apache.commons.jxpath JXPathContext getValue

Introduction

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

Prototype

public abstract Object getValue(String xpath);

Source Link

Document

Evaluates the xpath and returns the resulting object.

Usage

From source file:org.chiba.xml.xforms.ui.RepeatTest.java

/**
 * Tests for correct prototype handling.
 *
 * @throws Exception if any error occurred during the test.
 *///from   w  w  w.ja  va2s . com
public void testRepeatPrototype() throws Exception {
    Repeat repeat = (Repeat) this.chibaBean.getContainer().lookup("repeat");
    JXPathContext context = JXPathContext.newContext(repeat.getElement());

    /*
    <chiba:data ... >
    <xf:group id="<generated>" appearance="repeated">
        <xf:input id="input" ref="."/>
        <xf:output id="output" ref="."/>
    </xf:group>
    </chiba:data>
    */
    assertEquals(new Double(1d), context.getValue("count(chiba:data/*)"));

    assertEquals("group", context.getValue("local-name(chiba:data/*[1])"));
    assertEquals(NamespaceConstants.XFORMS_NS, context.getValue("namespace-uri(chiba:data/*[1])"));
    assertEquals(Boolean.TRUE, context.getValue("string-length(chiba:data/xf:group/@id) > 0"));
    assertEquals("repeated", context.getValue("chiba:data/xf:group/@appearance"));
    assertEquals(new Double(2d), context.getValue("count(chiba:data/xf:group/*)"));

    assertEquals("input", context.getValue("local-name(chiba:data/xf:group/*[1])"));
    assertEquals(NamespaceConstants.XFORMS_NS, context.getValue("namespace-uri(chiba:data/xf:group/*[1])"));
    assertEquals("input", context.getValue("chiba:data/xf:group/xf:input/@id"));
    assertEquals(".", context.getValue("chiba:data/xf:group/xf:input/@ref"));

    assertEquals("output", context.getValue("local-name(chiba:data/xf:group/*[2])"));
    assertEquals(NamespaceConstants.XFORMS_NS, context.getValue("namespace-uri(chiba:data/xf:group/*[2])"));
    assertEquals("output", context.getValue("chiba:data/xf:group/xf:output/@id"));
    assertEquals(".", context.getValue("chiba:data/xf:group/xf:output/@ref"));
}

From source file:org.chiba.xml.xforms.ui.RepeatTest.java

/**
 * Tests for correct prototype handling.
 *
 * @throws Exception if any error occurred during the test.
 *///from ww w.  j ava2 s.  c o m
public void testRepeatPrototypeAnon() throws Exception {
    Repeat repeat = (Repeat) this.chibaBean.getContainer().lookup("repeat-anon");
    JXPathContext context = JXPathContext.newContext(repeat.getElement());

    /*
    <chiba:data ... >
    <xf:group id="<generated>" appearance="repeated">
        <xf:input id="input" ref="."/>
        <xf:output id="output" ref="."/>
    </xf:group>
    </chiba:data>
    */
    assertEquals(new Double(1d), context.getValue("count(chiba:data/*)"));

    assertEquals("group", context.getValue("local-name(chiba:data/*[1])"));
    assertEquals(NamespaceConstants.XFORMS_NS, context.getValue("namespace-uri(chiba:data/*[1])"));
    assertEquals(Boolean.TRUE, context.getValue("string-length(chiba:data/xf:group/@id) > 0"));
    assertEquals("repeated", context.getValue("chiba:data/xf:group/@appearance"));
    assertEquals(new Double(2d), context.getValue("count(chiba:data/xf:group/*)"));

    assertEquals("input", context.getValue("local-name(chiba:data/xf:group/*[1])"));
    assertEquals(NamespaceConstants.XFORMS_NS, context.getValue("namespace-uri(chiba:data/xf:group/*[1])"));
    assertEquals(Boolean.TRUE, context.getValue("string-length(chiba:data/xf:group/xf:input/@id) > 0"));
    assertEquals(".", context.getValue("chiba:data/xf:group/xf:input/@ref"));

    assertEquals("output", context.getValue("local-name(chiba:data/xf:group/*[2])"));
    assertEquals(NamespaceConstants.XFORMS_NS, context.getValue("namespace-uri(chiba:data/xf:group/*[2])"));
    assertEquals(Boolean.TRUE, context.getValue("string-length(chiba:data/xf:group/xf:output/@id) > 0"));
    assertEquals(".", context.getValue("chiba:data/xf:group/xf:output/@ref"));
}

From source file:org.chiba.xml.xforms.ui.RepeatTest.java

public void testRepeatRefreshing() throws Exception {

    Repeat repeat = (Repeat) this.chibaBean.getContainer().lookup("nested-master-repeat");
    this.chibaBean.updateRepeatIndex("nested-master-repeat", 3);
    assertEquals(3, repeat.getIndex());//from   w ww  .ja v  a  2s.  c  o  m

    this.chibaBean.dispatch("trigger-insert-nested-master", DOMEventNames.ACTIVATE);
    // DOMUtil.prettyPrintDOM(chibaBean.getContainer().getDocument());
    JXPathContext context = JXPathContext.newContext(chibaBean.getContainer().getDocument());
    assertEquals("7",
            context.getValue("//xf:repeat[@id='nested-master-repeat']//xf:repeat//xf:input/chiba:data"));
    assertEquals("8",
            context.getValue("//xf:repeat[@id='nested-master-repeat']//xf:repeat//xf:output/chiba:data"));
    assertEquals(1, repeat.getIndex());

}

From source file:org.chiba.xml.xforms.ui.test.DataElementTest.java

/**
 * Tests initializing the data element.//from  www.j  a v  a2s .c o m
 *
 * @throws Exception if any error occurred during the test.
 */
public void testInit() throws Exception {
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("value", context.getValue("//*[@id='input-existing']/chiba:data"));
    assertEquals("true", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:valid"));
    assertEquals("false", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:readonly"));
    assertEquals("false", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:required"));
    assertEquals("true", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:enabled"));
    assertEquals("xsd:token", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:type"));
    assertEquals("/data[1]/item[1]", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:xpath"));
}

From source file:org.chiba.xml.xforms.ui.test.DataElementTest.java

/**
 * Tests initializing the data element with a missing instance node.
 *
 * @throws Exception if any error occurred during the test.
 *//* w  w  w. j ava2  s .  com*/
public void testInitMissing() throws Exception {
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("", context.getValue("//*[@id='input-missing']/chiba:data"));
    assertEquals("true", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:valid"));
    assertEquals("false", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:readonly"));
    assertEquals("false", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:required"));
    assertEquals("false", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:enabled"));
    assertEquals(Boolean.FALSE, context.getValue("boolean(//*[@id='input-missing']/chiba:data/@chiba:type)"));
    assertEquals(Boolean.FALSE, context.getValue("boolean(//*[@id='input-missing']/chiba:data/@chiba:xpath)"));
}

From source file:org.chiba.xml.xforms.ui.test.DataElementTest.java

/**
 * Tests updating the data element.//w w  w  .j  ava  2  s  .  co m
 *
 * @throws Exception if any error occurred during the test.
 */
public void testUpdate() throws Exception {
    this.chibaBean.updateControlValue("input-existing", "foobar");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("foobar", context.getValue("//*[@id='input-existing']/chiba:data"));
    assertEquals("true", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:valid"));
    assertEquals("false", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:readonly"));
    assertEquals("false", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:required"));
    assertEquals("true", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:enabled"));
    assertEquals("xsd:token", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:type"));
    assertEquals("/data[1]/item[1]", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:xpath"));
}

From source file:org.chiba.xml.xforms.ui.test.DataElementTest.java

/**
 * Tests updating the data element after deleting an existing instance
 * node./*from w  w  w. j  av a  2s  .com*/
 *
 * @throws Exception if any error occurred during the test.
 */
public void testUpdateDeleteExisting() throws Exception {
    this.chibaBean.dispatch("delete-existing", EventFactory.DOM_ACTIVATE);
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("", context.getValue("//*[@id='input-existing']/chiba:data"));
    assertEquals("true", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:valid"));
    assertEquals("false", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:readonly"));
    assertEquals("false", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:required"));
    assertEquals("false", context.getValue("//*[@id='input-existing']/chiba:data/@chiba:enabled"));
    assertEquals(Boolean.FALSE, context.getValue("boolean(//*[@id='input-existing']/chiba:data/@chiba:type)"));
    assertEquals(Boolean.FALSE, context.getValue("boolean(//*[@id='input-existing']/chiba:data/@chiba:xpath)"));
}

From source file:org.chiba.xml.xforms.ui.test.DataElementTest.java

/**
 * Tests updating the data element after inserting a missing instance node.
 *
 * @throws Exception if any error occurred during the test.
 *//* w ww  .  ja va  2 s.c o m*/
public void testUpdateInsertMissing() throws Exception {
    this.chibaBean.dispatch("insert-missing", EventFactory.DOM_ACTIVATE);
    JXPathContext context = this.chibaBean.getContainer().getRootContext();

    assertEquals("value", context.getValue("//*[@id='input-missing']/chiba:data"));
    assertEquals("true", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:valid"));
    assertEquals("false", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:readonly"));
    assertEquals("false", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:required"));
    assertEquals("true", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:enabled"));
    assertEquals("xsd:token", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:type"));
    assertEquals("/data[1]/item[2]", context.getValue("//*[@id='input-missing']/chiba:data/@chiba:xpath"));
}

From source file:org.chiba.xml.xforms.ui.test.ItemsetTest.java

private void assertItem(JXPathContext context, String id, int position, String selected, String label,
        String value) {/*from   w ww.  j a v  a 2 s .c  om*/
    assertEquals(id, Boolean.TRUE,
            context.getValue("boolean(//*[@id='" + id + "']/xf:itemset/xf:item[" + position + "]/@id)"));
    assertEquals(id, selected,
            context.getValue("//*[@id='" + id + "']/xf:itemset/xf:item[" + position + "]/@xf:selected"));
    assertEquals(id, Boolean.TRUE, context
            .getValue("boolean(//*[@id='" + id + "']/xf:itemset/xf:item[" + position + "]/xf:label/@id)"));
    assertEquals(id, label,
            context.getValue("//*[@id='" + id + "']/xf:itemset/xf:item[" + position + "]/xf:label"));
    assertEquals(id, Boolean.TRUE, context
            .getValue("boolean(//*[@id='" + id + "']/xf:itemset/xf:item[" + position + "]/xf:value/@id)"));
    assertEquals(id, value,
            context.getValue("//*[@id='" + id + "']/xf:itemset/xf:item[" + position + "]/xf:value"));
}

From source file:org.chiba.xml.xforms.ui.test.OutputTest.java

/**
 * Tests output with an ui binding./*from  w  w  w .j a  v  a2s  . c  o m*/
 *
 * @throws Exception if any error occurred during the test.
 */
public void testUIBinding() throws Exception {
    Output output = (Output) this.chibaBean.getContainer().lookup("output-1");
    JXPathContext context = this.chibaBean.getContainer().getRootContext();
    assertEquals("1", context.getValue("//xf:output[@id='output-1']/chiba:data"));
    assertEquals("/data[1]/item[1]", context.getValue("//xf:output[@id='output-1']/chiba:data/@chiba:xpath"));
    assertEquals("1", output.getValue());

    Model model = this.chibaBean.getContainer().getModel("model-1");
    model.getDefaultInstance().setNodeValue("/data/item[1]", "3");
    model.refresh();
    assertEquals("3", context.getValue("//xf:output[@id='output-1']/chiba:data"));
    assertEquals("3", output.getValue());
}