Author: mukulg Date: Sat Oct 11 07:28:50 2014 New Revision: 1631025 URL: http://svn.apache.org/r1631025 Log: committing fix for jira issue XERCESJ-1646
Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties?rev=1631025&r1=1631024&r2=1631025&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/msg/XMLSchemaMessages.properties Sat Oct 11 07:28:50 2014 @@ -367,6 +367,7 @@ TargetNamespace.2 = TargetNamespace.2: Expecting no namespace, but the schema document has a target namespace of ''{1}''. UndeclaredEntity = UndeclaredEntity: Entity ''{0}'' is not declared. UndeclaredPrefix = UndeclaredPrefix: Cannot resolve ''{0}'' as a QName: the prefix ''{1}'' is not declared. + FacetsContradict = FacetsContradict: For simpleType definition ''{2}'', the enumeration value ''{0}'' contradicts with value of ''{1}'' facet. # JAXP 1.2 schema source property errors Modified: xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java URL: http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java?rev=1631025&r1=1631024&r2=1631025&view=diff ============================================================================== --- xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java (original) +++ xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/impl/xs/traversers/XSDAbstractTraverser.java Sat Oct 11 07:28:50 2014 @@ -28,6 +28,7 @@ import org.apache.xerces.impl.Constants; import org.apache.xerces.impl.dv.InvalidDatatypeValueException; import org.apache.xerces.impl.dv.XSFacets; import org.apache.xerces.impl.dv.XSSimpleType; +import org.apache.xerces.impl.dv.util.Base64; import org.apache.xerces.impl.validation.ValidationState; import org.apache.xerces.impl.xs.SchemaGrammar; import org.apache.xerces.impl.xs.SchemaNamespaceSupport; @@ -354,6 +355,8 @@ abstract class XSDAbstractTraverser { int currentFacet = 0; xsFacets.reset(); boolean seenPattern = false; + Element contextNode = (Element)content.getParentNode(); + boolean hasLengthFacet = false, hasMinLengthFacet = false, hasMaxLengthFacet = false; while (content != null) { // General Attribute Checking Object[] attrs = null; @@ -619,9 +622,11 @@ abstract class XSDAbstractTraverser { switch (currentFacet) { case XSSimpleType.FACET_MINLENGTH: xsFacets.minLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); + hasMinLengthFacet = true; break; case XSSimpleType.FACET_MAXLENGTH: xsFacets.maxLength = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); + hasMaxLengthFacet = true; break; case XSSimpleType.FACET_MAXEXCLUSIVE: xsFacets.maxExclusive = (String)attrs[XSAttributeChecker.ATTIDX_VALUE]; @@ -646,6 +651,7 @@ abstract class XSDAbstractTraverser { break; case XSSimpleType.FACET_LENGTH: xsFacets.length = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); + hasLengthFacet = true; break; case XSSimpleType.FACET_MAXSCALE: xsFacets.maxScale = ((XInt)attrs[XSAttributeChecker.ATTIDX_VALUE]).intValue(); //XML Schema 1.1 @@ -754,9 +760,122 @@ abstract class XSDAbstractTraverser { } fPattern.setLength(0); + + // check if length, minLength and maxLength facets contradict with enumeration facets. + // currently considers the case when the baseValidator is a built-in type. + if (enumData != null) { + if (hasLengthFacet) { + checkEnumerationAndLengthInconsistency(baseValidator, enumData, contextNode, XS11TypeHelper.getSchemaTypeName(typeDef)); + } + if (hasMinLengthFacet) { + checkEnumerationAndMinLengthInconsistency(baseValidator, enumData, contextNode, XS11TypeHelper.getSchemaTypeName(typeDef)); + } + if (hasMaxLengthFacet) { + checkEnumerationAndMaxLengthInconsistency(baseValidator, enumData, contextNode, XS11TypeHelper.getSchemaTypeName(typeDef)); + } + } return new FacetInfo(xsFacets, content, facetsPresent, facetsFixed); } + + /* + * Check whether values of xs:maxLength and xs:enumeration are consistent. Report a warning message if they are not. + */ + private void checkEnumerationAndMaxLengthInconsistency(XSSimpleType baseValidator, Vector enumData, Element contextNode, String typeName) { + if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(baseValidator.getNamespace()) && + SchemaSymbols.ATTVAL_HEXBINARY.equals(baseValidator.getName())) { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + if (enumVal.length() / 2 > xsFacets.maxLength) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_MAXLENGTH, typeName}, contextNode); + } + } + } + else if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(baseValidator.getNamespace()) && + SchemaSymbols.ATTVAL_BASE64BINARY.equals(baseValidator.getName())) { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + byte[] decodedVal = Base64.decode(enumVal); + if (decodedVal != null && (new String(decodedVal)).length() > xsFacets.maxLength) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_MAXLENGTH, typeName}, contextNode); + } + } + } + else { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + if (enumVal.length() > xsFacets.maxLength) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_MAXLENGTH, typeName}, contextNode); + } + } + } + } // checkEnumerationAndMaxLengthInconsistency + + /* + * Check whether values of xs:minLength and xs:enumeration are consistent. Report a warning message if they are not. + */ + private void checkEnumerationAndMinLengthInconsistency(XSSimpleType baseValidator, Vector enumData, Element contextNode, String typeName) { + if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(baseValidator.getNamespace()) && + SchemaSymbols.ATTVAL_HEXBINARY.equals(baseValidator.getName())) { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + if (enumVal.length() / 2 < xsFacets.minLength) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_MINLENGTH, typeName}, contextNode); + } + } + } + else if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(baseValidator.getNamespace()) && + SchemaSymbols.ATTVAL_BASE64BINARY.equals(baseValidator.getName())) { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + byte[] decodedVal = Base64.decode(enumVal); + if (decodedVal != null && (new String(decodedVal)).length() < xsFacets.minLength) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_MINLENGTH, typeName}, contextNode); + } + } + } + else { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + if (enumVal.length() < xsFacets.minLength) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_MINLENGTH, typeName}, contextNode); + } + } + } + } // checkEnumerationAndMinLengthInconsistency + + /* + * Check whether values of xs:length and xs:enumeration are consistent. Report a warning message if they are not. + */ + private void checkEnumerationAndLengthInconsistency(XSSimpleType baseValidator, Vector enumData, Element contextNode, String typeName) { + if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(baseValidator.getNamespace()) && + SchemaSymbols.ATTVAL_HEXBINARY.equals(baseValidator.getName())) { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + if (enumVal.length() / 2 != xsFacets.length) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_LENGTH, typeName}, contextNode); + } + } + } + else if (SchemaSymbols.URI_SCHEMAFORSCHEMA.equals(baseValidator.getNamespace()) && + SchemaSymbols.ATTVAL_BASE64BINARY.equals(baseValidator.getName())) { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + byte[] decodedVal = Base64.decode(enumVal); + if (decodedVal != null && (new String(decodedVal)).length() != xsFacets.length) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_LENGTH, typeName}, contextNode); + } + } + } + else { + for (int enumIdx = 0; enumIdx < enumData.size(); enumIdx++) { + String enumVal = ((String)enumData.get(enumIdx)); + if (enumVal.length() != xsFacets.length) { + reportSchemaWarning("FacetsContradict", new Object[]{enumVal, SchemaSymbols.ELT_LENGTH, typeName}, contextNode); + } + } + } + } // checkEnumerationAndLengthInconsistency // return whether QName/NOTATION is part of the given type --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@xerces.apache.org For additional commands, e-mail: commits-h...@xerces.apache.org