List of usage examples for org.apache.commons.jxpath JXPathContext removeAll
public abstract void removeAll(String xpath);
From source file:org.apache.cocoon.components.source.impl.XModuleSource.java
/** * Delete the source /* www . ja va 2s . c o m*/ */ public void delete() throws SourceException { if (!(this.xPath.length() == 0 || this.xPath.equals("/"))) { Object value; try { value = getInputAttribute(this.attributeType, this.attributeName); } catch (SAXException e) { throw new SourceException("delete: ", e); } if (value == null) throw new SourceException(" The attribute: " + this.attributeName + " is empty"); JXPathContext context = JXPathContext.newContext(value); context.removeAll(this.xPath); } else { try { setOutputAttribute(this.attributeType, this.attributeName, null); } catch (SAXException e) { throw new SourceException("delete: ", e); } } }
From source file:org.apache.cocoon.forms.binding.SimpleRepeaterJXPathBinding.java
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException { // Find the repeater Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId); if (repeater.getSize() == 0 && this.deleteIfEmpty) { // Repeater is empty : erase all jctx.removeAll(this.repeaterPath); } else {// w ww .j av a 2 s . co m // Repeater is not empty // Move to repeater context and create the path if needed JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath)); // Delete all that is already present repeaterContext.removeAll(this.rowPath); for (int i = 0; i < repeater.getSize(); i++) { Pointer rowPtr = repeaterContext.createPath(this.rowPath + '[' + (i + 1) + ']'); JXPathContext rowContext = repeaterContext.getRelativeContext(rowPtr); this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext); } } }
From source file:org.apache.cocoon.forms.binding.TempRepeaterJXPathBinding.java
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException { // (See comment in doLoad about type checking and throwing a meaningful exception.) Repeater repeater = (Repeater) selectWidget(frmModel, this.repeaterId); // Perform shortcut binding if the repeater is empty // and the deleteIfEmpty config option is selected. if (repeater.getSize() == 0 && this.deleteIfEmpty) { // Delete all of the old data for this repeater. jctx.removeAll(this.repeaterPath); // Otherwise perform the normal save binding. } else {/*from w w w . j av a2 s . co m*/ // Narrow to the repeater context, creating the path if it did not exist. JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath)); // Start by deleting all of the old row data. repeaterContext.removeAll(this.rowPath); // Verify that repeater is not empty and has an insert row binding. if (repeater.getSize() > 0) { if (this.insertRowBinding != null) { //register the factory! //this.insertRowBinding.saveFormToModel(repeater, repeaterContext); // Iterate through the repeater rows. for (int i = 0; i < repeater.getSize(); i++) { // Narrow to the repeater row context. Pointer rowPointer = repeaterContext.getPointer(this.rowPathInsert); JXPathContext rowContext = repeaterContext.getRelativeContext(rowPointer); // Variables used for virtual rows. // They are initialized here just to keep the compiler happy. Node rowNode = null; Node virtualNode = null; // If virtual rows are requested, create a temporary node and // narrow the context to this initially empty new virtual row. if (virtualRows == true) { rowNode = (Node) rowContext.getContextBean(); Document document = rowNode.getOwnerDocument(); virtualNode = document.createElementNS(null, "virtual"); Node fakeDocElement = document.getDocumentElement().cloneNode(false); fakeDocElement.appendChild(virtualNode); rowContext = JXPathContext.newContext(repeaterContext, fakeDocElement); rowContext = rowContext.getRelativeContext(rowContext.getPointer("virtual")); } // Perform the insert row binding this.insertRowBinding.saveFormToModel(repeater, rowContext); // Perform the save row binding. this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext); // If virtual rows are requested, finish by appending the // children of the virtual row to the real context node. if (virtualRows == true) { NodeList list = virtualNode.getChildNodes(); int count = list.getLength(); for (int j = 0; j < count; j++) { // The list shrinks when a child is appended to the context // node, so we always reference the first child in the list. rowNode.appendChild(list.item(0)); } } getLogger().debug("bound new row"); } } else { getLogger().warn("TempRepeaterBinding has detected rows to insert, " + "but misses the <on-insert-row> binding to do it."); } } } }
From source file:org.apache.cocoon.woody.binding.MultiValueJXPathBinding.java
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException { Widget widget = frmModel.getWidget(this.multiValueId); Object[] values = (Object[]) widget.getValue(); JXPathContext multiValueContext = jctx.getRelativeContext(jctx.createPath(this.multiValuePath)); // Delete all that is already present multiValueContext.removeAll(this.rowPath); boolean update = false; if (values != null) { // first update the values for (int i = 0; i < values.length; i++) { String path = this.rowPath + '[' + (i + 1) + ']'; Pointer rowPtr = multiValueContext.createPath(path); Object value = values[i]; if (value != null && convertor != null) { value = convertor.convertToString(value, convertorLocale, null); }/* www. ja v a 2 s . c om*/ rowPtr.setValue(value); } // now perform any other bindings that need to be performed when the value is updated this.updateBinding.saveFormToModel(frmModel, multiValueContext); update = true; } if (getLogger().isDebugEnabled()) { getLogger().debug("done saving " + toString() + " -- on-update == " + update); } }
From source file:org.apache.cocoon.woody.binding.SimpleRepeaterJXPathBinding.java
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException { // Find the repeater Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId); if (repeater.getSize() == 0 && this.deleteIfEmpty) { // Repeater is empty : erase all jctx.removeAll(this.repeaterPath); } else {/*from www . j a v a 2 s . c o m*/ // Repeater is not empty // Move to repeater context and create the path if needed JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath)); // Delete all that is already present repeaterContext.removeAll(this.rowPath); for (int i = 0; i < repeater.getSize(); i++) { Pointer rowPtr = repeaterContext.createPath(this.rowPath + '[' + (i + 1) + ']'); JXPathContext rowContext = repeaterContext.getRelativeContext(rowPtr); this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext); } } }
From source file:org.apache.cocoon.woody.binding.TempRepeaterJXPathBinding.java
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException { // (See comment in doLoad about type checking and throwing a meaningful exception.) Repeater repeater = (Repeater) frmModel.getWidget(this.repeaterId); // Perform shortcut binding if the repeater is empty // and the deleteIfEmpty config option is selected. if (repeater.getSize() == 0 && this.deleteIfEmpty) { // Delete all of the old data for this repeater. jctx.removeAll(this.repeaterPath); // Otherwise perform the normal save binding. } else {/*from w w w . j a v a 2 s. c o m*/ // Narrow to the repeater context, creating the path if it did not exist. JXPathContext repeaterContext = jctx.getRelativeContext(jctx.createPath(this.repeaterPath)); // Start by deleting all of the old row data. repeaterContext.removeAll(this.rowPath); // Verify that repeater is not empty and has an insert row binding. if (repeater.getSize() > 0) { if (this.insertRowBinding != null) { //register the factory! //this.insertRowBinding.saveFormToModel(repeater, repeaterContext); // Iterate through the repeater rows. for (int i = 0; i < repeater.getSize(); i++) { // Narrow to the repeater row context. Pointer rowPointer = repeaterContext.getPointer(this.rowPathInsert); JXPathContext rowContext = repeaterContext.getRelativeContext(rowPointer); // Variables used for virtual rows. // They are initialized here just to keep the compiler happy. Node rowNode = null; Node virtualNode = null; // If virtual rows are requested, create a temporary node and // narrow the context to this initially empty new virtual row. if (virtualRows == true) { rowNode = (Node) rowContext.getContextBean(); virtualNode = rowNode.getOwnerDocument().createElementNS(null, "virtual"); rowContext = JXPathContext.newContext(repeaterContext, virtualNode); } // Perform the insert row binding this.insertRowBinding.saveFormToModel(repeater, rowContext); // Perform the save row binding. this.rowBinding.saveFormToModel(repeater.getRow(i), rowContext); // If virtual rows are requested, finish by appending the // children of the virtual row to the real context node. if (virtualRows == true) { NodeList list = virtualNode.getChildNodes(); int count = list.getLength(); for (int j = 0; j < count; j++) { // The list shrinks when a child is appended to the context // node, so we always reference the first child in the list. rowNode.appendChild(list.item(0)); } } getLogger().debug("bound new row"); } } else { getLogger().warn("TempRepeaterBinding has detected rows to insert, " + "but misses the <on-insert-row> binding to do it."); } } } }