Permalink
Browse files

Add ignorable dynamic XPath errors on MIPs and rename property

  • Loading branch information...
ebruchez committed Nov 5, 2011
1 parent 5b6b2fe commit 3d4f8488f2be19d21dd5ae19229d58c567a2e337
@@ -885,11 +885,12 @@ public ServerError(String message) {
}
public void addServerError(ServerError serverError) {
- if (XFormsProperties.isShowRecoverableErrors(this)) {
+ final int maxErrors = XFormsProperties.getShowMaxRecoverableErrors(this);
+ if (maxErrors > 0) {
if (serverErrors == null)
serverErrors = new ArrayList<ServerError>();
- if (serverErrors.size() < XFormsProperties.getShowMaxRecoverableErrors(this))
+ if (serverErrors.size() < maxErrors)
serverErrors.add(serverError);
}
}
@@ -556,9 +556,23 @@ public void performDefaultAction(XFormsEvent event) {
// Custom event for XPath errors
// NOTE: We don't like this event very much as it is dispatched in the middle of rebuild/recalculate/revalidate,
// and event handlers for this have to be careful. It might be better to dispatch it *after* RRR.
- XFormsUtils.handleNonFatalXPathException(getContainingDocument(), ((XXFormsXPathErrorEvent) event).throwable());
+
+ final Throwable t = ((XXFormsXPathErrorEvent) event).throwable();
+
+ if (isIgnorableXPathError(t))
+ XFormsUtils.logNonFatalXPathExceptionAsDebug(getContainingDocument(), t);
+ else
+ XFormsUtils.handleNonFatalXPathException(getContainingDocument(), t);
}
}
+
+ private boolean isIgnorableXPathError(Throwable t) {
+ if (XFormsProperties.isIgnoreDynamicMIPXPathErrors(containingDocument)) {
+ final Throwable root = OXFException.getRootThrowable(t);
+ return (root instanceof XPathException) && ! ((XPathException) root).isStaticError();
+ } else
+ return false;
+ }
private void doReset() {
// TODO
@@ -16,6 +16,7 @@
import org.apache.commons.collections.map.CompositeMap;
import org.dom4j.Namespace;
import org.dom4j.QName;
+import org.orbeon.oxf.common.OXFException;
import org.orbeon.oxf.common.ValidationException;
import org.orbeon.oxf.util.IndentedLogger;
import org.orbeon.oxf.util.XPathCache;
@@ -358,6 +359,13 @@ private void iterateBinds(BindRunner bindRunner) {
}
}
}
+
+ private void handleMIPXPathException(Exception e, Bind bind, String expression, String message) {
+ final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), message,
+ bind.staticBind.element(), "expression", expression));
+
+ container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ }
private String evaluateXXFormsDefaultBind(Bind bind, int position) {
// Handle xxforms:default MIP
@@ -367,10 +375,7 @@ private String evaluateXXFormsDefaultBind(Bind bind, int position) {
final NodeInfo currentNodeInfo = (NodeInfo) bind.nodeset.get(position - 1);
return evaluateStringExpression(bind.nodeset, position, bind, bind.staticBind.getInitialValue(), getVariables(currentNodeInfo));
} catch (Exception e) {
- final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), "evaluating XForms default bind",
- bind.staticBind.element(), "expression", bind.staticBind.getCalculate()));
-
- container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ handleMIPXPathException(e, bind, bind.staticBind.getInitialValue(), "evaluating XForms default bind");
return null;
}
} else {
@@ -405,10 +410,7 @@ public String evaluateCalculateBind(Bind bind, int position) {
final NodeInfo currentNodeInfo = (NodeInfo) bind.nodeset.get(position - 1);
return evaluateStringExpression(bind.nodeset, position, bind, bind.staticBind.getCalculate(), getVariables(currentNodeInfo));
} catch (Exception e) {
- final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), "evaluating XForms calculate bind",
- bind.staticBind.element(), "expression", bind.staticBind.getCalculate()));
-
- container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ handleMIPXPathException(e, bind, bind.staticBind.getCalculate(), "evaluating XForms calculate bind");
return null;
}
} else {
@@ -473,10 +475,7 @@ private String evaluateCustomMIP(Bind bind, String propertyName, int position, M
try {
return evaluateStringExpression(bind.nodeset, position, bind, expression, currentVariables);
} catch (Exception e) {
- final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), "evaluating XForms custom bind",
- bind.staticBind.element(), "name", propertyName, "expression", expression));
-
- container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ handleMIPXPathException(e, bind, bind.staticBind.getCalculate(), "evaluating XForms custom bind");// xxx "name", propertyName
return null;
}
} else {
@@ -502,10 +501,7 @@ private Boolean evaluateRequiredMIP(Bind bind, int position, Map<String, ValueRe
// Get MIP value
return evaluateBooleanExpression1(bind.nodeset, position, bind, bind.staticBind.getRequired(), currentVariables);
} catch (Exception e) {
- final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), "evaluating XForms required bind",
- bind.staticBind.element(), "expression", bind.staticBind.getRequired()));
-
- container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ handleMIPXPathException(e, bind, bind.staticBind.getRequired(), "evaluating XForms required bind");
return null;
}
} else {
@@ -519,7 +515,7 @@ private void evaluateAndSetReadonlyMIP(Bind bind, int position, Map<String, Valu
// Mark node
bind.setReadonly(position, readonly);
} else if (bind.staticBind.getCalculate() != null) {
- // The bind doesn't have a readonly attribute, but has a calculate: set readonly to true()
+ // The bind doesn't have a readonly attribute, but has` a calculate: set readonly to true()
bind.setReadonly(position, true);
}
//
@@ -551,11 +547,7 @@ private Boolean evaluateReadonlyMIP(Bind bind, int position, Map<String, ValueRe
try {
return evaluateBooleanExpression1(bind.nodeset, position, bind, bind.staticBind.getReadonly(), currentVariables);
} catch (Exception e) {
- final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), "evaluating XForms readonly bind",
- bind.staticBind.element(), "expression", bind.staticBind.getReadonly()));
-
-
- container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ handleMIPXPathException(e, bind, bind.staticBind.getReadonly(), "evaluating XForms readonly bind");
return null;
}
} else {
@@ -577,10 +569,7 @@ private Boolean evaluateRelevantMIP(Bind bind, int position, Map<String, ValueRe
try {
return evaluateBooleanExpression1(bind.nodeset, position, bind, bind.staticBind.getRelevant(), currentVariables);
} catch (Exception e) {
- final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), "evaluating XForms relevant bind",
- bind.staticBind.element(), "expression", bind.staticBind.getRelevant()));
-
- container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ handleMIPXPathException(e, bind, bind.staticBind.getRelevant(), "evaluating XForms relevant bind");
return null;
}
} else {
@@ -863,10 +852,7 @@ private Boolean evaluateConstraintMIP(Bind bind, int position, NodeInfo currentN
// Get MIP value
return evaluateBooleanExpression1(bind.nodeset, position, bind, bind.staticBind.getConstraint(), getVariables(currentNodeInfo));
} catch (Exception e) {
- final ValidationException ve = ValidationException.wrapException(e, new ExtendedLocationData(bind.staticBind.locationData(), "evaluating XForms constraint bind",
- bind.staticBind.element(), "expression", bind.staticBind.getConstraint()));
-
- container.dispatchEvent(new XXFormsXPathErrorEvent(containingDocument, model, ve.getMessage(), ve));
+ handleMIPXPathException(e, bind, bind.staticBind.getConstraint(), "evaluating XForms constraint bind");
return null;
}
} else {
@@ -79,7 +79,7 @@
private static final String DATEPICKER_TWO_MONTHS_PROPERTY = "datepicker.two-months";
private static final String SHOW_ERROR_DIALOG_PROPERTY = "show-error-dialog";
private static final String SHOW_RECOVERABLE_ERRORS_PROPERTY = "show-recoverable-errors";
- private static final String SHOW_MAX_RECOVERABLE_ERRORS_PROPERTY = "show-max-recoverable-errors";
+ private static final String IGNORE_DYNAMIC_MIP_XPATH_ERRORS_PROPERTY = "ignore-dynamic-mip-xpath-errors";
private static final String CLIENT_EVENTS_MODE_PROPERTY = "client.events.mode";
private static final String CLIENT_EVENTS_FILTER_PROPERTY = "client.events.filter";
@@ -215,8 +215,8 @@ public void validate(Object value, LocationData locationData) {
new PropertyDefinition(LOCAL_INSTANCE_INCLUDE_PROPERTY, false, false),
new PropertyDefinition(EXPOSE_XPATH_TYPES_PROPERTY, false, false),
new PropertyDefinition(AJAX_SHOW_LOADING_ICON_PROPERTY, true, false),
- new PropertyDefinition(SHOW_RECOVERABLE_ERRORS_PROPERTY, true, false),
- new PropertyDefinition(SHOW_MAX_RECOVERABLE_ERRORS_PROPERTY, 10, false),
+ new PropertyDefinition(SHOW_RECOVERABLE_ERRORS_PROPERTY, 10, false),
+ new PropertyDefinition(IGNORE_DYNAMIC_MIP_XPATH_ERRORS_PROPERTY, false, false),
new PropertyDefinition(DATE_FORMAT_PROPERTY, "if (. castable as xs:date) then format-date(xs:date(.), '[FNn] [MNn] [D], [Y] [ZN]', 'en', (), ()) else .", false),
new PropertyDefinition(DATETIME_FORMAT_PROPERTY, "if (. castable as xs:dateTime) then format-dateTime(xs:dateTime(.), '[FNn] [MNn] [D], [Y] [H01]:[m01]:[s01] [ZN]', 'en', (), ()) else .", false),
new PropertyDefinition(TIME_FORMAT_PROPERTY, "if (. castable as xs:time) then format-time(xs:time(.), '[H01]:[m01]:[s01] [ZN]', 'en', (), ()) else .", false),
@@ -484,11 +484,11 @@ public static boolean isAjaxShowLoadingIcon(XFormsContainingDocument containingD
}
public static int getShowMaxRecoverableErrors(XFormsContainingDocument containingDocument) {
- return getIntegerProperty(containingDocument, SHOW_MAX_RECOVERABLE_ERRORS_PROPERTY);
- }
+ return getIntegerProperty(containingDocument, SHOW_RECOVERABLE_ERRORS_PROPERTY);
+ }
- public static boolean isShowRecoverableErrors(XFormsContainingDocument containingDocument) {
- return getBooleanProperty(containingDocument, SHOW_RECOVERABLE_ERRORS_PROPERTY);
+ public static boolean isIgnoreDynamicMIPXPathErrors(XFormsContainingDocument containingDocument) {
+ return getBooleanProperty(containingDocument, IGNORE_DYNAMIC_MIP_XPATH_ERRORS_PROPERTY);
}
public static boolean isSpanHTMLLayout(XFormsContainingDocument containingDocument) {
@@ -1560,9 +1560,20 @@ public static void handleNonFatalXPathException(XFormsContainingDocument contain
// The error is non fatal only upon XForms updates
throw new OXFException(t);
} else {
- final IndentedLogger indentedLogger = containingDocument.getIndentedLogger();
- indentedLogger.logWarning("", "exception while evaluating XPath expression", t);
+ logNonFatalXPathException(containingDocument, t);
containingDocument.addServerError(new XFormsContainingDocument.ServerError(t));
}
}
+
+ public static void logNonFatalXPathException(XFormsContainingDocument containingDocument, Throwable t) {
+ // NOTE: For MIPs, this is called as the result of dispatching xforms-xpath-error.
+ final IndentedLogger indentedLogger = containingDocument.getIndentedLogger();
+ indentedLogger.logWarning("", "exception while evaluating XPath expression", t);
+ }
+
+ public static void logNonFatalXPathExceptionAsDebug(XFormsContainingDocument containingDocument, Throwable t) {
+ // NOTE: For MIPs, this is called as the result of dispatching xforms-xpath-error.
+ final IndentedLogger indentedLogger = containingDocument.getIndentedLogger();
+ indentedLogger.logDebug("", "exception while evaluating XPath expression", t);
+ }
}
@@ -16,7 +16,6 @@
import org.dom4j.Node;
import org.dom4j.QName;
import org.orbeon.oxf.xforms.InstanceData;
-import org.orbeon.oxf.xforms.XFormsInstance;
import org.orbeon.oxf.xforms.model.DataModel;
import org.orbeon.saxon.om.*;
import org.orbeon.saxon.trans.Err;
@@ -116,7 +116,8 @@
<property as="xs:boolean" name="oxf.xforms.datepicker.navigator" value="true"/>
<property as="xs:boolean" name="oxf.xforms.datepicker.two-months" value="false"/>
<property as="xs:boolean" name="oxf.xforms.show-error-dialog" value="true"/>
- <property as="xs:boolean" name="oxf.xforms.show-recoverable-errors" value="true"/>
+ <property as="xs:integer" name="oxf.xforms.show-recoverable-errors" value="10"/>
+ <property as="xs:boolean" name="oxf.xforms.ignore-dynamic-mip-xpath-errors" value="false"/>
<property as="xs:integer" name="oxf.xforms.internal-short-delay" value="100"/>
<property as="xs:integer" name="oxf.xforms.delay-before-incremental-request" value="500"/>
Oops, something went wrong.

0 comments on commit 3d4f848

Please sign in to comment.