2
* The Apache Software License, Version 1.1
5
* Copyright (c) 1999-2004 The Apache Software Foundation.
8
* Redistribution and use in source and binary forms, with or without
9
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
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
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.
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.
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.
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
48
* ====================================================================
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.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
58
17
package org.apache.xerces.impl;
86
44
* <li>http://apache.org/xml/properties/internal/dtd-scanner</li>
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
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 $
96
56
public class XML11DocumentScannerImpl
97
57
extends XMLDocumentScannerImpl {
100
/** Array of 3 strings. */
101
private String[] fStrings = new String[3];
104
60
private XMLString fString = new XMLString();
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.
148
* @return true if the non-normalized and normalized value are the same
192
150
* <strong>Note:</strong> This method uses fStringBuffer2, anything in it
193
151
* at the time of calling is lost.
195
protected void scanAttributeValue(XMLString value,
153
protected boolean scanAttributeValue(XMLString value,
196
154
XMLString nonNormalizedValue,
198
156
boolean checkEntities,String eleName)
212
170
System.out.println("** scanLiteral -> \""
213
171
+ value.toString() + "\"");
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});
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() + "\"");
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] = ' ';
462
* Normalize whitespace in an XMLString converting all whitespace
463
* characters to space characters.
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) {
469
if (XMLChar.isSpace(c)) {
476
* Checks whether this string would be unchanged by normalization.
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.
482
protected int isUnchangedByNormalization(XMLString value) {
483
int end = value.offset + value.length;
484
for (int i = value.offset; i < end; ++i) {
486
if (XMLChar.isSpace(c)) {
487
return i - value.offset;
491
493
// returns true if the given character is not
492
494
// valid with respect to the version of