~ubuntu-branches/ubuntu/karmic/libxerces2-java/karmic

« back to all changes in this revision

Viewing changes to src/org/apache/xerces/impl/XML11DocumentScannerImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-12-04 17:37:55 UTC
  • mfrom: (2.1.2 etch)
  • Revision ID: james.westby@ubuntu.com-20061204173755-hb6ybrrrk097zhx7
Tags: 2.8.1-1ubuntu1
* Merge with Debian unstable; remaining changes:
  - Build -gcj package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * The Apache Software License, Version 1.1
3
 
 *
4
 
 *
5
 
 * Copyright (c) 1999-2004 The Apache Software Foundation.
6
 
 * All rights reserved.
7
 
 *
8
 
 * Redistribution and use in source and binary forms, with or without
9
 
 * modification, are permitted provided that the following conditions
10
 
 * are met:
11
 
 *
12
 
 * 1. Redistributions of source code must retain the above copyright
13
 
 *    notice, this list of conditions and the following disclaimer.
14
 
 *
15
 
 * 2. Redistributions in binary form must reproduce the above copyright
16
 
 *    notice, this list of conditions and the following disclaimer in
17
 
 *    the documentation and/or other materials provided with the
18
 
 *    distribution.
19
 
 *
20
 
 * 3. The end-user documentation included with the redistribution,
21
 
 *    if any, must include the following acknowledgment:
22
 
 *       "This product includes software developed by the
23
 
 *        Apache Software Foundation (http://www.apache.org/)."
24
 
 *    Alternately, this acknowledgment may appear in the software itself,
25
 
 *    if and wherever such third-party acknowledgments normally appear.
26
 
 *
27
 
 * 4. The names "Xerces" and "Apache Software Foundation" must
28
 
 *    not be used to endorse or promote products derived from this
29
 
 *    software without prior written permission. For written
30
 
 *    permission, please contact apache@apache.org.
31
 
 *
32
 
 * 5. Products derived from this software may not be called "Apache",
33
 
 *    nor may "Apache" appear in their name, without prior written
34
 
 *    permission of the Apache Software Foundation.
35
 
 *
36
 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37
 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38
 
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
 
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40
 
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43
 
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44
 
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45
 
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46
 
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47
 
 * SUCH DAMAGE.
48
 
 * ====================================================================
49
 
 *
50
 
 * This software consists of voluntary contributions made by many
51
 
 * individuals on behalf of the Apache Software Foundation and was
52
 
 * originally based on software copyright (c) 1999, International
53
 
 * Business Machines, Inc., http://www.apache.org.  For more
54
 
 * information on the Apache Software Foundation, please see
55
 
 * <http://www.apache.org/>.
 
2
 * Copyright 1999-2005 The Apache Software Foundation.
 
3
 * 
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 * 
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 * 
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
56
15
 */
57
16
 
58
17
package org.apache.xerces.impl;
63
22
import org.apache.xerces.util.XML11Char;
64
23
import org.apache.xerces.util.XMLChar;
65
24
import org.apache.xerces.util.XMLStringBuffer;
66
 
import org.apache.xerces.xni.XMLAttributes;
67
25
import org.apache.xerces.xni.XMLString;
68
26
import org.apache.xerces.xni.XNIException;
69
27
 
86
44
 *  <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
87
45
 * </ul>
88
46
 *
 
47
 * @xerces.internal
 
48
 *
89
49
 * @author Glenn Marcy, IBM
90
50
 * @author Andy Clark, IBM
91
51
 * @author Arnaud  Le Hors, IBM
92
52
 * @author Eric Ye, IBM
93
53
 *
94
 
 * @version $Id: XML11DocumentScannerImpl.java,v 1.17 2004/02/11 18:55:20 mrglavas Exp $
 
54
 * @version $Id: XML11DocumentScannerImpl.java 354533 2005-12-06 20:12:10Z mrglavas $
95
55
 */
96
56
public class XML11DocumentScannerImpl
97
57
    extends XMLDocumentScannerImpl {
98
58
 
99
 
 
100
 
    /** Array of 3 strings. */
101
 
    private String[] fStrings = new String[3];
102
 
 
103
59
    /** String. */
104
60
    private XMLString fString = new XMLString();
105
61
 
189
145
     *                      false if undeclared entities should be reported as WFC violation.
190
146
     * @param eleName The name of element to which this attribute belongs.
191
147
     *
 
148
     * @return true if the non-normalized and normalized value are the same
 
149
     * 
192
150
     * <strong>Note:</strong> This method uses fStringBuffer2, anything in it
193
151
     * at the time of calling is lost.
194
152
     **/
195
 
    protected void scanAttributeValue(XMLString value, 
 
153
    protected boolean scanAttributeValue(XMLString value, 
196
154
                                      XMLString nonNormalizedValue,
197
155
                                      String atName,
198
156
                                      boolean checkEntities,String eleName)
212
170
            System.out.println("** scanLiteral -> \""
213
171
                               + value.toString() + "\"");
214
172
        }
 
173
        
 
174
        int fromIndex = 0;
 
175
        if (c == quote && (fromIndex = isUnchangedByNormalization(value)) == -1) {
 
176
            /** Both the non-normalized and normalized attribute values are equal. **/
 
177
            nonNormalizedValue.setValues(value);
 
178
            int cquote = fEntityScanner.scanChar();
 
179
            if (cquote != quote) {
 
180
                reportFatalError("CloseQuoteExpected", new Object[]{eleName,atName});
 
181
            }
 
182
            return true;
 
183
        }
215
184
        fStringBuffer2.clear();
216
185
        fStringBuffer2.append(value);
217
 
        normalizeWhitespace(value);
 
186
        normalizeWhitespace(value, fromIndex);
218
187
        if (DEBUG_ATTR_NORMALIZATION) {
219
188
            System.out.println("** normalizeWhitespace -> \""
220
189
                               + value.toString() + "\"");
370
339
                        }
371
340
                    }
372
341
                }
373
 
                else if (c != -1 && XML11Char.isXML11Invalid(c)) {
 
342
                else if (c != -1 && isInvalidLiteral(c)) {
374
343
                    reportFatalError("InvalidCharInAttValue",
375
344
                                     new Object[] {eleName, atName, Integer.toString(c, 16)});
376
345
                    fEntityScanner.scanChar();
399
368
        if (cquote != quote) {
400
369
            reportFatalError("CloseQuoteExpected", new Object[]{eleName,atName});
401
370
        }
 
371
        return nonNormalizedValue.equals(value.ch, value.offset, value.length);
402
372
    } // scanAttributeValue()
403
373
 
404
374
    //
480
450
     */
481
451
    protected void normalizeWhitespace(XMLString value) {
482
452
        int end = value.offset + value.length;
483
 
            for (int i = value.offset; i < end; i++) {
 
453
            for (int i = value.offset; i < end; ++i) {
484
454
           int c = value.ch[i];
485
455
           if (XMLChar.isSpace(c)) {
486
456
               value.ch[i] = ' ';
487
457
           }
488
458
       }
489
459
    }
 
460
    
 
461
    /**
 
462
     * Normalize whitespace in an XMLString converting all whitespace
 
463
     * characters to space characters.
 
464
     */
 
465
    protected void normalizeWhitespace(XMLString value, int fromIndex) {
 
466
        int end = value.offset + value.length;
 
467
        for (int i = value.offset + fromIndex; i < end; ++i) {
 
468
            int c = value.ch[i];
 
469
            if (XMLChar.isSpace(c)) {
 
470
                value.ch[i] = ' ';
 
471
            }
 
472
        }
 
473
    }
 
474
    
 
475
    /**
 
476
     * Checks whether this string would be unchanged by normalization.
 
477
     * 
 
478
     * @return -1 if the value would be unchanged by normalization,
 
479
     * otherwise the index of the first whitespace character which
 
480
     * would be transformed.
 
481
     */
 
482
    protected int isUnchangedByNormalization(XMLString value) {
 
483
        int end = value.offset + value.length;
 
484
        for (int i = value.offset; i < end; ++i) {
 
485
            int c = value.ch[i];
 
486
            if (XMLChar.isSpace(c)) {
 
487
                return i - value.offset;
 
488
            }
 
489
        }
 
490
        return -1;
 
491
    }
490
492
 
491
493
    // returns true if the given character is not
492
494
    // valid with respect to the version of