List of usage examples for org.apache.commons.jxpath JXPathContext newContext
public static JXPathContext newContext(Object contextBean)
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());/*www .j av a2 s. c om*/ 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.Selector.java
private void setSelection(boolean force, boolean dispatch) throws XFormsException { if (this.context == null) { this.context = JXPathContext.newContext(this.element); }/*from ww w . j av a 2s .co m*/ Item item; String itemId; String value = getValue(); boolean selectable = true; Iterator iterator = this.context.iterate("//" + this.xformsPrefix + ":" + XFormsConstants.ITEM + "[not(ancestor::" + NamespaceCtx.CHIBA_PREFIX + ":data)]/@id"); while (iterator.hasNext()) { itemId = iterator.next().toString(); item = (Item) this.container.lookup(itemId); if (selectable && isInRange(value, item.getValue())) { if (force || !item.isSelected()) { if (getLogger().isDebugEnabled()) { getLogger().debug(this + " selecting item " + itemId); } item.select(); if (dispatch) { this.container.dispatch(item.getTarget(), EventFactory.SELECT, null); } } // allow only one first selection for non-multiple selectors selectable = isMultiple(); } else { if (force || item.isSelected()) { if (getLogger().isDebugEnabled()) { getLogger().debug(this + " deselecting item " + itemId); } item.deselect(); if (dispatch) { this.container.dispatch(item.getTarget(), EventFactory.DESELECT, null); } } } } }
From source file:org.chiba.xml.xforms.ui.SelectorTest.java
/** * Tests Select1 with dynamic Itemset.//from w w w .j a v a 2 s . c o m * * @throws Exception if any error occurred during the test. */ public void testSelect1Dynamic() throws Exception { Selector selector = (Selector) this.chibaBean.getContainer().lookup("select-3"); assertEquals("123", selector.getValue()); JXPathContext context = JXPathContext.newContext(selector.getElement()); context.registerNamespace("xforms", NamespaceConstants.XFORMS_NS); Iterator iterator = context.iterate("//xforms:item/@id"); String item1 = iterator.next().toString(); String item2 = iterator.next().toString(); String item3 = iterator.next().toString(); register(item1, item2, item3); selector.setValue("124"); deregister(item1, item2, item3); assertEquals("124", selector.getValue()); assertEquals(null, this.selectListener1.getId()); assertEquals(item2, this.selectListener2.getId()); assertEquals(null, this.selectListener3.getId()); assertEquals(item1, this.deselectListener1.getId()); assertEquals(null, this.deselectListener2.getId()); assertEquals(null, this.deselectListener3.getId()); }
From source file:org.chiba.xml.xforms.ui.SelectorTest.java
/** * Tests Select1 with dynamic Itemset.//from w w w .j ava 2 s .c o m * * @throws Exception if any error occurred during the test. */ public void testSelect1DynamicTriggered() throws Exception { Selector selector = (Selector) this.chibaBean.getContainer().lookup("select-3"); assertEquals("123", selector.getValue()); JXPathContext context = JXPathContext.newContext(selector.getElement()); Iterator iterator = context.iterate("//xf:item/@id"); String item1 = iterator.next().toString(); String item2 = iterator.next().toString(); String item3 = iterator.next().toString(); register(item1, item2, item3); this.chibaBean.dispatch("trigger-3", DOMEventNames.ACTIVATE); deregister(item1, item2, item3); assertEquals("125", selector.getValue()); assertEquals(null, this.selectListener1.getId()); assertEquals(null, this.selectListener2.getId()); assertEquals(null, this.selectListener3.getId()); assertEquals(null, this.deselectListener1.getId()); assertEquals(null, this.deselectListener2.getId()); assertEquals(null, this.deselectListener3.getId()); }
From source file:org.chiba.xml.xforms.ui.SelectorTest.java
/** * Tests Select with dynamic Itemset.//from w ww.j av a 2 s . co m * * @throws Exception if any error occurred during the test. */ public void testSelectDynamic() throws Exception { Selector selector = (Selector) this.chibaBean.getContainer().lookup("select-4"); assertEquals("123", selector.getValue()); JXPathContext context = JXPathContext.newContext(selector.getElement()); Iterator iterator = context.iterate("//xf:item/@id"); String item1 = iterator.next().toString(); String item2 = iterator.next().toString(); String item3 = iterator.next().toString(); register(item1, item2, item3); selector.setValue("124 125"); deregister(item1, item2, item3); assertEquals("124 125", selector.getValue()); assertEquals(null, this.selectListener1.getId()); assertEquals(item2, this.selectListener2.getId()); assertEquals(item3, this.selectListener3.getId()); assertEquals(item1, this.deselectListener1.getId()); assertEquals(null, this.deselectListener2.getId()); assertEquals(null, this.deselectListener3.getId()); }
From source file:org.chiba.xml.xforms.ui.SelectorTest.java
/** * Tests Select1 with dynamic Itemset.//from w w w . j a v a 2s . co m * * @throws Exception if any error occurred during the test. */ public void testSelectDynamicTriggered() throws Exception { Selector selector = (Selector) this.chibaBean.getContainer().lookup("select-4"); assertEquals("123", selector.getValue()); JXPathContext context = JXPathContext.newContext(selector.getElement()); Iterator iterator = context.iterate("//xf:item/@id"); String item1 = iterator.next().toString(); String item2 = iterator.next().toString(); String item3 = iterator.next().toString(); register(item1, item2, item3); this.chibaBean.dispatch("trigger-4", DOMEventNames.ACTIVATE); deregister(item1, item2, item3); assertEquals("125", selector.getValue()); assertEquals(null, this.selectListener1.getId()); assertEquals(null, this.selectListener2.getId()); assertEquals(null, this.selectListener3.getId()); assertEquals(null, this.deselectListener1.getId()); assertEquals(null, this.deselectListener2.getId()); assertEquals(null, this.deselectListener3.getId()); }
From source file:org.chiba.xml.xforms.ui.test.RepeatIndexTest.java
/** * Sets up the test.// www . ja v a 2 s. com * * @throws Exception in any error occurred during setup. */ protected void setUp() throws Exception { this.chibaBean = new ChibaBean(); this.chibaBean.setXMLContainer(getClass().getResourceAsStream("RepeatIndexTest.xhtml")); this.chibaBean.init(); JXPathContext context = JXPathContext.newContext(this.chibaBean.getXMLContainer()); // iterate unrolled repeats Iterator repeatIterator = context.iterate("//xforms:repeat[chiba:data]/@id"); this.enclosingRepeat = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); this.nestedRepeat1 = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); this.nestedRepeat2 = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); this.nestedRepeat3 = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); // iterate repeated inputs Iterator inputIterator = context.iterate("//xforms:input/@id"); this.input11 = (Text) this.chibaBean.getContainer().lookup(inputIterator.next().toString()); this.input12 = (Text) this.chibaBean.getContainer().lookup(inputIterator.next().toString()); inputIterator.next(); // skip repeat prototype this.input21 = (Text) this.chibaBean.getContainer().lookup(inputIterator.next().toString()); this.input22 = (Text) this.chibaBean.getContainer().lookup(inputIterator.next().toString()); inputIterator.next(); // skip repeat prototype this.input31 = (Text) this.chibaBean.getContainer().lookup(inputIterator.next().toString()); this.input32 = (Text) this.chibaBean.getContainer().lookup(inputIterator.next().toString()); // iterate repeated actions Iterator actionIterator = context.iterate("//xforms:action/@id"); this.action11 = (XFormsAction) this.chibaBean.getContainer().lookup(actionIterator.next().toString()); this.action12 = (XFormsAction) this.chibaBean.getContainer().lookup(actionIterator.next().toString()); actionIterator.next(); // skip repeat prototype this.action21 = (XFormsAction) this.chibaBean.getContainer().lookup(actionIterator.next().toString()); this.action22 = (XFormsAction) this.chibaBean.getContainer().lookup(actionIterator.next().toString()); actionIterator.next(); // skip repeat prototype this.action31 = (XFormsAction) this.chibaBean.getContainer().lookup(actionIterator.next().toString()); this.action32 = (XFormsAction) this.chibaBean.getContainer().lookup(actionIterator.next().toString()); }
From source file:org.chiba.xml.xforms.ui.test.RepeatItemTest.java
/** * Sets up the test./*from w w w . j a v a 2s . c o m*/ * * @throws Exception in any error occurred during setup. */ protected void setUp() throws Exception { this.chibaBean = new ChibaBean(); this.chibaBean.setXMLContainer(getClass().getResourceAsStream("RepeatItemTest.xhtml")); this.chibaBean.init(); JXPathContext context = JXPathContext.newContext(this.chibaBean.getXMLContainer()); // iterate unrolled repeats Iterator repeatIterator = context.iterate("//xforms:repeat[chiba:data]/@id"); this.enclosingRepeat = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); this.nestedRepeat1 = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); this.nestedRepeat2 = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); this.nestedRepeat3 = (Repeat) this.chibaBean.getContainer().lookup(repeatIterator.next().toString()); }
From source file:org.chiba.xml.xforms.ui.test.RepeatTest.java
/** * Tests for correct prototype handling. * * @throws Exception if any error occurred during the test. *//* w w w . ja v a 2 s.co m*/ public void testRepeatPrototype() throws Exception { JXPathContext context = JXPathContext.newContext(this.repeat.getElement()); /* <chiba:data ... > <xforms:group chiba:transient="true" chiba:position="0"> <xforms:input id="input" xforms:ref="."> <xforms:alert id="..."/> </xforms:input> <xforms:output id="output" xforms:ref="."/> </xforms:group> </chiba:data> */ assertEquals("1", context.getValue("count(chiba:data/*)", Integer.class).toString()); assertEquals("group", context.getValue("local-name(chiba:data/*[1])").toString()); assertEquals(NamespaceCtx.XFORMS_NS, context.getValue("namespace-uri(chiba:data/*[1])").toString()); assertEquals("true", context.getValue("chiba:data/xforms:group/@chiba:transient").toString()); assertEquals("0", context.getValue("chiba:data/xforms:group/@chiba:position").toString()); assertEquals("2", context.getValue("count(chiba:data/xforms:group/*)", Integer.class).toString()); assertEquals("input", context.getValue("local-name(chiba:data/xforms:group/*[1])").toString()); assertEquals(NamespaceCtx.XFORMS_NS, context.getValue("namespace-uri(chiba:data/xforms:group/*[1])").toString()); assertEquals("input", context.getValue("chiba:data/xforms:group/xforms:input/@id").toString()); assertEquals(".", context.getValue("chiba:data/xforms:group/xforms:input/@xforms:ref").toString()); assertEquals("1", context.getValue("count(chiba:data/xforms:group/xforms:input/*)", Integer.class).toString()); assertEquals("alert", context.getValue("local-name(chiba:data/xforms:group/xforms:input/*[1])").toString()); assertEquals(NamespaceCtx.XFORMS_NS, context.getValue("namespace-uri(chiba:data/xforms:group/xforms:input/*[1])").toString()); assertEquals(true, context.getValue("chiba:data/xforms:group/xforms:output/@id").toString().length() > 0); assertEquals("0", context.getValue("count(chiba:data/xforms:group/xforms:output/*)", Integer.class).toString()); assertEquals("output", context.getValue("local-name(chiba:data/xforms:group/*[2])").toString()); assertEquals(NamespaceCtx.XFORMS_NS, context.getValue("namespace-uri(chiba:data/xforms:group/*[2])").toString()); assertEquals("output", context.getValue("chiba:data/xforms:group/xforms:output/@id").toString()); assertEquals(".", context.getValue("chiba:data/xforms:group/xforms:output/@xforms:ref").toString()); assertEquals("0", context.getValue("count(chiba:data/xforms:group/xforms:output/*)", Integer.class).toString()); }
From source file:org.chiba.xml.xforms.ui.test.RepeatTest.java
/** * Tests location path resolution./*from w w w . j av a 2 s.co m*/ * * @throws Exception if any error occurred during the test. */ public void testLocationPath() throws Exception { List ids = new ArrayList(); JXPathContext context = JXPathContext.newContext(this.repeat.getElement()); Iterator iterator = context.iterate("//xforms:input[chiba:data]/@id"); while (iterator.hasNext()) { String id = (String) iterator.next(); ids.add(id); } assertEquals(3, ids.size()); for (int index = 0; index < ids.size(); index++) { String id = (String) ids.get(index); Text input = (Text) this.chibaBean.getContainer().lookup(id); assertEquals("/*[1]/item[" + String.valueOf(index + 1) + "]", input.getLocationPath()); } }