List of usage examples for org.apache.commons.jxpath JXPathContext getPointer
public abstract Pointer getPointer(String xpath);
From source file:org.apache.cocoon.forms.binding.UnionJXPathBinding.java
/** * Narrows the scope on the form-model to the member widget-field, and * narrows the scope on the object-model to the member xpath-context * before continuing the binding over the child-bindings. *///from ww w . jav a2 s . c o m public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { Union unionWidget = (Union) selectWidget(frmModel, this.widgetId); JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); Binding[] subBindings = getChildBindings(); if (subBindings != null) { int size = subBindings.length; for (int i = 0; i < size; i++) { subBindings[i].saveFormToModel(unionWidget, subContext); } } if (getLogger().isDebugEnabled()) { getLogger().debug("done saving " + toString()); } }
From source file:org.apache.cocoon.forms.binding.ValueJXPathBinding.java
/** * Actively performs the binding from the CForms-form to the ObjectModel * wrapped in a jxpath context//from w ww . j a v a 2s .c o m */ public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { Widget widget = selectWidget(frmModel, this.fieldId); Object value = widget.getValue(); if (value != null && convertor != null) { value = convertor.convertToString(value, convertorLocale, null); } Object oldValue = jxpc.getValue(this.xpath); if (getLogger().isDebugEnabled()) { getLogger().debug("value= " + value + "-- oldvalue=" + oldValue); } boolean update = false; if ((value == null && oldValue != null) || value != null && !value.equals(oldValue)) { // first update the value itself if (value != null) { jxpc.createPathAndSetValue(this.xpath, value); } else { jxpc.removePath(this.xpath); } // now perform any other bindings that need to be performed when the value is updated JXPathContext subContext = null; try { subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); } catch (JXPathException e) { // if the value has been set to null and the underlying model is a bean, then // JXPath will not be able to create a relative context if (getLogger().isDebugEnabled()) { getLogger().debug("(Ignorable) problem binding field " + widget.getRequestParameterName(), e); } } if (subContext != null) { this.updateBinding.saveFormToModel(frmModel, subContext); } update = true; } if (getLogger().isDebugEnabled()) { getLogger().debug("done saving " + toString() + " -- value= " + value + " -- on-update == " + update); } }
From source file:org.apache.cocoon.forms.formmodel.WidgetTestHelper.java
public static void assertXPathExists(String message, String xpath, Document doc) { JXPathContext ctx = JXPathContext.newContext(doc); ctx.setLenient(true);/*from ww w .j a v a2 s . c om*/ Pointer pointer = ctx.getPointer(xpath); Assert.assertNotNull(message, pointer.getNode()); }
From source file:org.apache.cocoon.forms.formmodel.WidgetTestHelper.java
public static void assertXPathNotExists(String message, String xpath, Document doc) { JXPathContext ctx = JXPathContext.newContext(doc); ctx.setLenient(true);//from ww w . j av a 2 s . com Pointer pointer = ctx.getPointer(xpath); Assert.assertNull(message, pointer.getNode()); }
From source file:org.apache.cocoon.woody.binding.AggregateJXPathBinding.java
/** * Narrows the scope on the form-model to the member widget-field, and * narrows the scope on the object-model to the member xpath-context * before continuing the binding over the child-bindings. *///from w ww. java 2s . co m public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { AggregateField aggregate = (AggregateField) frmModel.getWidget(this.widgetId); JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); super.doLoad(aggregate, subContext); aggregate.combineFields(); if (getLogger().isDebugEnabled()) { getLogger().debug("Done loading " + toString()); } }
From source file:org.apache.cocoon.woody.binding.AggregateJXPathBinding.java
/** * Narrows the scope on the form-model to the member widget-field, and * narrows the scope on the object-model to the member xpath-context * before continuing the binding over the child-bindings. *//*from ww w.ja v a 2s.com*/ public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { AggregateField aggregate = (AggregateField) frmModel.getWidget(this.widgetId); JXPathContext subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath)); super.doSave(aggregate, subContext); if (getLogger().isDebugEnabled()) { getLogger().debug("Done saving " + toString()); } }
From source file:org.apache.cocoon.woody.binding.ContextJXPathBinding.java
/** * Actively performs the binding from the Woody-form to the ObjectModel * wrapped in a jxpath context./* ww w . j a v a 2 s .c o m*/ */ public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { Pointer ptr = jxpc.getPointer(this.xpath); if (ptr.getNode() == null) { jxpc.createPath(this.xpath); // Need to recreate the pointer after creating the path ptr = jxpc.getPointer(this.xpath); } JXPathContext subContext = jxpc.getRelativeContext(ptr); super.doSave(frmModel, subContext); if (getLogger().isDebugEnabled()) { getLogger().debug("done saving " + toString()); } }
From source file:org.apache.cocoon.woody.binding.JavaScriptJXPathBinding.java
public void doLoad(Widget frmModel, JXPathContext jctx) { if (this.loadScript != null) { Widget widget = frmModel.getWidget(this.id); // Move to widget context Pointer pointer = jctx.getPointer(this.path); // FIXME: remove this ugly hack and get the request from the // Avalon context once binding builder are real components Map objectModel = CocoonComponentManager.getCurrentEnvironment().getObjectModel(); try {//from w w w.j ava 2 s. c o m Map values = new HashMap(3); values.put("widget", widget); values.put("jxpathPointer", pointer); if (pointer.getNode() != null) { values.put("jxpathContext", jctx.getRelativeContext(pointer)); } JavaScriptHelper.execScript(this.loadScript, values, objectModel); } catch (RuntimeException re) { // rethrow throw re; } catch (Exception e) { throw new CascadingRuntimeException("Error invoking JavaScript event handler", e); } } else { if (this.getLogger().isInfoEnabled()) { this.getLogger().info( "[Javascript Binding] - loadForm: No javascript code avaliable. Widget id=" + this.getId()); } } }
From source file:org.apache.cocoon.woody.binding.MultiValueJXPathBinding.java
public void doLoad(Widget frmModel, JXPathContext jctx) throws BindingException { Widget widget = frmModel.getWidget(this.multiValueId); if (widget == null) { throw new BindingException("The widget with the ID [" + this.multiValueId + "] referenced in the binding does not exist in the form definition."); }/*from www .ja v a 2s .co m*/ // Move to multi value context Pointer ptr = jctx.getPointer(this.multiValuePath); if (ptr.getNode() != null) { // There are some nodes to load from JXPathContext multiValueContext = jctx.getRelativeContext(ptr); // build a jxpath iterator for pointers Iterator rowPointers = multiValueContext.iterate(this.rowPath); LinkedList list = new LinkedList(); while (rowPointers.hasNext()) { Object value = rowPointers.next(); if (value != null && convertor != null) { if (value instanceof String) { value = convertor.convertFromString((String) value, convertorLocale, null); } else { getLogger().warn("Convertor ignored on backend-value which isn't of type String."); } } list.add(value); } widget.setValue(list.toArray()); } if (getLogger().isDebugEnabled()) getLogger().debug("done loading values " + toString()); }
From source file:org.apache.cocoon.woody.binding.RepeaterJXPathBinding.java
/** * Binds the unique-id of the repeated rows, and narrows the context on * objectModelContext and Repeater to the repeated rows before handing * over to the actual binding-children./* w w w . j a v a 2 s . c o m*/ */ public void doLoad(Widget frmModel, JXPathContext jxpc) throws BindingException { // Find the repeater Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId); repeater.removeRows(); int initialSize = repeater.getSize(); // build a jxpath iterator for pointers JXPathContext repeaterContext = jxpc.getRelativeContext(jxpc.getPointer(this.repeaterPath)); Iterator rowPointers = repeaterContext.iteratePointers(this.rowPath); //iterate through it while (rowPointers.hasNext()) { // create a new row, take that as the frmModelSubContext Repeater.RepeaterRow thisRow; if (initialSize > 0) { thisRow = repeater.getRow(--initialSize); } else { thisRow = repeater.addRow(); } // make a jxpath ObjectModelSubcontext on the iterated element Pointer jxp = (Pointer) rowPointers.next(); JXPathContext rowContext = repeaterContext.getRelativeContext(jxp); // hand it over to children Iterator iter = this.uniqueRowBinding.iterator(); while (iter.hasNext()) { ((UniqueFieldJXPathBinding) iter.next()).loadFormFromModel(thisRow, rowContext); } this.rowBinding.loadFormFromModel(thisRow, rowContext); } if (getLogger().isDebugEnabled()) getLogger().debug("done loading rows " + toString()); }