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/04 21:57:48 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/impl/v2/datatypes BooleanDatatypeValidator.java

elena       01/10/04 12:57:48

  Modified:    java/src/org/apache/xerces/impl/v2 SchemaValidator.java
                        XSParticleDecl.java
               java/src/org/apache/xerces/impl/v2/datatypes
                        BooleanDatatypeValidator.java
  Log:
  modify how we check for mixed content model (dont store fBuffer)
  
  Revision  Changes    Path
  1.19      +41 -24    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- SchemaValidator.java	2001/10/02 16:07:47	1.18
  +++ SchemaValidator.java	2001/10/04 19:57:48	1.19
  @@ -109,7 +109,7 @@
    * @author Andy Clark, IBM
    * @author Jeffrey Rodriguez IBM
    *
  - * @version $Id: SchemaValidator.java,v 1.18 2001/10/02 16:07:47 neilg Exp $
  + * @version $Id: SchemaValidator.java,v 1.19 2001/10/04 19:57:48 elena Exp $
    */
   public class SchemaValidator
       implements XMLComponent, XMLDocumentFilter {
  @@ -418,8 +418,21 @@
        * @throws XNIException Thrown by handler to signal an error.
        */
       public void characters(XMLString text) throws XNIException {
  +        if (fSkipValidationDepth >= 0)
  +            return;
  +        boolean allWhiteSpace = true;
  +        for (int i=text.offset; i< text.offset+text.length; i++) {
  +                if (!XMLChar.isSpace(text.ch[i])) {
  +                    allWhiteSpace = false;
  +                    break;
  +                }
  +        }
  +        
  +        fBuffer.append(text.toString()); 
  +        if (!allWhiteSpace) {
  +            fSawCharacters = true;
  +        }
   
  -        handleCharacters(text);
   
           // call handlers
           if (fDocumentHandler != null) {
  @@ -740,23 +753,25 @@
       int[][] fCMStateStack = new int[INITIAL_STACK_SIZE][];
   
       /** Temporary string buffers. */
  -    StringBuffer fBuffer;
  +    final StringBuffer fBuffer = new StringBuffer();
   
  -    /** stack to hold string for all nodes */
  -    StringBuffer[] fBufferStack = new StringBuffer[INITIAL_STACK_SIZE];
  +    /** Did we see non-whitespace character data? */
  +    boolean fSawCharacters = false;
   
  +    /** Stack to record if we saw character data outside of element content*/
  +    boolean[] fStringContent = new boolean[INITIAL_STACK_SIZE];
       /**
        * This table has to be own by instance of XMLValidator and shared
        * among ID, IDREF and IDREFS.
        * REVISIT: Should replace with a lighter structure.
        */
  -    Hashtable fTableOfIDs = new Hashtable();
  -    Hashtable fTableOfIDRefs = new Hashtable();
  +    final Hashtable fTableOfIDs = new Hashtable();
  +    final Hashtable fTableOfIDRefs = new Hashtable();
   
       /**
        * temprory qname
        */
  -    QName fTempQName = new QName();
  +    final QName fTempQName = new QName();
       /**
        * temprory empty object, used to fill IDREF table
        */
  @@ -823,7 +838,8 @@
           fCurrentType = null;
           fCurrentCM = null;
           fCurrCMState = null;
  -        fBuffer = null;
  +        fBuffer.setLength(0);
  +        fSawCharacters=false;
           fSkipValidationDepth = -1;
           fElementDepth = -1;
           fChildCount = 0;
  @@ -842,18 +858,23 @@
               int[] newArrayI = new int[newSize];
               System.arraycopy(fChildCountStack, 0, newArrayI, 0, newSize);
               fChildCountStack = newArrayI;
  +            
               XSElementDecl[] newArrayE = new XSElementDecl[newSize];
               System.arraycopy(fElemDeclStack, 0, newArrayE, 0, newSize);
               fElemDeclStack = newArrayE;
  +            
               XSTypeDecl[] newArrayT = new XSTypeDecl[newSize];
               System.arraycopy(fTypeStack, 0, newArrayT, 0, newSize);
               fTypeStack = newArrayT;
  +            
               XSCMValidator[] newArrayC = new XSCMValidator[newSize];
               System.arraycopy(fCMStack, 0, newArrayC, 0, newSize);
               fCMStack = newArrayC;
  -            StringBuffer[] newArrayB = new StringBuffer[newSize];
  -            System.arraycopy(fBufferStack, 0, newArrayB, 0, newSize);
  -            fBufferStack = newArrayB;
  +            
  +            boolean[] newArrayD = new boolean[newSize];
  +            System.arraycopy(fStringContent, 0, newArrayD, 0, newSize);
  +            fStringContent = newArrayD;
  +
               int[][] newArrayIA = new int[newSize][];
               System.arraycopy(fCMStateStack, 0, newArrayIA, 0, newSize);
               fCMStateStack = newArrayIA;
  @@ -903,7 +924,7 @@
               fNilStack[fElementDepth] = fNil;
               fTypeStack[fElementDepth] = fCurrentType;
               fCMStack[fElementDepth] = fCurrentCM;
  -            fBufferStack[fElementDepth] = fBuffer;
  +            fStringContent[fElementDepth] = fSawCharacters;
           }
   
           // get xsi:schemaLocation and xsi:noNamespaceSchemaLocation attributes,
  @@ -1045,7 +1066,8 @@
               fCurrCMState = fCurrentCM.startContentModel();
   
           // and the buffer to hold the value of the element
  -        fBuffer = new StringBuffer();
  +        fBuffer.setLength(0);
  +        fSawCharacters = false;
   
           // get information about xsi:nil
           String xsiNil = attributes.getValue(URI_XSI, XSI_NIL);
  @@ -1084,7 +1106,7 @@
                   fCurrentType = fTypeStack[fElementDepth];
                   fCurrentCM = fCMStack[fElementDepth];
                   fCurrCMState = fCMStateStack[fElementDepth];
  -                fBuffer = fBufferStack[fElementDepth];
  +                fSawCharacters = fStringContent[fElementDepth];
               } else {
                   fElementDepth--;
               }
  @@ -1120,16 +1142,11 @@
               fCurrentType = fTypeStack[fElementDepth];
               fCurrentCM = fCMStack[fElementDepth];
               fCurrCMState = fCMStateStack[fElementDepth];
  -            fBuffer = fBufferStack[fElementDepth];
  +            fSawCharacters = fStringContent[fElementDepth];
           }
  -
  +        
       } // handleEndElement(QName,boolean)*/
   
  -    void handleCharacters(XMLString text) {
  -        if (fSkipValidationDepth >= 0)
  -            return;
  -        fBuffer.append(text.toString());
  -    } // handleCharacters(XMLString)
   
       void handleStartPrefix(String prefix, String uri) {
           // push namespace context if necessary
  @@ -1547,9 +1564,9 @@
               // 2.3 If the {content type} is element-only, then the element information item has no character information item [children] other than those whose [character code] is defined as a white space in [XML 1.0 (Second Edition)].
               if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT) {
                   // REVISIT: how to check whether there is any text content?
  -                String content = XSAttributeChecker.normalize(textContent, SchemaSymbols.WS_COLLAPSE);
  -                if (content.length() != 0)
  +                if (fSawCharacters) {
                       reportSchemaError("cvc-complex-type.2.3", new Object[]{element.rawname});
  +                }
               }
               // 2.4 If the {content type} is element-only or mixed, then the sequence of the element information item's element information item [children], if any, taken in order, is �valid� with respect to the {content type}'s particle, as defined in Element Sequence Locally Valid (Particle) (�3.9.4).
               if (ctype.fContentType == XSComplexTypeDecl.CONTENTTYPE_ELEMENT ||
  
  
  
  1.12      +2 -1      xml-xerces/java/src/org/apache/xerces/impl/v2/XSParticleDecl.java
  
  Index: XSParticleDecl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/XSParticleDecl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- XSParticleDecl.java	2001/10/02 16:07:47	1.11
  +++ XSParticleDecl.java	2001/10/04 19:57:48	1.12
  @@ -62,7 +62,7 @@
    *
    * @author Sandy Gao, IBM
    *
  - * @version $Id: XSParticleDecl.java,v 1.11 2001/10/02 16:07:47 neilg Exp $
  + * @version $Id: XSParticleDecl.java,v 1.12 2001/10/04 19:57:48 elena Exp $
    */
   public class XSParticleDecl {
   
  @@ -99,6 +99,7 @@
           // build fBuffering
           fBuffer.setLength(0);
           appendParticle(fBuffer);
  +        fBuffer.append(" with minOccurs="+fMinOccurs +", maxOccurs="+fMaxOccurs);
           return fBuffer.toString();
       }
   
  
  
  
  1.3       +3 -2      xml-xerces/java/src/org/apache/xerces/impl/v2/datatypes/BooleanDatatypeValidator.java
  
  Index: BooleanDatatypeValidator.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/impl/v2/datatypes/BooleanDatatypeValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BooleanDatatypeValidator.java	2001/09/19 18:16:07	1.2
  +++ BooleanDatatypeValidator.java	2001/10/04 19:57:48	1.3
  @@ -69,7 +69,7 @@
    * @author Ted Leung
    * @author Jeffrey Rodriguez
    * @author Mark Swinkles - List Validation refactoring
  - * @version  $Id: BooleanDatatypeValidator.java,v 1.2 2001/09/19 18:16:07 neilg Exp $
  + * @version  $Id: BooleanDatatypeValidator.java,v 1.3 2001/10/04 19:57:48 elena Exp $
    */
   
   public class BooleanDatatypeValidator extends AbstractDatatypeValidator {
  @@ -168,7 +168,8 @@
       private void checkContent( String content, boolean asBase )
       throws InvalidDatatypeValueException {
           // validate against parent type if any
  -        if ( this.fBaseValidator != null ) {
  +        // REVISIT: fast fix to avoid class cast exception
  +        if ( this.fBaseValidator != null && !(fBaseValidator instanceof AnySimpleType)) {
               // validate content as a base type
                   ((BooleanDatatypeValidator)fBaseValidator).checkContent(content, true);
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org