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 2001/10/25 02:44:34 UTC
cvs commit: xml-xerces/java/src/org/apache/xerces/impl/validation ValidationManager.java
elena 01/10/24 17:44:34
Modified: java/src/org/apache/xerces/impl XMLDTDValidator.java
java/src/org/apache/xerces/impl/v2 SchemaValidator.java
java/src/org/apache/xerces/impl/validation
ValidationManager.java
Log:
Add dynamic validation to schema validator + allow validation of files with dtd only.
Need to revisit the assumptions we make about the meaning of validation and schema features
Revision Changes Path
1.10 +29 -4 xml-xerces/java/src/org/apache/xerces/impl/XMLDTDValidator.java
Index: XMLDTDValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/XMLDTDValidator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- XMLDTDValidator.java 2001/10/16 15:11:37 1.9
+++ XMLDTDValidator.java 2001/10/25 00:44:33 1.10
@@ -128,7 +128,7 @@
* @author Andy Clark, IBM
* @author Jeffrey Rodriguez IBM
*
- * @version $Id: XMLDTDValidator.java,v 1.9 2001/10/16 15:11:37 elena Exp $
+ * @version $Id: XMLDTDValidator.java,v 1.10 2001/10/25 00:44:33 elena Exp $
*/
public class XMLDTDValidator
implements XMLComponent,
@@ -156,6 +156,7 @@
protected static final String DYNAMIC_VALIDATION =
Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE;
+ /** Feature identifier: xml schema validation */
protected static final String SCHEMA_VALIDATION =
Constants.XERCES_FEATURE_PREFIX +Constants.SCHEMA_VALIDATION_FEATURE;
@@ -221,7 +222,8 @@
/** Validation. */
protected boolean fValidation;
- /** Validation. */
+
+ /** Validation against only DTD */
protected boolean fDTDValidation;
/**
@@ -522,7 +524,8 @@
// clear grammars
fDTDGrammar = null;
-
+ fSeenDoctypeDecl = false;
+
// initialize state
fInDTD = false;
fInDTDIgnore = false;
@@ -2561,14 +2564,36 @@
protected void handleStartElement(QName element, XMLAttributes attributes,
boolean isEmpty) throws XNIException {
+ // 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:
+ // Outcome: validation errors reported against both grammars: DTD and schemas.
+ //
+ //
+ // if dynamic validation is on
+ // validate only against grammar we've found (depending on settings
+ // for schema feature)
+ //
// set wether we're performing validation
- fPerformValidation = fValidation && (!fDynamicValidation || fSeenDoctypeDecl) && fDTDValidation;
+ fPerformValidation = fValidation && (!fDynamicValidation || fSeenDoctypeDecl)
+ && (fDTDValidation || fSeenDoctypeDecl);
// VC: Root Element Type
// see if the root element's name matches the one in DoctypeDecl
if (!fSeenRootElement) {
fSeenRootElement = true;
fValidationManager.getValidationState().setEntityState(fDTDGrammar);
+ fValidationManager.setGrammarFound(fSeenDoctypeDecl);
rootElementSpecified(element);
}
1.40 +82 -31 xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaValidator.java
Index: SchemaValidator.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/SchemaValidator.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- SchemaValidator.java 2001/10/23 19:43:54 1.39
+++ SchemaValidator.java 2001/10/25 00:44:33 1.40
@@ -115,7 +115,7 @@
* @author Andy Clark, IBM
* @author Jeffrey Rodriguez IBM
*
- * @version $Id: SchemaValidator.java,v 1.39 2001/10/23 19:43:54 lmartin Exp $
+ * @version $Id: SchemaValidator.java,v 1.40 2001/10/25 00:44:33 elena Exp $
*/
public class SchemaValidator
implements XMLComponent, XMLDocumentFilter,
@@ -128,8 +128,16 @@
private static final boolean DEBUG = false;
// feature identifiers
+
+ protected static final String NAMESPACES =
+ Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE;
+
/** Feature identifier: validation. */
protected static final String VALIDATION =
+ Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE;
+
+ /** Feature identifier: validation. */
+ protected static final String SCHEMA_VALIDATION =
Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE;
/** Feature identifier: dynamic validation. */
@@ -160,8 +168,10 @@
// recognized features and properties
/** Recognized features. */
- protected static final String[] RECOGNIZED_FEATURES = {
+ protected static final String[] RECOGNIZED_FEATURES = {
VALIDATION,
+ NAMESPACES,
+ SCHEMA_VALIDATION,
DYNAMIC_VALIDATION,
};
@@ -176,8 +186,11 @@
//
// Data
//
-
+ protected boolean fSeenRoot = false;
// features
+ // REVISIT: what does it mean if namespaces is off
+ // while schema validation is on?
+ protected boolean fNamespaces = false;
/** Validation. */
protected boolean fValidation = false;
@@ -235,10 +248,6 @@
*/
public void setFeature(String featureId, boolean state)
throws XMLConfigurationException {
- if (featureId.equals(VALIDATION))
- fValidation = state;
- else if (featureId.equals(DYNAMIC_VALIDATION))
- fDynamicValidation = state;
} // setFeature(String,boolean)
/**
@@ -862,6 +871,36 @@
}
fSymbolTable = symbolTable;
+ // sax features
+ try {
+ fNamespaces = componentManager.getFeature(NAMESPACES);
+ }
+ catch (XMLConfigurationException e) {
+ fNamespaces = true;
+ }
+ try {
+ fValidation = componentManager.getFeature(VALIDATION);
+ }
+ catch (XMLConfigurationException e) {
+ fValidation = false;
+ }
+ try {
+ // REVISIT: should schema validation depend on validation?
+ // fValidation = fValidation && componentManager.getFeature(SCHEMA_VALIDATION);
+ fValidation = componentManager.getFeature(SCHEMA_VALIDATION);
+ }
+ catch (XMLConfigurationException e) {
+ fValidation = false;
+ }
+
+ // Xerces features
+ try {
+ fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION);
+ }
+ catch (XMLConfigurationException e) {
+ fDynamicValidation = false;
+ }
+
// get entity resolver. if there is no one, create a default
// REVISIT: use default entity resolution from ENTITY MANAGER - temporary solution
fEntityResolver = (XMLEntityResolver)componentManager.getProperty(ENTITY_MANAGER);
@@ -1023,39 +1062,21 @@
else
fPushForNextBinding = true;
- // whether to do validation
// root element
- // REVISIT: consider DynamicValidation
if (fElementDepth == -1) {
- fDoValidation = fValidation;
+ // at this point we assume that no XML schemas found in the instance document
+ // thus we will not validate in the case dynamic feature is on or we found dtd grammar
+ fDoValidation = fValidation && !(fValidationManager.isGrammarFound() || fDynamicValidation);
+
fValidationState = fValidationManager.getValidationState();
fValidationState.setNamespaceSupport(fNamespaceSupport);
fValidationState.setSymbolTable(fSymbolTable);
}
-
- // if we are in the content of "skip", then just skip this element
- // REVISIT: is this the correct behaviour for ID constraints? -NG
- if (fSkipValidationDepth >= 0) {
- fElementDepth++;
- return;
- }
-
- // if it's not the root element, we push the current states in the stacks
- if (fElementDepth != -1) {
- ensureStackCapacity();
- fChildCountStack[fElementDepth] = fChildCount+1;
- fChildCount = 0;
- fElemDeclStack[fElementDepth] = fCurrentElemDecl;
- fNilStack[fElementDepth] = fNil;
- fTypeStack[fElementDepth] = fCurrentType;
- fCMStack[fElementDepth] = fCurrentCM;
- fStringContent[fElementDepth] = fSawCharacters;
- }
-
// get xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes,
// parse them to get the grammars
// REVISIT: we'll defer this operation until there is a reference to
// a component from that namespace
+
String sLocation = attributes.getValue(URI_XSI, XSI_SCHEMALOCATION);
String nsLocation = attributes.getValue(URI_XSI, XSI_NONAMESPACESCHEMALOCATION);
if (sLocation != null) {
@@ -1076,6 +1097,36 @@
if (fGrammarResolver.getGrammar(null) == null)
fSchemaHandler.parseSchema(null, nsLocation);
}
+ // REVISIT: we should not rely on presence of
+ // schemaLocation or noNamespaceSchemaLocation
+ // attributes
+ if (sLocation !=null || nsLocation !=null) {
+ // if we found grammar we should attempt to validate
+ // based on values of validation & schema features
+ // only
+
+ fDoValidation = fValidation;
+ }
+ // if we are in the content of "skip", then just skip this element
+ // REVISIT: is this the correct behaviour for ID constraints? -NG
+ if (fSkipValidationDepth >= 0) {
+ fElementDepth++;
+ return;
+ }
+
+ // if it's not the root element, we push the current states in the stacks
+ if (fElementDepth != -1) {
+ ensureStackCapacity();
+ fChildCountStack[fElementDepth] = fChildCount+1;
+ fChildCount = 0;
+ fElemDeclStack[fElementDepth] = fCurrentElemDecl;
+ fNilStack[fElementDepth] = fNil;
+ fTypeStack[fElementDepth] = fCurrentType;
+ fCMStack[fElementDepth] = fCurrentCM;
+ fStringContent[fElementDepth] = fSawCharacters;
+ }
+
+
// get the element decl for this element
fCurrentElemDecl = null;
@@ -1205,7 +1256,7 @@
processAttributes(element, attributes, attrGrp);
// activate identity constraints
- if (fValidation ) {
+ if (fDoValidation ) {
fValueStoreCache.startElement();
fMatcherStack.pushContext();
if (fCurrentElemDecl != null) {
1.2 +11 -6 xml-xerces/java/src/org/apache/xerces/impl/validation/ValidationManager.java
Index: ValidationManager.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/validation/ValidationManager.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ValidationManager.java 2001/10/16 15:11:38 1.1
+++ ValidationManager.java 2001/10/25 00:44:33 1.2
@@ -73,26 +73,31 @@
// REVISIT: should validation/state be another property?
protected final ValidationState fValidationState= new ValidationState();
-
+ protected boolean fGrammarFound = false;
+
public ValidationState getValidationState (){
return fValidationState;
}
+ public void setGrammarFound(boolean grammar){
+ fGrammarFound = grammar;
+ }
+
+ public boolean isGrammarFound(){
+ return fGrammarFound;
+ }
+
// REVISIT: handle other validation coordination
// the following will depend on the final set of validation
// features
- //protected boolean fGrammarFound = false;
//protected XMLComponent fLastValidator = null;
-
- // public void setGrammarFound(){
-
- // public boolean isGrammarFound(){
// public boolean isLastValidationComponent( XMLComponent validator){
// public void setLastValidationComponent( XMLComponent validator){
public void reset (){
fValidationState.reset();
+ fGrammarFound = false;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org