List of usage examples for org.apache.commons.jxpath JXPathContext getValue
public abstract Object getValue(String xpath);
From source file:org.chiba.xml.xforms.test.ChibaBeanTest.java
/** * test, if updateControlValue correctly changes the value and a value-changed event occurs on the relevant control. * Check the new updateControlValue method suitable for Upload controls with anyURI type data. * * @throws Exception/*from w ww . j a v a 2 s. c om*/ */ public void testUploadAnyURI() throws Exception { String testFilename = "hello-upload.xhtml"; String id = "upload-uri"; String nodePath = "//file4"; processor.setXMLContainer(getClass().getResourceAsStream(testFilename)); processor.init(); Listener listener = new ChibaBeanTest.Listener(); JXPathContext context = JXPathContext.newContext(this.processor.getXMLContainer()); Node node = (Node) context.getPointer("//*[@id='" + id + "']").getNode(); EventTarget eventTarget = (EventTarget) node; eventTarget.addEventListener(EventFactory.VALUE_CHANGED, listener, false); /* the content must be the URI !! BufferedInputStream bf = new BufferedInputStream(getClass().getResourceAsStream(testFilename)); byte[] bytes = new byte[bf.available()]; bf.read(bytes); String testString = new String(bytes); */ String uploadFilename = "upload-test.txt"; String uploadMediatype = "text/xml"; processor.updateControlValue(id, uploadMediatype, uploadFilename, getClass().getResource(testFilename).toString().getBytes()); assertTrue(listener.type.equals(EventFactory.VALUE_CHANGED)); assertTrue(listener.target.equals(id)); //test the side effect of dispatching the DOMActivate to a setvalue //trigger -> the instance has a new value Document instance = processor.getContainer().getDefaultModel().getDefaultInstance().getInstanceDocument(); JXPathContext context1 = JXPathContext.newContext(instance); String value = context1.getValue(nodePath).toString(); assertEquals(getClass().getResource(testFilename).toString(), value); //Verify upload properties assertEquals(uploadFilename, context1.getValue(nodePath + "/@path").toString()); assertEquals(uploadMediatype, context1.getValue(nodePath + "/@contentType").toString()); }
From source file:org.chiba.xml.xforms.test.ContainerTest.java
/** * __UNDOCUMENTED__/* w w w. j ava 2s . c o m*/ * * @throws Exception __UNDOCUMENTED__ */ public void testSetInstanceURI() throws Exception { processor.setXMLContainer(getClass().getResourceAsStream("model-test.xml")); processor.setInstanceURI("", "http://instance-uri-test"); JXPathContext context = processor.getContainer().getRootContext(); String src = (String) context.getValue("//xforms:instance[1]/@xforms:src"); assertTrue(src.equals("http://instance-uri-test")); //setting named instance processor.setInstanceURI("another", "file://myfile"); src = (String) context.getValue("//xforms:instance[@id='another']/@xforms:src"); assertTrue(src.equals("file://myfile")); // DOMUtil.prettyPrintDOM(processor.getContainer().getDocument()); }
From source file:org.chiba.xml.xforms.test.RepeatedModelItemsTest.java
public void testDatatype() throws Exception { this.chibaBean.setXMLContainer(getClass().getResourceAsStream("jobAppMini-broken.xml")); this.chibaBean.init(); chibaBean.getContainer().dispatch("insert-trigger", "DOMActivate"); JXPathContext context = JXPathContext.newContext(chibaBean.getContainer().getDocument()); String type = (String) context.getValue( "//*[@chiba:xpath='/jobApplication[1]/resume[1]/education-info[2]/school-name[1]/value[1]']/@chiba:type"); assertEquals("token", type); type = (String) context.getValue( "//*[@chiba:xpath='/jobApplication[1]/resume[1]/education-info[2]/completion-date[1]/value[1]']/@chiba:type"); assertEquals("date", type); }
From source file:org.chiba.xml.xforms.ui.ItemsetTest.java
protected void assertInitializedItemset(String selectId) throws XFormsException { JXPathContext context = this.chibaBean.getContainer().getRootContext(); assertEquals(selectId, "123", context.getValue("//*[@id='" + selectId + "']/chiba:data")); assertEquals(selectId, new Double(1d), context.getValue("count(//*[@id='" + selectId + "']/xf:itemset/chiba:data/xf:item)")); assertEquals(selectId, new Double(3d), context.getValue("count(//*[@id='" + selectId + "']/xf:itemset/xf:item)")); assertItem(context, selectId, 1, "true", "First", "123"); assertItem(context, selectId, 2, "false", "Second", "124"); assertItem(context, selectId, 3, "false", "Third", "125"); }
From source file:org.chiba.xml.xforms.ui.ItemsetTest.java
protected void assertUpdatedItemset(String selectId) throws XFormsException { JXPathContext context = this.chibaBean.getContainer().getRootContext(); assertEquals(selectId, "125", context.getValue("//*[@id='" + selectId + "']/chiba:data")); assertEquals(selectId, new Double(3d), context.getValue("count(//*[@id='" + selectId + "']/xf:itemset/xf:item)")); assertItem(context, selectId, 1, "false", "First", "123"); assertItem(context, selectId, 2, "false", "Second", "124"); assertItem(context, selectId, 3, "true", "Third", "125"); }
From source file:org.chiba.xml.xforms.ui.ItemsetTest.java
protected void assertGrownItemset(String selectId) throws XFormsException { JXPathContext context = this.chibaBean.getContainer().getRootContext(); assertEquals(selectId, "123", context.getValue("//*[@id='" + selectId + "']/chiba:data")); assertEquals(selectId, new Double(4d), context.getValue("count(//*[@id='" + selectId + "']/xf:itemset/xf:item)")); assertItem(context, selectId, 1, "true", "First", "123"); assertItem(context, selectId, 2, "false", "Third", "125"); assertItem(context, selectId, 3, "false", "Second", "124"); assertItem(context, selectId, 4, "false", "Third", "125"); }
From source file:org.chiba.xml.xforms.ui.ItemsetTest.java
protected void assertShrunkItemset(String selectId) throws XFormsException { JXPathContext context = this.chibaBean.getContainer().getRootContext(); assertEquals(selectId, "123", context.getValue("//*[@id='" + selectId + "']/chiba:data")); assertEquals(selectId, new Double(2d), context.getValue("count(//*[@id='" + selectId + "']/xf:itemset/xf:item)")); assertItem(context, selectId, 1, "true", "First", "123"); assertItem(context, selectId, 2, "false", "Third", "125"); }
From source file:org.chiba.xml.xforms.ui.ItemsetTest.java
private void assertItem(JXPathContext context, String id, int position, String selected, String label, String value) {/*from www. j ava2s. co m*/ 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 + "]/@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.Output.java
private String evaluate(String xpath) throws XFormsException { // get enclosing location path and instance id String locationPath = BindingResolver.getExpressionPath(this, this.repeatItemId); String instanceId = PathUtil.getInstanceId(this.model, locationPath); Instance instance = getModel().getInstance(instanceId); if (instance.existsNode(locationPath)) { try {//from w w w. j a v a2s .c om Pointer pointer = instance.getPointer(locationPath); JXPathContext context = instance.getInstanceContext().getRelativeContext(pointer); return String.valueOf(context.getValue(xpath)); } catch (JXPathException e) { throw new XFormsComputeException("could not evaluate output", e, this.model.getTarget(), xpath); } } return null; }
From source file:org.chiba.xml.xforms.ui.OutputTest.java
/** * Tests output with an ui binding.//from w w w . ja v a 2s .com * * @throws Exception if any error occurred during the test. */ public void testUIBinding() throws Exception { Output output = (Output) this.chibaBean.getContainer().lookup("output-ui-binding"); JXPathContext context = this.chibaBean.getContainer().getRootContext(); assertEquals("1", context.getValue("//xf:output[@id='output-ui-binding']/chiba:data")); assertEquals("string", context.getValue("//xf:output[@id='output-ui-binding']/chiba:data/@chiba:type")); assertEquals("1", output.getValue()); assertEquals(null, this.stateChangedListener.getId()); assertEquals(null, this.stateChangedListener.getPropertyNames()); register(output.getTarget(), false); this.chibaBean.updateControlValue("input-item-1", "3"); deregister(output.getTarget(), false); assertEquals("3", context.getValue("//xf:output[@id='output-ui-binding']/chiba:data")); assertEquals("3", output.getValue()); assertEquals("output-ui-binding", this.stateChangedListener.getId()); assertEquals(1, this.stateChangedListener.getPropertyNames().size()); assertEquals("3", this.stateChangedListener.getContext("value")); }