List of usage examples for org.apache.commons.jxpath JXPathContext removePath
public abstract void removePath(String xpath);
From source file:com.ebay.jetstream.epl.EPLUtilities.java
/** * transformToObject - This method converts incoming JsonString to HashMap. Need/use of this method is, in EPL we need * to use pass Objects through window. But EPL allows primitives type alone. For that we 'll convert Obejct to * JsonString and pass it to the stream. After that we need to convert back the Json String to original Object type. * //from w w w . ja v a 2 s . c om */ @SuppressWarnings("unchecked") public static HashMap<String, Object> transformToObjectAndRemoveKey(String jsonStr, String key) throws Exception { if (jsonStr != null) { ObjectMapper mapper = new ObjectMapper(); HashMap<String, Object> event = mapper.readValue(jsonStr, HashMap.class); if (key != null && !key.equals("")) { JXPathContext context = JXPathContext.newContext(event); context.setLenient(true); context.removePath(key); } return event; } return null; }
From source file:org.apache.cocoon.forms.binding.DeleteNodeJXPathBinding.java
/** * Removes the current context-bean from the jxpath context. *///w w w . ja va 2 s . c om public void doSave(Widget frmModel, JXPathContext jxpc) { // get rid of the contextbean jxpc.removePath("."); }
From source file:org.apache.cocoon.forms.binding.EnhancedRepeaterJXPathBinding.java
public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException { Repeater repeater = (Repeater) selectWidget(frmModel, super.getId()); if (!(repeater instanceof EnhancedRepeater)) { super.doSave(frmModel, jxpc); return;/*from w w w . ja v a 2 s . com*/ } EnhancedRepeater rep = (EnhancedRepeater) repeater; rep.doPageSave(); Pointer ptr = jxpc.getPointer(super.getRepeaterPath()); JXPathContext repeaterContext = jxpc.getRelativeContext(ptr); RepeaterJXPathCollection collection = rep.getCollection(); // iterate updated rows. note: we don't iterate over the whole context for (Iterator iter = collection.getUpdatedRows().iterator(); iter.hasNext();) { RepeaterItem item = (RepeaterItem) iter.next(); Repeater.RepeaterRow thisRow = item.getRow(); // Get the identity List identity = getIdentity(thisRow); if (hasNonNullElements(identity)) { // iterate nodes to find match Iterator rowPointers = repeaterContext.iteratePointers(getRowPath()); while (rowPointers.hasNext()) { Pointer jxp = (Pointer) rowPointers.next(); JXPathContext rowContext = repeaterContext.getRelativeContext(jxp); List contextIdentity = getIdentity(rowContext); if (ListUtils.isEqualList(identity, contextIdentity)) { getRowBinding().saveFormToModel(thisRow, rowContext); break; } } } else { getRowBinding().saveFormToModel(thisRow, item.getContext().getContextPointer()); } } for (Iterator iter = collection.getDeletedRows().iterator(); iter.hasNext();) { RepeaterItem item = (RepeaterItem) iter.next(); jxpc.removePath(item.getContext().createPath(".").asPath()); } // insert rows int indexCount = collection.getOriginalCollectionSize() - collection.getDeletedRows().size(); for (Iterator iter = collection.getInsertedRows().iterator(); iter.hasNext();) { indexCount++; RepeaterItem item = (RepeaterItem) iter.next(); // Perform the insert row binding. if (getInsertRowBinding() != null) { getInsertRowBinding().saveFormToModel(item.getRow(), repeaterContext); } // --> create the path to let the context be created Pointer newRowContextPointer = repeaterContext .createPath(super.getInsertRowPath() + "[" + indexCount + "]"); JXPathContext newRowContext = repeaterContext.getRelativeContext(newRowContextPointer); // + rebind to children for update super.getRowBinding().saveFormToModel(item.getRow(), newRowContext); } }
From source file:org.apache.cocoon.forms.binding.MultiValueJXPathBinding.java
public void doSave(Widget frmModel, JXPathContext jctx) throws BindingException { Widget widget = selectWidget(frmModel, this.multiValueId); Object[] values = (Object[]) widget.getValue(); JXPathContext multiValueContext = jctx.getRelativeContext(jctx.createPath(this.multiValuePath)); // Delete all that is already present // Unfortunately the following statement doesn't work (it doesn't removes all elements from the // list because of a bug in JXPath I wasn't able to locate). //multiValueContext.removeAll(this.rowPath); // TODO: This is a workaround until the bug in commons-jxpath is found, fixed and released Iterator rowPointers = multiValueContext.iteratePointers(this.rowPath); int cnt = 0;// w w w . j av a 2 s . com while (rowPointers.hasNext()) { cnt++; rowPointers.next(); } while (cnt >= 1) { String thePath = this.rowPath + "[" + cnt + "]"; multiValueContext.removePath(thePath); cnt--; } 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); } 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.forms.binding.ValueJXPathBinding.java
/** * Actively performs the binding from the CForms-form to the ObjectModel * wrapped in a jxpath context/*from ww w . j a v a 2 s. co 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); } }