xerces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From el...@apache.org
Subject cvs commit: xml-xerces/java/src/org/apache/xerces/validators/common XMLValidator.java
Date Wed, 07 Feb 2001 20:41:42 GMT
elena       01/02/07 12:41:41

  Modified:    java/src/org/apache/xerces/validators/common
                        XMLValidator.java
  Log:
  More support for schema attibute & elements normalization (J5) - (DOM)
  
  Revision  Changes    Path
  1.113     +38 -8     xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java
  
  Index: XMLValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/validators/common/XMLValidator.java,v
  retrieving revision 1.112
  retrieving revision 1.113
  diff -u -r1.112 -r1.113
  --- XMLValidator.java	2001/02/06 22:23:41	1.112
  +++ XMLValidator.java	2001/02/07 20:41:39	1.113
  @@ -121,7 +121,7 @@
   /**
    * This class is the super all-in-one validator used by the parser.
    *
  - * @version $Id: XMLValidator.java,v 1.112 2001/02/06 22:23:41 elena Exp $
  + * @version $Id: XMLValidator.java,v 1.113 2001/02/07 20:41:39 elena Exp $
    */
   public final class XMLValidator
       implements DefaultEntityHandler.EventHandler,
  @@ -351,7 +351,8 @@
       private boolean fFirstChunk = true; // got first chunk in characters() (SAX)
       private boolean fTrailing = false;  // Previous chunk had a trailing space
       private boolean fCollapse = false;  //collapse spaces
  -    private StringBuffer fStringBuffer = new StringBuffer();  //temporary
  +    private StringBuffer fStringBuffer = null;  //holds normalized str value
  +    private StringBuffer fTempBuffer = null;  //holds unnormalized str value
       
   
   
  @@ -715,15 +716,19 @@
        *          3 if there is both leading and trailing whitespace.
        */
      
  -    private int normalizeWhitespace(char[] chars, int offset, int length, boolean collapse)
{
  +    private int normalizeWhitespace( StringBuffer chars, boolean collapse) {
  +        int length = fTempBuffer.length(); 
  +        if (fStringBuffer == null) {
  +            fStringBuffer = new StringBuffer((CHUNK_SIZE>=length)?CHUNK_SIZE:length);
  +        }
           fStringBuffer.setLength(0);
           boolean skipSpace = collapse;
           boolean sawNonWS = false;
           int leading = 0;
           int trailing = 0;
           int c;
  -        for (int i = offset; i < length; i++) {
  -            c = chars[i];
  +        for (int i = 0; i < length; i++) {
  +            c = chars.charAt(i);
               if (c == 0x20 || c == 0x0D || c == 0x0A || c == 0x09) {
                   if (!skipSpace) {
                       // take the first whitespace as a space and skip the others
  @@ -785,8 +790,13 @@
           if (fBufferDatatype) {
               if (DEBUG_NORMALIZATION) {
                   System.out.println("Start schema datatype normalization");
  +            }
  +            if (fTempBuffer == null) {
  +                fTempBuffer = new StringBuffer((CHUNK_SIZE>=length)?CHUNK_SIZE:length);
               }
  -            int spaces = normalizeWhitespace(chars, offset, length, fCollapse);
  +            fTempBuffer.setLength(0);
  +            fTempBuffer.append(chars, offset, length);
  +            int spaces = normalizeWhitespace(fTempBuffer, fCollapse);
               int nLength = fStringBuffer.length();
               if (nLength > 0) {
                   if (spaces != 0 && fCollapse) { //some normalization was done
  @@ -824,7 +834,7 @@
               charDataInContent();
            }
            if (fBufferDatatype) {
  -            fDatatypeBuffer.append(chars, offset, length);
  +             fDatatypeBuffer.append(chars, offset, length);
            }
         }
         fDocumentHandler.characters(chars, offset, length);
  @@ -837,7 +847,27 @@
               charDataInContent();
            }
            if (fBufferDatatype) {
  -            fDatatypeBuffer.append(fStringPool.toString(data));
  +
  +             if (NORMALIZATION_ON) {
  +                 fCollapse = true; //REVISIT: must be updated according to datatypes
  +                 String str =  fStringPool.toString(data);
  +                 int length = str.length();
  +                 if (fTempBuffer == null) {
  +                     fTempBuffer = new StringBuffer((CHUNK_SIZE>=length)?CHUNK_SIZE:length);
  +                 }
  +                 fTempBuffer.setLength(0);
  +                 fTempBuffer.append(str);
  +                 int spaces = normalizeWhitespace(fTempBuffer, fCollapse);
  +                 if (spaces >0) {
  +                     //normalization was done.
  +                     fStringPool.releaseString(data);
  +                     data = fStringPool.addString(fStringBuffer.toString());
  +                 }
  +                 fDatatypeBuffer.append(fStringBuffer.toString());
  +             }
  +             else {
  +                 fDatatypeBuffer.append(fStringPool.toString(data));
  +             }
            }
         }
         fDocumentHandler.characters(data);
  
  
  

Mime
View raw message