# HG changeset patch
# User wleggette
# Date 1243179715 18000
# Node ID f0bd0cba7ef78e2b17b357e5d92da92840dcbc9a
# Parent dafa5bed9b3ee4f76be40c7ce7b2c9cf31400b3d
Adds validation by projection to XmlBeans. This feature provides a validation
mode using the "must ignore" extensibility rule set.
* * *
Fixed error in conflict between strict wildcard processing and VBP.
diff -r dafa5bed9b3e -r f0bd0cba7ef7
src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java
--- a/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java Thu May
07 00:43:26 2009 -0500
+++ b/src/typeimpl/org/apache/xmlbeans/impl/validator/Validator.java Sun May
24 10:41:55 2009 -0500
@@ -81,6 +81,8 @@
options = XmlOptions.maskNull(options);
_errorListener = (Collection) options.get(XmlOptions.ERROR_LISTENER);
_treatLaxAsSkip =
options.hasOption(XmlOptions.VALIDATE_TREAT_LAX_AS_SKIP);
+ _assumeAnyAttribute =
options.hasOption(XmlOptions.VALIDATE_ASSUME_ANY_ATTRIBUTE);
+ _assumeOpenContent =
options.hasOption(XmlOptions.VALIDATE_ASSUME_OPEN_CONTENT);
if (_errorListener == null)
_errorListener = defaultErrorListener;
@@ -296,7 +298,8 @@
if (!state.visit( name ))
{
- findDetailedErrorBegin(event ,state , name);
+ if (!_assumeOpenContent)
+ findDetailedErrorBegin(event ,state , name);
_eatContent = 1;
@@ -340,7 +343,10 @@
if (elementField == null)
{
- if (wildcardProcess == SchemaParticle.STRICT)
+ // assume open content conflicts with strict
+ // wildcard processing, so we use lax rules
+ if (!_assumeOpenContent &&
+ wildcardProcess == SchemaParticle.STRICT)
{
// KHK: cvc-complex-type.2.4c?
cvc-assess-elt.1.1.1.3.2?
emitFieldError( event,
XmlErrorCodes.ASSESS_ELEM_SCHEMA_VALID$NOT_RESOLVED,
@@ -445,22 +451,24 @@
if (originalErrorState != _errorState)
{
- // not sure how to extract this one
- emitFieldError( event,
XmlErrorCodes.ELEM_LOCALLY_VALID$XSI_TYPE_INVALID_QNAME,
- new Object[] { value }, event.getName(), xsiType, null,
- XmlValidationError.ELEMENT_TYPE_INVALID, state._type);
-
+ //if (!_validationByProjection) {
+ // not sure how to extract this one
+ emitFieldError( event,
XmlErrorCodes.ELEM_LOCALLY_VALID$XSI_TYPE_INVALID_QNAME,
+ new Object[] { value }, event.getName(), xsiType, null,
+ XmlValidationError.ELEMENT_TYPE_INVALID, state._type);
+ //}
_eatContent = 1;
return;
}
else if (xsiType == null)
{
- // NOT SURE errorAttributes._expectedSchemaType = xsiType;
- emitFieldError( event,
XmlErrorCodes.ELEM_LOCALLY_VALID$XSI_TYPE_NOT_FOUND,
- new Object[] { value }, event.getName(), null, null,
- XmlValidationError.ELEMENT_TYPE_INVALID, null);
-
+ if (!_assumeOpenContent) {
+ // NOT SURE errorAttributes._expectedSchemaType = xsiType;
+ emitFieldError( event,
XmlErrorCodes.ELEM_LOCALLY_VALID$XSI_TYPE_NOT_FOUND,
+ new Object[] { value }, event.getName(), null, null,
+ XmlValidationError.ELEMENT_TYPE_INVALID, null);
+ }
_eatContent = 1;
return;
@@ -638,6 +646,8 @@
if (!state._canHaveAttrs)
{
+ if (_assumeAnyAttribute)
+ return;
emitFieldError( event,
XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$NO_WILDCARD,
new Object[] {QNameHelper.pretty( attrName )}, attrName, null,
null,
XmlValidationError.INCORRECT_ATTRIBUTE, state._type);
@@ -677,6 +687,9 @@
if (wildcardProcess == SchemaAttributeModel.NONE)
{
+ if (_assumeAnyAttribute)
+ return;
+
// todo (dutta) need additional logic to determine the
expectedSchemaType
emitFieldError( event,
XmlErrorCodes.ELEM_COMPLEX_TYPE_LOCALLY_VALID$NO_WILDCARD,
new Object[] { QNameHelper.pretty( attrName ) },
@@ -1733,6 +1746,8 @@
private int _errorState;
private Collection _errorListener;
private boolean _treatLaxAsSkip;
+ private boolean _assumeAnyAttribute;
+ private boolean _assumeOpenContent;
private ValidatorVC _vc;
private int _suspendErrors;
private IdentityConstraint _constraintEngine;
diff -r dafa5bed9b3e -r f0bd0cba7ef7
src/xmlpublic/org/apache/xmlbeans/XmlOptions.java
--- a/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java Thu May 07 00:43:26
2009 -0500
+++ b/src/xmlpublic/org/apache/xmlbeans/XmlOptions.java Sun May 24 10:41:55
2009 -0500
@@ -771,6 +771,25 @@
public XmlOptions setValidateTreatLaxAsSkip() {
return set ( VALIDATE_TREAT_LAX_AS_SKIP );
}
+
+ /**
+ * Instructs the validator to ignore any elements not understood
+ * by the schema, closely following the behavior of Schema 1.1 "open
+ * content" rules. This is useful for XML languages that specify a
+ * "must ignore" rule to allow for forward compatibility.
+ */
+ public XmlOptions setValidateAssumeOpenContent() {
+ return set ( VALIDATE_ASSUME_OPEN_CONTENT );
+ }
+
+ /**
+ * Instructs the validator to ignore any attributes not understood
+ * by the schema. This is useful for XML languages that specify a
+ * "must ignore" rule to allow for forward compatibility.
+ */
+ public XmlOptions setValidateAssumeAnyAttribute() {
+ return set ( VALIDATE_ASSUME_ANY_ATTRIBUTE );
+ }
/**
* This option controls whether or not operations on XmlBeans are
@@ -946,6 +965,10 @@
/** @exclude */
public static final String VALIDATE_TEXT_ONLY =
"VALIDATE_TEXT_ONLY";
/** @exclude */
+ public static final String VALIDATE_ASSUME_OPEN_CONTENT =
"VALIDATE_ASSUME_OPEN_CONTENT";
+ /** @exclude */
+ public static final String VALIDATE_ASSUME_ANY_ATTRIBUTE =
"VALIDATE_ASSUME_ANY_ATTRIBUTE";
+ /** @exclude */
public static final String UNSYNCHRONIZED =
"UNSYNCHRONIZED";
/** @exclude */
public static final String ENTITY_RESOLVER =
"ENTITY_RESOLVER";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]