Author: mrglavas
Date: Mon Nov  7 05:12:09 2011
New Revision: 1198624

URL: http://svn.apache.org/viewvc?rev=1198624&view=rev
Log:
Comments and PIs are expected to be present in the XDM tree for assertions. 
Make sure we pass them to the validator when schema version is 1.1. We can 
still bypass the validator when we're in XML Schema 1.0 mode.

Modified:
    
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/DOMValidatorHelper.java

Modified: 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/DOMValidatorHelper.java
URL: 
http://svn.apache.org/viewvc/xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/DOMValidatorHelper.java?rev=1198624&r1=1198623&r2=1198624&view=diff
==============================================================================
--- 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/DOMValidatorHelper.java
 (original)
+++ 
xerces/java/branches/xml-schema-1.1-dev/src/org/apache/xerces/jaxp/validation/DOMValidatorHelper.java
 Mon Nov  7 05:12:09 2011
@@ -96,6 +96,10 @@ final class DOMValidatorHelper implement
     private static final String VALIDATION_MANAGER =
         Constants.XERCES_PROPERTY_PREFIX + 
Constants.VALIDATION_MANAGER_PROPERTY;
     
+    /** Property identifier: xml schema version. */
+    private static final String XML_SCHEMA_VERSION =
+        Constants.XERCES_PROPERTY_PREFIX + 
Constants.XML_SCHEMA_VERSION_PROPERTY;
+    
     //
     // Data
     //
@@ -145,12 +149,15 @@ final class DOMValidatorHelper implement
     /** Current element. **/
     private Node fCurrentElement;
     
-    /** Fields for start element, end element and characters. **/
+    /** Fields for start element, end element, characters, comments and 
processing instructions. **/
     final QName fElementQName = new QName();
     final QName fAttributeQName = new QName();
     final XMLAttributesImpl fAttributes = new XMLAttributesImpl(); 
     final XMLString fTempString = new XMLString();
     
+    /** Flag indicating whether the schema version is 1.1. */
+    private final boolean fIsXSD11;
+    
     public DOMValidatorHelper(XMLSchemaValidatorComponentManager 
componentManager) {
         fComponentManager = componentManager;
         fErrorReporter = (XMLErrorReporter) 
fComponentManager.getProperty(ERROR_REPORTER);
@@ -158,6 +165,7 @@ final class DOMValidatorHelper implement
         fSchemaValidator = (XMLSchemaValidator) 
fComponentManager.getProperty(SCHEMA_VALIDATOR);
         fSymbolTable = (SymbolTable) 
fComponentManager.getProperty(SYMBOL_TABLE);        
         fValidationManager = (ValidationManager) 
fComponentManager.getProperty(VALIDATION_MANAGER);
+        fIsXSD11 = 
Constants.W3C_XML_SCHEMA11_NS_URI.equals(fComponentManager.getProperty(XML_SCHEMA_VERSION));
     }
     
     /*
@@ -302,19 +310,23 @@ final class DOMValidatorHelper implement
                 }
                 break;
             case Node.PROCESSING_INSTRUCTION_NODE:
-                /** 
-                 * The validator does nothing with processing instructions so 
bypass it.
-                 * Send the ProcessingInstruction node directly to the result 
builder.
-                 */
+                // The XSD 1.0 validator does nothing with processing 
instructions so bypass it unless it's 1.1.
+                if (fIsXSD11) {
+                    fillXMLString(fTempString, node.getNodeValue());
+                    fSchemaValidator.processingInstruction(node.getNodeName(), 
fTempString, null);
+                }
+                // Send the ProcessingInstruction node directly to the result 
builder.
                 if (fDOMValidatorHandler != null) {
                     
fDOMValidatorHandler.processingInstruction((ProcessingInstruction) node);
                 }
                 break;
             case Node.COMMENT_NODE:
-                /** 
-                 * The validator does nothing with comments so bypass it.
-                 * Send the Comment node directly to the result builder.
-                 */
+                // The XSD 1.0 validator does nothing with comments so bypass 
it unless it's 1.1.
+                if (fIsXSD11) {
+                    fillXMLString(fTempString, node.getNodeValue());
+                    fSchemaValidator.comment(fTempString, null);
+                }
+                // Send the Comment node directly to the result builder.
                 if (fDOMValidatorHandler != null) {
                     fDOMValidatorHandler.comment((Comment) node);
                 }
@@ -452,6 +464,19 @@ final class DOMValidatorHelper implement
         }
     }
     
+    private void fillXMLString(XMLString toFill, String str) {
+        final int length = str.length();
+        final char[] strArray;
+        if (length <= fCharBuffer.length) {
+            str.getChars(0, length, fCharBuffer, 0);
+            strArray = fCharBuffer;
+        }
+        else {
+            strArray = str.toCharArray();
+        }
+        toFill.setValues(strArray, 0, length);
+    }
+    
     /**
      * Use isSameNode() for testing node identity if the DOM implementation
      * supports DOM Level 3 core and it isn't the Xerces implementation.



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to