List of usage examples for org.apache.commons.jxpath JXPathContext iterate
public abstract Iterator iterate(String xpath);
From source file:org.chiba.xml.xforms.ui.RepeatTest.java
/** * Tests location path resolution./*from w w w . j av a2 s . c om*/ * * @throws Exception if any error occurred during the test. */ public void testLocationPath() throws Exception { Repeat repeat = (Repeat) this.chibaBean.getContainer().lookup("repeat"); List ids = new ArrayList(); JXPathContext context = JXPathContext.newContext(repeat.getElement()); Iterator iterator = context.iterate("//xf: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()); } }
From source file:org.chiba.xml.xforms.ui.SelectorTest.java
/** * Tests Select1 with dynamic Itemset.//from w w w. j ava2 s.c om * * @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 ww w . j a v a2 s . co 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./* w ww .jav a 2s.com*/ * * @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 www. ja v a 2 s .c o 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.//from www. j a va2 s . 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("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 ww w . ja va 2 s . 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 location path resolution.//w ww. j a v a2s .c o 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()); } }
From source file:org.cloudml.connectors.util.JXPath.java
public Iterator iterate(Object context) { JXPathContext jpathcontext = JXPathContext.newContext(context); return jpathcontext.iterate(literal); }
From source file:org.codehaus.mojo.javascript.assembler.JsBuilderAssemblerReader.java
/** * {@inheritDoc}/*from w ww.j av a 2 s . co m*/ * * @see org.codehaus.mojo.javascript.assembler.AssemblerReader#getAssembler(java.io.File) */ public Assembler getAssembler(File file) throws Exception { logger.info("Reading assembler descriptor " + file.getAbsolutePath()); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document dom = builder.parse(file); Assembler assembler = new Assembler(); JXPathContext xpath = JXPathContext.newContext(dom); xpath.setLenient(true); String src = (String) xpath.getValue("//directory/@name"); List nodes = xpath.selectNodes("//target"); for (Iterator iterator = nodes.iterator(); iterator.hasNext();) { Node node = (Node) iterator.next(); Script script = new Script(); assembler.addScript(script); JXPathContext nodeContext = JXPathContext.newContext(node); String fileName = (String) nodeContext.getValue("@file"); fileName = fileName.replace('\\', '/'); if (fileName.startsWith(OUTPUT)) { fileName = fileName.substring(OUTPUT.length()); } script.setFileName(fileName); for (Iterator iter = nodeContext.iterate("//include/@name"); iter.hasNext();) { String include = ((String) iter.next()).replace('\\', '/'); if (src != null && src.length() > 0) { include = include.substring(src.length() + 1); } script.addInclude(include); } } return assembler; }