List of usage examples for org.apache.commons.jxpath JXPathContext isLenient
public synchronized boolean isLenient()
From source file:com.idega.chiba.web.xml.xforms.elements.action.IdegaDeleteAction.java
/** * Performs the <code>delete</code> action for all nodes. * //from w w w . j a v a 2 s . co m * @throws XFormsException * if an error occurred during <code>delete</code> processing. */ public void perform() throws XFormsException { super.perform(); // get instance and nodeset information Instance instance = this.model.getInstance(getInstanceId()); String pathExpression = getLocationPath(); int contextSize = instance.countNodeset(pathExpression); if (contextSize == 0) { getLogger().warn(this + " perform: nodeset '" + pathExpression + "' is empty"); return; } String path = null; // since jxpath doesn't provide a means for evaluating an expression // in a certain context, we use a trick here: the expression will be // evaluated during getPointer and the result stored as a variable JXPathContext context = instance.getInstanceContext(); boolean lenient = context.isLenient(); context.setLenient(true); context.getPointer(pathExpression + "[chiba:declare('delete-position', 1)]"); context.setLenient(lenient); // since jxpath's round impl is buggy (returns 0 for NaN) we perform // 'round' manually double value = ((Double) context.getValue("number(chiba:undeclare('delete-position'))")).doubleValue(); long position = Math.round(value); if (Double.isNaN(value) || position < 1 || position > contextSize) { getLogger().warn(this + " perform: expression '1' does not point to an existing node"); return; } path = new StringBuffer(pathExpression).append('[').append(position).append(']').toString(); // delete specified node and dispatch notification event while (instance.existsNode(path)) { try { instance.deleteNode(path); getLogger().info("Node deleted in delete action:" + path); } catch (JXPathException e) { getLogger().warn("Unable to delete:" + path); } } if (StringUtil.isEmpty(path)) { return; } this.container.dispatch(instance.getTarget(), XFormsEventNames.DELETE, path); // update behaviour doRebuild(true); doRecalculate(true); doRevalidate(true); doRefresh(true); }
From source file:org.apache.cocoon.forms.binding.JXPathBindingBase.java
/** * Redefines the Binding action as working on a JXPathContext Type rather * then on generic objects.//from ww w . ja v a 2s.co m * Executes the actual loading via {@link #doLoad(Widget, JXPathContext)} * depending on the configured value of the "direction" attribute. */ public final void loadFormFromModel(Widget frmModel, JXPathContext jxpc) throws BindingException { boolean inheritedLeniency = jxpc.isLenient(); applyLeniency(jxpc); applyNSDeclarations(jxpc); if (this.commonAtts.loadEnabled) { doLoad(frmModel, jxpc); } jxpc.setLenient(inheritedLeniency); }
From source file:org.apache.cocoon.forms.binding.JXPathBindingBase.java
/** * Redefines the Binding action as working on a JXPathContext Type rather * then on generic objects./*from ww w . j av a2 s.com*/ * Executes the actual saving via {@link #doSave(Widget, JXPathContext)} * depending on the configured value of the "direction" attribute. */ public final void saveFormToModel(Widget frmModel, JXPathContext jxpc) throws BindingException { boolean inheritedLeniency = jxpc.isLenient(); applyLeniency(jxpc); applyNSDeclarations(jxpc); if (this.commonAtts.saveEnabled) { doSave(frmModel, jxpc); } jxpc.setLenient(inheritedLeniency); }
From source file:org.apache.cocoon.generation.JXTemplateGenerator.java
static private Object getValue(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext, Boolean lenient) throws Exception { if (expr != null) { Object compiled = expr.compiledExpression; try {/* w ww. j av a 2 s .c o m*/ if (compiled instanceof CompiledExpression) { CompiledExpression e = (CompiledExpression) compiled; boolean oldLenient = jxpathContext.isLenient(); if (lenient != null) { jxpathContext.setLenient(lenient.booleanValue()); } try { return e.getValue(jxpathContext); } finally { jxpathContext.setLenient(oldLenient); } } else if (compiled instanceof Expression) { Expression e = (Expression) compiled; return e.evaluate(jexlContext); } return compiled; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof Exception) { throw (Exception) t; } throw (Error) t; } } else { return null; } }
From source file:org.apache.cocoon.generation.JXTemplateGenerator.java
private Object getNode(JXTExpression expr, JexlContext jexlContext, JXPathContext jxpathContext, Boolean lenient) throws Exception { try {/*from ww w. jav a 2 s . com*/ Object compiled = expr.compiledExpression; if (compiled instanceof CompiledExpression) { CompiledExpression e = (CompiledExpression) compiled; boolean oldLenient = jxpathContext.isLenient(); if (lenient != null) jxpathContext.setLenient(lenient.booleanValue()); try { Iterator iter = e.iteratePointers(jxpathContext); if (iter.hasNext()) { Pointer first = (Pointer) iter.next(); if (iter.hasNext()) { List result = new LinkedList(); result.add(first.getNode()); boolean dom = (first.getNode() instanceof Node); while (iter.hasNext()) { Object obj = ((Pointer) iter.next()).getNode(); dom = dom && (obj instanceof Node); result.add(obj); } Object[] arr; if (dom) { arr = new Node[result.size()]; } else { arr = new Object[result.size()]; } result.toArray(arr); return arr; } return first.getNode(); } return null; } finally { jxpathContext.setLenient(oldLenient); } } else if (compiled instanceof Expression) { Expression e = (Expression) compiled; return e.evaluate(jexlContext); } return expr.raw; } catch (InvocationTargetException e) { Throwable t = e.getTargetException(); if (t instanceof Exception) { throw (Exception) t; } throw (Error) t; } }
From source file:org.apache.cocoon.woody.binding.JXPathBindingBase.java
/** * Redefines the Binding action as working on a JXPathContext Type rather * then on generic objects.//from w w w . j a va 2 s . c o m * Executes the actual loading via {@link #doLoad(Widget, JXPathContext)} * depending on the configured value of the "direction" attribute. */ public final void loadFormFromModel(Widget frmModel, JXPathContext jxpc) throws BindingException { boolean inheritedLeniency = jxpc.isLenient(); applyLeniency(jxpc); if (this.commonAtts.loadEnabled) { doLoad(frmModel, jxpc); } jxpc.setLenient(inheritedLeniency); }
From source file:org.apache.cocoon.woody.binding.JXPathBindingBase.java
/** * Redefines the Binding action as working on a JXPathContext Type rather * then on generic objects./*from w w w . j a v a 2 s.c o m*/ * Executes the actual saving via {@link #doSave(Widget, JXPathContext)} * depending on the configured value of the "direction" attribute. */ public final void saveFormToModel(Widget frmModel, JXPathContext jxpc) throws BindingException { boolean inheritedLeniency = jxpc.isLenient(); applyLeniency(jxpc); if (this.commonAtts.saveEnabled) { doSave(frmModel, jxpc); } jxpc.setLenient(inheritedLeniency); }