Author: mrglavas
Date: Tue Oct 31 09:57:34 2006
New Revision: 469584

URL: http://svn.apache.org/viewvc?view=rev&rev=469584
Log:
String.trim() removes all leading and trailing characters less
than or equal to U+0020. This is okay for XML 1.0 since all
of the valid characters in that range are white space but
in XML 1.1 control chars are allowed. When the input to the
schema loader or schema validator is an XML 1.1 document we
need to be careful that we're not treating the control 
characters as XML spaces.

Modified:
    xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
    xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Selector.java
    
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
    
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java
    
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
    xerces/java/trunk/src/org/apache/xerces/util/XMLChar.java

Modified: 
xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java?view=diff&rev=469584&r1=469583&r2=469584
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/dv/xs/XSSimpleTypeDecl.java 
Tue Oct 31 09:57:34 2006
@@ -1989,7 +1989,7 @@
                                return content.toString();
                        }
                        else if (norm_type == NORMALIZE_TRIM) {
-                               return content.toString().trim();
+                               return XMLChar.trim(content.toString());
                        }
                }
                

Modified: 
xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java?view=diff&rev=469584&r1=469583&r2=469584
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/XMLSchemaValidator.java Tue 
Oct 31 09:57:34 2006
@@ -2659,7 +2659,7 @@
         // 3.2 If {nillable} is true and there is such an attribute 
information item and its actual value is true , then all of the following must 
be true:
         // 3.2.2 There must be no fixed {value constraint}.
         else {
-            String value = xsiNil.trim();
+            String value = XMLChar.trim(xsiNil);
             if (value.equals(SchemaSymbols.ATTVAL_TRUE)
                 || value.equals(SchemaSymbols.ATTVAL_TRUE_1)) {
                 if (fCurrentElemDecl != null

Modified: xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Selector.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Selector.java?view=diff&rev=469584&r1=469583&r2=469584
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Selector.java 
(original)
+++ xerces/java/trunk/src/org/apache/xerces/impl/xs/identity/Selector.java Tue 
Oct 31 09:57:34 2006
@@ -19,6 +19,7 @@
 
 import org.apache.xerces.impl.xpath.XPathException;
 import org.apache.xerces.util.SymbolTable;
+import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.NamespaceContext;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xni.XMLAttributes;
@@ -137,7 +138,7 @@
             StringBuffer modifiedXPath = new StringBuffer(xpath.length()+5);
             int unionIndex = -1;
             do {
-                if(!(xpath.trim().startsWith("/") 
||xpath.trim().startsWith("."))) {
+                if(!(XMLChar.trim(xpath).startsWith("/") || 
XMLChar.trim(xpath).startsWith("."))) {
                     modifiedXPath.append("./"); 
                 }
                 unionIndex = xpath.indexOf('|');

Modified: 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java?view=diff&rev=469584&r1=469583&r2=469584
==============================================================================
--- 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
 (original)
+++ 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSAttributeChecker.java
 Tue Oct 31 09:57:34 2006
@@ -34,6 +34,7 @@
 import org.apache.xerces.impl.xs.util.XIntPool;
 import org.apache.xerces.util.DOMUtil;
 import org.apache.xerces.util.SymbolTable;
+import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.util.XMLSymbols;
 import org.apache.xerces.xni.QName;
 import org.apache.xerces.xs.XSConstants;
@@ -1188,14 +1189,8 @@
         // strings. We only need to remove the whitespace from both ends.
         // In some special cases (list types), StringTokenizer can correctly
         // process the un-normalized whitespace.        
-        /**
-         * REVISIT: Trim removes all leading and trailing characters less
-         * than or equal to U+0020. This is okay for XML 1.0 since all
-         * of the valid characters in that range are white space but
-         * in XML 1.1 control chars are allowed. We shouldn't be trimming
-         * those. -- mrglavas
-         */
-        String value = ivalue.trim();
+
+        String value = XMLChar.trim(ivalue);
         Object retValue = null;
         Vector memberType;
         int choice;

Modified: 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java?view=diff&rev=469584&r1=469583&r2=469584
==============================================================================
--- 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java
 (original)
+++ 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDAbstractIDConstraintTraverser.java
 Tue Oct 31 09:57:34 2006
@@ -23,6 +23,7 @@
 import org.apache.xerces.impl.xs.identity.IdentityConstraint;
 import org.apache.xerces.impl.xs.identity.Selector;
 import org.apache.xerces.util.DOMUtil;
+import org.apache.xerces.util.XMLChar;
 import org.w3c.dom.Element;
 
 /**
@@ -107,7 +108,7 @@
             reportSchemaError("s4s-att-must-appear", new Object [] 
{SchemaSymbols.ELT_SELECTOR, SchemaSymbols.ATT_XPATH}, sElem);
             return;
         }
-        sText = sText.trim();
+        sText = XMLChar.trim(sText);
         
         Selector.XPath sXpath = null;
         try {

Modified: 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java?view=diff&rev=469584&r1=469583&r2=469584
==============================================================================
--- 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
 (original)
+++ 
xerces/java/trunk/src/org/apache/xerces/impl/xs/traversers/XSDElementTraverser.java
 Tue Oct 31 09:57:34 2006
@@ -34,6 +34,7 @@
 import org.apache.xerces.impl.xs.util.XSObjectListImpl;
 import org.apache.xerces.util.DOMUtil;
 import org.apache.xerces.util.SymbolTable;
+import org.apache.xerces.util.XMLChar;
 import org.apache.xerces.xni.QName;
 import org.w3c.dom.Element;
 import org.w3c.dom.Attr;
@@ -103,7 +104,7 @@
         } else {
             particle = new XSParticleDecl();
         }
-        if(fDeferTraversingLocalElements) {
+        if (fDeferTraversingLocalElements) {
             // The only thing we care about now is whether this element has
             // minOccurs=0. This affects (if the element appears in a complex
             // type) whether a type has emptiable content.
@@ -112,7 +113,7 @@
             if (attr != null) {
                 String min = attr.getValue();
                 try {
-                    int m = Integer.parseInt(min.trim());
+                    int m = Integer.parseInt(XMLChar.trim(min));
                     if (m >= 0)
                         particle.fMinOccurs = m;
                 }

Modified: xerces/java/trunk/src/org/apache/xerces/util/XMLChar.java
URL: 
http://svn.apache.org/viewvc/xerces/java/trunk/src/org/apache/xerces/util/XMLChar.java?view=diff&rev=469584&r1=469583&r2=469584
==============================================================================
--- xerces/java/trunk/src/org/apache/xerces/util/XMLChar.java (original)
+++ xerces/java/trunk/src/org/apache/xerces/util/XMLChar.java Tue Oct 31 
09:57:34 2006
@@ -1018,6 +1018,38 @@
         }
         return false;
     } // isValidIANAEncoding(String):boolean
-
+    
+    // other methods
+    
+    /**
+     * Trims space characters as defined by production [3] in 
+     * the XML 1.0 specification from both ends of the given string.
+     * 
+     * @param value the string to be trimmed
+     * @return the given string with the space characters trimmed
+     * from both ends
+     */
+    public static String trim(String value) {
+        int start;
+        int end;
+        final int lengthMinusOne = value.length() - 1;
+        for (start = 0; start <= lengthMinusOne; ++start) {
+            if (!isSpace(value.charAt(start))) {
+                break;
+            }
+        }
+        for (end = lengthMinusOne; end >= start; --end) {
+            if (!isSpace(value.charAt(end))) {
+                break;
+            }
+        }
+        if (start == 0 && end == lengthMinusOne) {
+            return value;
+        }
+        if (start > lengthMinusOne) {
+            return "";
+        }
+        return value.substring(start, end + 1);
+    } // trim(String):String
 
 } // class XMLChar



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to