List of usage examples for org.apache.commons.jxpath JXPathContext getPointer
public abstract Pointer getPointer(String xpath);
From source file:org.chiba.xml.xforms.test.ContainerTest.java
public void testImportInstance() throws Exception { this.processor.setXMLContainer(getClass().getResourceAsStream("buglet.xml")); Element e = getXmlResource("buglet-instance.xml").getDocumentElement(); this.processor.importInstance("another", e); //compare inlined instance with external one JXPathContext context = processor.getContainer().getRootContext(); Element e1 = (Element) context.getPointer("//xforms:instance[@id='another']/*[1]").getNode(); assertTrue(getComparator().compare(e, e1)); }
From source file:org.chiba.xml.xforms.test.RepeatedModelItemsTest.java
public void testInitialState() throws Exception { this.chibaBean.setXMLContainer(getClass().getResourceAsStream("repeatedModelItems.xhtml")); this.chibaBean.init(); Instance instance = this.chibaBean.getContainer().getDefaultModel().getDefaultInstance(); // ModelItem item = instance.getModelItem("/data/items/item[2]/a[1]"); // assertNotNull(item); ///*from ww w . j a v a2 s . co m*/ // System.out.println("item type: " + item.getDatatype()); // System.out.println("item type: " + item.getRelevant()); // System.out.println("item type: " + item.getReadonly()); JXPathContext context = JXPathContext.newContext(instance.getInstanceDocument()); NodeImpl node = (NodeImpl) context.getPointer("//x").getNode(); Object object = node.getUserData(); assertNotNull(object); ModelItem item = instance.getModelItem("//x"); assertNotNull(item); item = instance.getModelItem("//items/item[2]/a"); assertNotNull(item); assertEquals("string", item.getDatatype()); assertEquals("false()", item.getReadonly()); assertEquals("string-length(.) = 3", item.getRelevant()); item = instance.getModelItem("//items/item[2]/b"); assertEquals("integer", item.getDatatype()); assertEquals("false()", item.getRequired()); assertEquals("string-length(.) = 3", item.getRelevant()); item = instance.getModelItem("//items/item[2]/c"); assertEquals("count(//items/item)", item.getCalculate()); chibaBean.getContainer().dispatch("insert", "DOMActivate"); DOMUtil.prettyPrintDOM( chibaBean.getContainer().getDefaultModel().getDefaultInstance().getInstanceDocument()); item = instance.getModelItem("/data[1]/items[1]/item[3]"); assertNotNull(item); assertEquals("false()", item.getReadonly()); item = instance.getModelItem("/data[1]/items[1]/item[3]/a[1]"); assertNotNull(item); assertEquals("string", item.getDatatype()); assertEquals("false()", item.getReadonly()); assertEquals("string-length(.) = 3", item.getRelevant()); }
From source file:org.chiba.xml.xforms.ui.OutputTest.java
public void testTreeUIBinding() throws Exception { JXPathContext context = this.chibaBean.getContainer().getRootContext(); Node instanceNode = (Node) context.getPointer("//tree").getNode(); Node dataNode = (Node) context.getPointer("//xf:output[@id='tree-ui-binding']/chiba:data/*").getNode(); assertTrue(getComparator().compare(instanceNode, dataNode)); }
From source file:org.chiba.xml.xforms.xpath.test.ExtensionFunctionsTest.java
public void testInstance() throws Exception { Document inDocument = getXmlResource("instance-test.xml"); ChibaBean chibaBean = new ChibaBean(); chibaBean.setXMLContainer(inDocument); chibaBean.init();/* www .j a v a 2 s. c om*/ // XPathExtensionFunctions functions = new XPathExtensionFunctions(chibaBean.getContainer().getDefaultModel()); XPathExtensionFunctions functions = new XPathExtensionFunctions(); functions.setNamespaceContext(chibaBean.getContainer().getDefaultModel().getDefaultInstance().getElement()); JXPathContext context = chibaBean.getContainer().getDefaultModel().getDefaultInstance() .getInstanceContext(); context.setFunctions(functions); Object o = context.getValue("instance('first')/some-dummy"); assertTrue(o.equals("some dummy value")); o = context.getValue("xforms:instance('first')/some-dummy"); assertTrue(o.equals("some dummy value")); o = context.getValue("instance('second')/."); assertTrue(o.equals("another dummy value")); Pointer pointer = context.getPointer("instance('second')/."); assertEquals("another dummy value", pointer.getValue()); assertEquals("/another-dummy[1]", pointer.asPath()); o = context.getValue("xforms:instance('second')/."); assertTrue(o.equals("another dummy value")); }
From source file:org.chiba.xml.xforms.xpath.test.JXPathTest.java
/** * Tests calculation with a relative context. * * @throws Exception if any error occurred during the test. *///from w w w. j a v a 2 s . com public void testRelativeCalculation() throws Exception { Pointer rootPointer = this.context.getPointer("//my:item[2]/my:discount"); JXPathContext relativeContext = this.context.getRelativeContext(rootPointer); Pointer relativePointer = relativeContext.getPointer("string(count(../../my:item))"); assertEquals("2", relativePointer.getValue()); }
From source file:org.chiba.xml.xforms.xpath.test.JXPathTest.java
/** * Tests relevance with a relative context. * * @throws Exception if any error occurred during the test. *///from w w w . j av a 2 s . c o m public void testRelativeRelevance() throws Exception { Pointer rootPointer1 = this.context.getPointer("//my:item[1]/my:discount"); JXPathContext relativeContext1 = this.context.getRelativeContext(rootPointer1); Pointer relativePointer1 = relativeContext1.getPointer("boolean(../my:amount > 100)"); assertEquals(Boolean.TRUE, relativePointer1.getValue()); Pointer rootPointer2 = this.context.getPointer("//my:item[2]/my:discount"); JXPathContext relativeContext2 = this.context.getRelativeContext(rootPointer2); Pointer relativePointer2 = relativeContext2.getPointer("boolean(../my:amount > 100)"); assertEquals(Boolean.FALSE, relativePointer2.getValue()); Pointer rootPointer3 = this.context.getPointer("//my:item[2]/my:discount"); JXPathContext relativeContext3 = this.context.getRelativeContext(rootPointer3); Pointer relativePointer3 = relativeContext3.getPointer("boolean(../my:non-existing-node > 100)"); assertEquals(Boolean.FALSE, relativePointer3.getValue()); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathPointer(JXPathContext ctx, String xpath, String expected) { ctx.setLenient(false);//from w ww .ja v a 2 s .c om Pointer pointer = ctx.getPointer(xpath); String actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathPointerLenient(JXPathContext ctx, String xpath, String expected) { ctx.setLenient(true);//from www . j a v a 2 s . c o m Pointer pointer = ctx.getPointer(xpath); String actual = pointer.toString(); assertEquals("Evaluating pointer <" + xpath + ">", expected, actual); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertDocumentOrder(JXPathContext context, String path1, String path2, int expected) { NodePointer np1 = (NodePointer) context.getPointer(path1); NodePointer np2 = (NodePointer) context.getPointer(path2); int res = np1.compareTo(np2); if (res < 0) { res = -1;/*from w w w . j a v a 2 s .c o m*/ } else if (res > 0) { res = 1; } assertEquals("Comparing paths '" + path1 + "' and '" + path2 + "'", expected, res); }
From source file:org.firesoa.common.jxpath.JXPathTestCase.java
protected void assertXPathNodeType(JXPathContext ctx, String xpath, Class clazz) { ctx.setLenient(false);//w w w . j av a2 s .c o m Pointer actual = ctx.getPointer(xpath); assertTrue("Evaluating <" + xpath + "> = " + actual.getNode().getClass(), clazz.isAssignableFrom(actual.getNode().getClass())); }