You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2003/08/19 21:06:14 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/msg XMLMessages.properties
elena 2003/08/19 12:06:14
Modified: java/src/org/apache/xerces/impl
XMLDocumentFragmentScannerImpl.java
java/src/org/apache/xerces/impl/dtd XMLDTDValidator.java
java/src/org/apache/xerces/impl/io UTF8Reader.java
java/src/org/apache/xerces/impl/msg XMLMessages.properties
Log:
Errata for XML 1.0 Second edition:
this fixes E15.1, (elements declared to be EMPTY in the DTD cannot have
comments, PIs or entity references), E15.2 (character references to
whitespace are not allowed when the elements are declared to have child
content), E27 and E2 (Validity constraint: No duplicate tokens)
Patches provided by Glenn Marcy, Peter McCracken, Neil Delima.
Revision Changes Path
1.36 +8 -2 xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java
Index: XMLDocumentFragmentScannerImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDocumentFragmentScannerImpl.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- XMLDocumentFragmentScannerImpl.java 24 Jul 2003 18:09:54 -0000 1.35
+++ XMLDocumentFragmentScannerImpl.java 19 Aug 2003 19:06:13 -0000 1.36
@@ -61,10 +61,12 @@
import java.io.IOException;
import org.apache.xerces.impl.msg.XMLMessageFormatter;
+import org.apache.xerces.util.AugmentationsImpl;
import org.apache.xerces.util.XMLAttributesImpl;
import org.apache.xerces.util.XMLChar;
import org.apache.xerces.util.XMLStringBuffer;
import org.apache.xerces.util.XMLSymbols;
+import org.apache.xerces.xni.Augmentations;
import org.apache.xerces.xni.QName;
import org.apache.xerces.xni.XMLAttributes;
import org.apache.xerces.xni.XMLDocumentHandler;
@@ -1076,6 +1078,8 @@
} // scanEndElement():int
+ public static final String CHAR_REF = "characterReference";
+
/**
* Scans a character reference.
* <p>
@@ -1095,7 +1099,9 @@
if (fNotifyCharRefs) {
fDocumentHandler.startGeneralEntity(fCharRefLiteral, null, null, null);
}
- fDocumentHandler.characters(fStringBuffer2, null);
+ Augmentations augs = new AugmentationsImpl();
+ augs.putItem(CHAR_REF, Boolean.TRUE);
+ fDocumentHandler.characters(fStringBuffer2, augs);
if (fNotifyCharRefs) {
fDocumentHandler.endGeneralEntity(fCharRefLiteral, null);
}
1.50 +122 -38 xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java
Index: XMLDTDValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/dtd/XMLDTDValidator.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- XMLDTDValidator.java 5 Jun 2003 21:51:32 -0000 1.49
+++ XMLDTDValidator.java 19 Aug 2003 19:06:14 -0000 1.50
@@ -58,6 +58,7 @@
package org.apache.xerces.impl.dtd;
import org.apache.xerces.impl.Constants;
+import org.apache.xerces.impl.XMLDocumentFragmentScannerImpl;
import org.apache.xerces.impl.XMLEntityManager;
import org.apache.xerces.impl.XMLErrorReporter;
import org.apache.xerces.impl.dtd.models.ContentModelValidator;
@@ -852,6 +853,16 @@
if (!allWhiteSpace) {
charDataInContent();
}
+
+ // For E15.2
+ if (augs != null && augs.getItem(XMLDocumentFragmentScannerImpl.CHAR_REF) == Boolean.TRUE) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MSG_CONTENT_INVALID_SPECIFIED",
+ new Object[]{ fCurrentElement.rawname,
+ fDTDGrammar.getContentSpecAsString(fElementDepth),
+ "character reference"},
+ XMLErrorReporter.SEVERITY_ERROR);
+ }
}
if (fCurrentContentSpecType == XMLElementDecl.TYPE_EMPTY) {
@@ -963,7 +974,18 @@
* @throws XNIException Thrown by application to signal an error.
*/
public void comment(XMLString text, Augmentations augs) throws XNIException {
-
+ // fixes E15.1
+ if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) {
+ fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl);
+ if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MSG_CONTENT_INVALID_SPECIFIED",
+ new Object[]{ fCurrentElement.rawname,
+ "EMPTY",
+ "comment"},
+ XMLErrorReporter.SEVERITY_ERROR);
+ }
+ }
// call handlers
if (fDocumentHandler != null) {
fDocumentHandler.comment(text, augs);
@@ -992,6 +1014,18 @@
public void processingInstruction(String target, XMLString data, Augmentations augs)
throws XNIException {
+ // fixes E15.1
+ if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) {
+ fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl);
+ if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MSG_CONTENT_INVALID_SPECIFIED",
+ new Object[]{ fCurrentElement.rawname,
+ "EMPTY",
+ "processing instruction"},
+ XMLErrorReporter.SEVERITY_ERROR);
+ }
+ }
// call handlers
if (fDocumentHandler != null) {
fDocumentHandler.processingInstruction(target, data, augs);
@@ -1019,10 +1053,19 @@
XMLResourceIdentifier identifier,
String encoding,
Augmentations augs) throws XNIException {
-
- if (fPerformValidation && fDTDGrammar != null &&
- fGrammarBucket.getStandalone()) {
- XMLDTDLoader.checkStandaloneEntityRef(name, fDTDGrammar, fEntityDecl, fErrorReporter);
+ if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) {
+ fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl);
+ // fixes E15.1
+ if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MSG_CONTENT_INVALID_SPECIFIED",
+ new Object[]{ fCurrentElement.rawname,
+ "EMPTY", "ENTITY"},
+ XMLErrorReporter.SEVERITY_ERROR);
+ }
+ if (fGrammarBucket.getStandalone()) {
+ XMLDTDLoader.checkStandaloneEntityRef(name, fDTDGrammar, fEntityDecl, fErrorReporter);
+ }
}
if (fDocumentHandler != null) {
fDocumentHandler.startGeneralEntity(name, identifier, encoding, augs);
@@ -1094,7 +1137,7 @@
(fDTDValidation || fSeenDoctypeDecl);
}
- //REVISIT:we can convert into functions.. adding default attribute values.. and one validating.
+ //REVISIT:we can convert into functions.. adding default attribute values.. and one validating.
/** Add default attributes and validate. */
protected void addDTDDefaultAttrsAndValidate(QName elementName, int elementIndex,
@@ -1137,7 +1180,48 @@
String attType = getAttributeTypeName(fTempAttDecl);
int attDefaultType =fTempAttDecl.simpleType.defaultType;
String attValue = null;
-
+
+ boolean found = false;
+ if((fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ENUMERATION ||
+ fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NOTATION) &&
+ fPerformValidation) {
+
+ for (int i=0; i<fTempAttDecl.simpleType.enumeration.length ; i++) {
+ for (int j=0; j<fTempAttDecl.simpleType.enumeration.length ; j++) {
+ if (fTempAttDecl.simpleType.enumeration[i].equals
+ (fTempAttDecl.simpleType.enumeration[j]) && i!=j) {
+ found = true;
+ break;
+ }
+ }
+ if (found)
+ break;
+ }
+
+ StringBuffer enumValueString = new StringBuffer();
+ if (fTempAttDecl.simpleType.enumeration != null) {
+ enumValueString.append("(");
+ for (int i = 0; i < fTempAttDecl.simpleType.enumeration.length; i++) {
+ enumValueString.append(fTempAttDecl.simpleType.enumeration[i]+" ");
+ }
+ enumValueString.append(")");
+ }
+
+ if (found && fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ENUMERATION) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MSG_DISTINCT_TOKENS_IN_ENUMERATION",
+ new Object[] {attRawName, enumValueString},
+ XMLErrorReporter.SEVERITY_ERROR);
+
+ } else if (found && fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NOTATION) {
+ fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
+ "MSG_DISTINCT_NOTATION_IN_ENUMERATION",
+ new Object[] {attRawName, enumValueString},
+ XMLErrorReporter.SEVERITY_ERROR);
+
+ }
+ }
+
if (fTempAttDecl.simpleType.defaultValue != null) {
attValue = fTempAttDecl.simpleType.defaultValue;
}
@@ -1839,34 +1923,34 @@
// VC: Root Element Type
// see if the root element's name matches the one in DoctypeDecl
- if (!fSeenRootElement) {
- // REVISIT: Here are current assumptions about validation features
- // given that XMLSchema validator is in the pipeline
- //
- // http://xml.org/sax/features/validation = true
- // http://apache.org/xml/features/validation/schema = true
- //
- // [1] XML instance document only has reference to a DTD
- // Outcome: report validation errors only against dtd.
- //
- // [2] XML instance document has only XML Schema grammars:
- // Outcome: report validation errors only against schemas (no errors produced from DTD validator)
- //
- // [3] XML instance document has DTD and XML schemas:
- // [a] if schema language is not set outcome - validation errors reported against both grammars: DTD and schemas.
- // [b] if schema language is set to XML Schema - do not report validation errors
- //
- // if dynamic validation is on
- // validate only against grammar we've found (depending on settings
- // for schema feature)
- //
- //
- fPerformValidation = validate();
- fSeenRootElement = true;
- fValidationManager.setEntityState(fDTDGrammar);
- fValidationManager.setGrammarFound(fSeenDoctypeDecl);
- rootElementSpecified(element);
- }
+ if (!fSeenRootElement) {
+ // REVISIT: Here are current assumptions about validation features
+ // given that XMLSchema validator is in the pipeline
+ //
+ // http://xml.org/sax/features/validation = true
+ // http://apache.org/xml/features/validation/schema = true
+ //
+ // [1] XML instance document only has reference to a DTD
+ // Outcome: report validation errors only against dtd.
+ //
+ // [2] XML instance document has only XML Schema grammars:
+ // Outcome: report validation errors only against schemas (no errors produced from DTD validator)
+ //
+ // [3] XML instance document has DTD and XML schemas:
+ // [a] if schema language is not set outcome - validation errors reported against both grammars: DTD and schemas.
+ // [b] if schema language is set to XML Schema - do not report validation errors
+ //
+ // if dynamic validation is on
+ // validate only against grammar we've found (depending on settings
+ // for schema feature)
+ //
+ //
+ fPerformValidation = validate();
+ fSeenRootElement = true;
+ fValidationManager.setEntityState(fDTDGrammar);
+ fValidationManager.setGrammarFound(fSeenDoctypeDecl);
+ rootElementSpecified(element);
+ }
if (fDTDGrammar == null) {
if (!fPerformValidation) {
@@ -1891,7 +1975,7 @@
else {
// resolve the element
fCurrentElementIndex = fDTDGrammar.getElementDeclIndex(element);
- //changed here.. new function for getContentSpecType
+ //changed here.. new function for getContentSpecType
fCurrentContentSpecType = fDTDGrammar.getContentSpecType(fCurrentElementIndex);
if (fCurrentContentSpecType == -1 && fPerformValidation) {
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
@@ -1904,7 +1988,7 @@
// 1. normalize the attributes
// 2. validate the attrivute list.
// TO DO:
- //changed here.. also pass element name,
+ //changed here.. also pass element name,
addDTDDefaultAttrsAndValidate(element, fCurrentElementIndex, attributes);
}
}
1.7 +4 -4 xml-xerces/java/src/org/apache/xerces/impl/io/UTF8Reader.java
Index: UTF8Reader.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/io/UTF8Reader.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- UTF8Reader.java 17 Jun 2003 17:57:14 -0000 1.6
+++ UTF8Reader.java 19 Aug 2003 19:06:14 -0000 1.7
@@ -214,7 +214,7 @@
if (b1 == -1) {
expectedByte(2, 3);
}
- if ((b1 & 0xC0) != 0x80) {
+ if ((b1 & 0xC0) != 0x80 || (b0 == 0xED && b1 >= 0xA0)) {
invalidByte(2, 3, b1);
}
int b2 = index == fOffset
@@ -421,7 +421,7 @@
}
count++;
}
- if ((b1 & 0xC0) != 0x80) {
+ if ((b1 & 0xC0) != 0x80 || (b0 == 0xED && b1 >= 0xA0)) {
if (out > offset) {
fBuffer[0] = (byte)b0;
fBuffer[1] = (byte)b1;
@@ -719,4 +719,4 @@
} // invalidSurrogate(int)
-} // class UTF8Reader
+} // class UTF8Reader
\ No newline at end of file
1.24 +3 -0 xml-xerces/java/src/org/apache/xerces/impl/msg/XMLMessages.properties
Index: XMLMessages.properties
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/msg/XMLMessages.properties,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- XMLMessages.properties 25 Jul 2003 19:35:46 -0000 1.23
+++ XMLMessages.properties 19 Aug 2003 19:06:14 -0000 1.24
@@ -174,6 +174,8 @@
NotationTypeUnterminated = The notation type list must end with '')'' in the \"{1}\" attribute declaration.
MSG_NMTOKEN_REQUIRED_IN_ENUMERATION = The name token is required in the enumerated type list for the \"{1}\" attribute declaration.
EnumerationUnterminated = The enumerated type list must end with '')'' in the \"{1}\" attribute declaration.
+ MSG_DISTINCT_TOKENS_IN_ENUMERATION = The NmTokens in a single Enumeration attribute declaration, must all be distinct.
+ MSG_DISTINCT_NOTATION_IN_ENUMERATION = The notation names in a single NotationType attribute declaration must all be distinct.
# 3.3.2 Attribute Defaults
MSG_SPACE_REQUIRED_AFTER_FIXED_IN_DEFAULTDECL = White space must appear after \"FIXED\" in the \"{1}\" attribute declaration.
# 3.4 Conditional Sections
@@ -226,6 +228,7 @@
MSG_ATTVALUE_CHANGED_DURING_NORMALIZATION_WHEN_STANDALONE = The value \"{1}\" of attribute \"{0}\" must not be changed by normalization (to \"{2}\") in a standalone document.
MSG_CONTENT_INCOMPLETE = The content of element type \"{0}\" is incomplete, it must match \"{1}\".
MSG_CONTENT_INVALID = The content of element type \"{0}\" must match \"{1}\".
+ MSG_CONTENT_INVALID_SPECIFIED = The content of element type \"{0}\" must match \"{1}\". Children of type \"{2}\" are not allowed.
MSG_DEFAULTED_ATTRIBUTE_NOT_SPECIFIED = Attribute \"{1}\" for element type \"{0}\" has a default value and must be specified in a standalone document.
MSG_DUPLICATE_ATTDEF = Attribute \"{1}\" is already declared for element type \"{0}\".
MSG_ELEMENT_ALREADY_DECLARED = Element type \"{0}\" must not be declared more than once.
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org