KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > impl > XML11EntityScanner


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 1999-2002 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/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.impl;
59
60 import java.io.IOException JavaDoc;
61
62 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
63 import com.sun.org.apache.xerces.internal.util.XMLChar;
64 import com.sun.org.apache.xerces.internal.util.XML11Char;
65 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
66 import com.sun.org.apache.xerces.internal.xni.QName;
67 import com.sun.org.apache.xerces.internal.xni.XMLString;
68
69 /**
70  * Implements the entity scanner methods in
71  * the context of XML 1.1.
72  *
73  * @author Michael Glavassevich, IBM
74  * @author Neil Graham, IBM
75  * @version $Id: XML11EntityScanner.java,v 1.11 2003/12/19 03:36:44 mrglavas Exp $
76  */

77
78 public class XML11EntityScanner
79     extends XMLEntityScanner {
80
81     //
82
// Constructors
83
//
84

85     /** Default constructor. */
86     public XML11EntityScanner() {
87         super();
88     } // <init>()
89

90     //
91
// XMLEntityScanner methods
92
//
93

94     /**
95      * Returns the next character on the input.
96      * <p>
97      * <strong>Note:</strong> The character is <em>not</em> consumed.
98      *
99      * @throws IOException Thrown if i/o error occurs.
100      * @throws EOFException Thrown on end of file.
101      */

102     public int peekChar() throws IOException JavaDoc {
103
104         // load more characters, if needed
105
if (fCurrentEntity.position == fCurrentEntity.count) {
106             load(0, true);
107         }
108
109         // peek at character
110
int c = fCurrentEntity.ch[fCurrentEntity.position];
111
112         // return peeked character
113
if (fCurrentEntity.isExternal()) {
114             return (c != '\r' && c != 0x85 && c != 0x2028) ? c : '\n';
115         }
116         else {
117             return c;
118         }
119
120     } // peekChar():int
121

122     /**
123      * Returns the next character on the input.
124      * <p>
125      * <strong>Note:</strong> The character is consumed.
126      *
127      * @throws IOException Thrown if i/o error occurs.
128      * @throws EOFException Thrown on end of file.
129      */

130     public int scanChar() throws IOException JavaDoc {
131
132         // load more characters, if needed
133
if (fCurrentEntity.position == fCurrentEntity.count) {
134             load(0, true);
135         }
136
137         // scan character
138
int c = fCurrentEntity.ch[fCurrentEntity.position++];
139         boolean external = false;
140         if (c == '\n' ||
141             ((c == '\r' || c == 0x85 || c == 0x2028) && (external = fCurrentEntity.isExternal()))) {
142             fCurrentEntity.lineNumber++;
143             fCurrentEntity.columnNumber = 1;
144             if (fCurrentEntity.position == fCurrentEntity.count) {
145                 fCurrentEntity.ch[0] = (char)c;
146                 load(1, false);
147             }
148             if (c == '\r' && external) {
149                 int cc = fCurrentEntity.ch[fCurrentEntity.position++];
150                 if (cc != '\n' && cc != 0x85) {
151                     fCurrentEntity.position--;
152                 }
153             }
154             c = '\n';
155         }
156
157         // return character that was scanned
158
fCurrentEntity.columnNumber++;
159         return c;
160
161     } // scanChar():int
162

163     /**
164      * Returns a string matching the NMTOKEN production appearing immediately
165      * on the input as a symbol, or null if NMTOKEN Name string is present.
166      * <p>
167      * <strong>Note:</strong> The NMTOKEN characters are consumed.
168      * <p>
169      * <strong>Note:</strong> The string returned must be a symbol. The
170      * SymbolTable can be used for this purpose.
171      *
172      * @throws IOException Thrown if i/o error occurs.
173      * @throws EOFException Thrown on end of file.
174      *
175      * @see com.sun.org.apache.xerces.internal.util.SymbolTable
176      * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
177      */

178     public String JavaDoc scanNmtoken() throws IOException JavaDoc {
179         // load more characters, if needed
180
if (fCurrentEntity.position == fCurrentEntity.count) {
181             load(0, true);
182         }
183
184         // scan nmtoken
185
int offset = fCurrentEntity.position;
186         
187         do {
188             char ch = fCurrentEntity.ch[fCurrentEntity.position];
189             if (XML11Char.isXML11Name(ch)) {
190                 if (++fCurrentEntity.position == fCurrentEntity.count) {
191                     int length = fCurrentEntity.position - offset;
192                     if (length == fCurrentEntity.ch.length) {
193                         // bad luck we have to resize our buffer
194
char[] tmp = new char[fCurrentEntity.ch.length << 1];
195                         System.arraycopy(fCurrentEntity.ch, offset,
196                                          tmp, 0, length);
197                         fCurrentEntity.ch = tmp;
198                     }
199                     else {
200                         System.arraycopy(fCurrentEntity.ch, offset,
201                                          fCurrentEntity.ch, 0, length);
202                     }
203                     offset = 0;
204                     if (load(length, false)) {
205                         break;
206                     }
207                 }
208             }
209             else if (XML11Char.isXML11NameHighSurrogate(ch)) {
210                 if (++fCurrentEntity.position == fCurrentEntity.count) {
211                     int length = fCurrentEntity.position - offset;
212                     if (length == fCurrentEntity.ch.length) {
213                         // bad luck we have to resize our buffer
214
char[] tmp = new char[fCurrentEntity.ch.length << 1];
215                         System.arraycopy(fCurrentEntity.ch, offset,
216                                          tmp, 0, length);
217                         fCurrentEntity.ch = tmp;
218                     }
219                     else {
220                         System.arraycopy(fCurrentEntity.ch, offset,
221                                          fCurrentEntity.ch, 0, length);
222                     }
223                     offset = 0;
224                     if (load(length, false)) {
225                         --fCurrentEntity.position;
226                         break;
227                     }
228                 }
229                 char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
230                 if ( !XMLChar.isLowSurrogate(ch2) ||
231                      !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) {
232                     --fCurrentEntity.position;
233                     break;
234                 }
235                 if (++fCurrentEntity.position == fCurrentEntity.count) {
236                     int length = fCurrentEntity.position - offset;
237                     if (length == fCurrentEntity.ch.length) {
238                         // bad luck we have to resize our buffer
239
char[] tmp = new char[fCurrentEntity.ch.length << 1];
240                         System.arraycopy(fCurrentEntity.ch, offset,
241                                          tmp, 0, length);
242                         fCurrentEntity.ch = tmp;
243                     }
244                     else {
245                         System.arraycopy(fCurrentEntity.ch, offset,
246                                          fCurrentEntity.ch, 0, length);
247                     }
248                     offset = 0;
249                     if (load(length, false)) {
250                         break;
251                     }
252                 }
253             }
254             else {
255                 break;
256             }
257         }
258         while (true);
259         
260         int length = fCurrentEntity.position - offset;
261         fCurrentEntity.columnNumber += length;
262
263         // return nmtoken
264
String JavaDoc symbol = null;
265         if (length > 0) {
266             symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
267         }
268         return symbol;
269
270     } // scanNmtoken():String
271

272     /**
273      * Returns a string matching the Name production appearing immediately
274      * on the input as a symbol, or null if no Name string is present.
275      * <p>
276      * <strong>Note:</strong> The Name characters are consumed.
277      * <p>
278      * <strong>Note:</strong> The string returned must be a symbol. The
279      * SymbolTable can be used for this purpose.
280      *
281      * @throws IOException Thrown if i/o error occurs.
282      * @throws EOFException Thrown on end of file.
283      *
284      * @see com.sun.org.apache.xerces.internal.util.SymbolTable
285      * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
286      * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NameStart
287      */

288     public String JavaDoc scanName() throws IOException JavaDoc {
289         // load more characters, if needed
290
if (fCurrentEntity.position == fCurrentEntity.count) {
291             load(0, true);
292         }
293
294         // scan name
295
int offset = fCurrentEntity.position;
296         char ch = fCurrentEntity.ch[offset];
297         
298         if (XML11Char.isXML11NameStart(ch)) {
299             if (++fCurrentEntity.position == fCurrentEntity.count) {
300                 fCurrentEntity.ch[0] = ch;
301                 offset = 0;
302                 if (load(1, false)) {
303                     fCurrentEntity.columnNumber++;
304                     String JavaDoc symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
305                     return symbol;
306                 }
307             }
308         }
309         else if (XML11Char.isXML11NameHighSurrogate(ch)) {
310             if (++fCurrentEntity.position == fCurrentEntity.count) {
311                 fCurrentEntity.ch[0] = ch;
312                 offset = 0;
313                 if (load(1, false)) {
314                     --fCurrentEntity.position;
315                     return null;
316                 }
317             }
318             char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
319             if ( !XMLChar.isLowSurrogate(ch2) ||
320                  !XML11Char.isXML11NameStart(XMLChar.supplemental(ch, ch2)) ) {
321                 --fCurrentEntity.position;
322                 return null;
323             }
324             if (++fCurrentEntity.position == fCurrentEntity.count) {
325                 fCurrentEntity.ch[0] = ch;
326                 fCurrentEntity.ch[1] = ch2;
327                 offset = 0;
328                 if (load(2, false)) {
329                     fCurrentEntity.columnNumber += 2;
330                     String JavaDoc symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);
331                     return symbol;
332                 }
333             }
334         }
335         else {
336             return null;
337         }
338         
339         do {
340             ch = fCurrentEntity.ch[fCurrentEntity.position];
341             if (XML11Char.isXML11Name(ch)) {
342                 if (++fCurrentEntity.position == fCurrentEntity.count) {
343                     int length = fCurrentEntity.position - offset;
344                     if (length == fCurrentEntity.ch.length) {
345                         // bad luck we have to resize our buffer
346
char[] tmp = new char[fCurrentEntity.ch.length << 1];
347                         System.arraycopy(fCurrentEntity.ch, offset,
348                                          tmp, 0, length);
349                         fCurrentEntity.ch = tmp;
350                     }
351                     else {
352                         System.arraycopy(fCurrentEntity.ch, offset,
353                                          fCurrentEntity.ch, 0, length);
354                     }
355                     offset = 0;
356                     if (load(length, false)) {
357                         break;
358                     }
359                 }
360             }
361             else if (XML11Char.isXML11NameHighSurrogate(ch)) {
362                 if (++fCurrentEntity.position == fCurrentEntity.count) {
363                     int length = fCurrentEntity.position - offset;
364                     if (length == fCurrentEntity.ch.length) {
365                         // bad luck we have to resize our buffer
366
char[] tmp = new char[fCurrentEntity.ch.length << 1];
367                         System.arraycopy(fCurrentEntity.ch, offset,
368                                          tmp, 0, length);
369                         fCurrentEntity.ch = tmp;
370                     }
371                     else {
372                         System.arraycopy(fCurrentEntity.ch, offset,
373                                          fCurrentEntity.ch, 0, length);
374                     }
375                     offset = 0;
376                     if (load(length, false)) {
377                         --fCurrentEntity.position;
378                         break;
379                     }
380                 }
381                 char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
382                 if ( !XMLChar.isLowSurrogate(ch2) ||
383                      !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) {
384                     --fCurrentEntity.position;
385                     break;
386                 }
387                 if (++fCurrentEntity.position == fCurrentEntity.count) {
388                     int length = fCurrentEntity.position - offset;
389                     if (length == fCurrentEntity.ch.length) {
390                         // bad luck we have to resize our buffer
391
char[] tmp = new char[fCurrentEntity.ch.length << 1];
392                         System.arraycopy(fCurrentEntity.ch, offset,
393                                          tmp, 0, length);
394                         fCurrentEntity.ch = tmp;
395                     }
396                     else {
397                         System.arraycopy(fCurrentEntity.ch, offset,
398                                          fCurrentEntity.ch, 0, length);
399                     }
400                     offset = 0;
401                     if (load(length, false)) {
402                         break;
403                     }
404                 }
405             }
406             else {
407                 break;
408             }
409         }
410         while (true);
411
412         int length = fCurrentEntity.position - offset;
413         fCurrentEntity.columnNumber += length;
414
415         // return name
416
String JavaDoc symbol = null;
417         if (length > 0) {
418             symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
419         }
420         return symbol;
421
422     } // scanName():String
423

424     /**
425      * Returns a string matching the NCName production appearing immediately
426      * on the input as a symbol, or null if no NCName string is present.
427      * <p>
428      * <strong>Note:</strong> The NCName characters are consumed.
429      * <p>
430      * <strong>Note:</strong> The string returned must be a symbol. The
431      * SymbolTable can be used for this purpose.
432      *
433      * @throws IOException Thrown if i/o error occurs.
434      * @throws EOFException Thrown on end of file.
435      *
436      * @see com.sun.org.apache.xerces.internal.util.SymbolTable
437      * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NCName
438      * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NCNameStart
439      */

440     public String JavaDoc scanNCName() throws IOException JavaDoc {
441
442         // load more characters, if needed
443
if (fCurrentEntity.position == fCurrentEntity.count) {
444             load(0, true);
445         }
446
447         // scan name
448
int offset = fCurrentEntity.position;
449         char ch = fCurrentEntity.ch[offset];
450         
451         if (XML11Char.isXML11NCNameStart(ch)) {
452             if (++fCurrentEntity.position == fCurrentEntity.count) {
453                 fCurrentEntity.ch[0] = ch;
454                 offset = 0;
455                 if (load(1, false)) {
456                     fCurrentEntity.columnNumber++;
457                     String JavaDoc symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
458                     return symbol;
459                 }
460             }
461         }
462         else if (XML11Char.isXML11NameHighSurrogate(ch)) {
463             if (++fCurrentEntity.position == fCurrentEntity.count) {
464                 fCurrentEntity.ch[0] = ch;
465                 offset = 0;
466                 if (load(1, false)) {
467                     --fCurrentEntity.position;
468                     return null;
469                 }
470             }
471             char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
472             if ( !XMLChar.isLowSurrogate(ch2) ||
473                  !XML11Char.isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) {
474                 --fCurrentEntity.position;
475                 return null;
476             }
477             if (++fCurrentEntity.position == fCurrentEntity.count) {
478                 fCurrentEntity.ch[0] = ch;
479                 fCurrentEntity.ch[1] = ch2;
480                 offset = 0;
481                 if (load(2, false)) {
482                     fCurrentEntity.columnNumber += 2;
483                     String JavaDoc symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);
484                     return symbol;
485                 }
486             }
487         }
488         else {
489             return null;
490         }
491         
492         do {
493             ch = fCurrentEntity.ch[fCurrentEntity.position];
494             if (XML11Char.isXML11NCName(ch)) {
495                 if (++fCurrentEntity.position == fCurrentEntity.count) {
496                     int length = fCurrentEntity.position - offset;
497                     if (length == fCurrentEntity.ch.length) {
498                         // bad luck we have to resize our buffer
499
char[] tmp = new char[fCurrentEntity.ch.length << 1];
500                         System.arraycopy(fCurrentEntity.ch, offset,
501                                          tmp, 0, length);
502                         fCurrentEntity.ch = tmp;
503                     }
504                     else {
505                         System.arraycopy(fCurrentEntity.ch, offset,
506                                          fCurrentEntity.ch, 0, length);
507                     }
508                     offset = 0;
509                     if (load(length, false)) {
510                         break;
511                     }
512                 }
513             }
514             else if (XML11Char.isXML11NameHighSurrogate(ch)) {
515                 if (++fCurrentEntity.position == fCurrentEntity.count) {
516                     int length = fCurrentEntity.position - offset;
517                     if (length == fCurrentEntity.ch.length) {
518                         // bad luck we have to resize our buffer
519
char[] tmp = new char[fCurrentEntity.ch.length << 1];
520                         System.arraycopy(fCurrentEntity.ch, offset,
521                                          tmp, 0, length);
522                         fCurrentEntity.ch = tmp;
523                     }
524                     else {
525                         System.arraycopy(fCurrentEntity.ch, offset,
526                                          fCurrentEntity.ch, 0, length);
527                     }
528                     offset = 0;
529                     if (load(length, false)) {
530                         --fCurrentEntity.position;
531                         break;
532                     }
533                 }
534                 char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
535                 if ( !XMLChar.isLowSurrogate(ch2) ||
536                      !XML11Char.isXML11NCName(XMLChar.supplemental(ch, ch2)) ) {
537                     --fCurrentEntity.position;
538                     break;
539                 }
540                 if (++fCurrentEntity.position == fCurrentEntity.count) {
541                     int length = fCurrentEntity.position - offset;
542                     if (length == fCurrentEntity.ch.length) {
543                         // bad luck we have to resize our buffer
544
char[] tmp = new char[fCurrentEntity.ch.length << 1];
545                         System.arraycopy(fCurrentEntity.ch, offset,
546                                          tmp, 0, length);
547                         fCurrentEntity.ch = tmp;
548                     }
549                     else {
550                         System.arraycopy(fCurrentEntity.ch, offset,
551                                          fCurrentEntity.ch, 0, length);
552                     }
553                     offset = 0;
554                     if (load(length, false)) {
555                         break;
556                     }
557                 }
558             }
559             else {
560                 break;
561             }
562         }
563         while (true);
564         
565         int length = fCurrentEntity.position - offset;
566         fCurrentEntity.columnNumber += length;
567
568         // return name
569
String JavaDoc symbol = null;
570         if (length > 0) {
571             symbol = fSymbolTable.addSymbol(fCurrentEntity.ch, offset, length);
572         }
573         return symbol;
574
575     } // scanNCName():String
576

577     /**
578      * Scans a qualified name from the input, setting the fields of the
579      * QName structure appropriately.
580      * <p>
581      * <strong>Note:</strong> The qualified name characters are consumed.
582      * <p>
583      * <strong>Note:</strong> The strings used to set the values of the
584      * QName structure must be symbols. The SymbolTable can be used for
585      * this purpose.
586      *
587      * @param qname The qualified name structure to fill.
588      *
589      * @return Returns true if a qualified name appeared immediately on
590      * the input and was scanned, false otherwise.
591      *
592      * @throws IOException Thrown if i/o error occurs.
593      * @throws EOFException Thrown on end of file.
594      *
595      * @see com.sun.org.apache.xerces.internal.util.SymbolTable
596      * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Name
597      * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11NameStart
598      */

599     public boolean scanQName(QName qname) throws IOException JavaDoc {
600
601         // load more characters, if needed
602
if (fCurrentEntity.position == fCurrentEntity.count) {
603             load(0, true);
604         }
605
606         // scan qualified name
607
int offset = fCurrentEntity.position;
608         char ch = fCurrentEntity.ch[offset];
609         
610         if (XML11Char.isXML11NCNameStart(ch)) {
611             if (++fCurrentEntity.position == fCurrentEntity.count) {
612                 fCurrentEntity.ch[0] = ch;
613                 offset = 0;
614                 if (load(1, false)) {
615                     fCurrentEntity.columnNumber++;
616                     String JavaDoc name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 1);
617                     qname.setValues(null, name, name, null);
618                     return true;
619                 }
620             }
621         }
622         else if (XML11Char.isXML11NameHighSurrogate(ch)) {
623             if (++fCurrentEntity.position == fCurrentEntity.count) {
624                 fCurrentEntity.ch[0] = ch;
625                 offset = 0;
626                 if (load(1, false)) {
627                     --fCurrentEntity.position;
628                     return false;
629                 }
630             }
631             char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
632             if ( !XMLChar.isLowSurrogate(ch2) ||
633                  !XML11Char.isXML11NCNameStart(XMLChar.supplemental(ch, ch2)) ) {
634                 --fCurrentEntity.position;
635                 return false;
636             }
637             if (++fCurrentEntity.position == fCurrentEntity.count) {
638                 fCurrentEntity.ch[0] = ch;
639                 fCurrentEntity.ch[1] = ch2;
640                 offset = 0;
641                 if (load(2, false)) {
642                     fCurrentEntity.columnNumber += 2;
643                     String JavaDoc name = fSymbolTable.addSymbol(fCurrentEntity.ch, 0, 2);
644                     qname.setValues(null, name, name, null);
645                     return true;
646                 }
647             }
648         }
649         else {
650             return false;
651         }
652         
653         int index = -1;
654         boolean sawIncompleteSurrogatePair = false;
655         do {
656             ch = fCurrentEntity.ch[fCurrentEntity.position];
657             if (XML11Char.isXML11Name(ch)) {
658                 if (ch == ':') {
659                     if (index != -1) {
660                         break;
661                     }
662                     index = fCurrentEntity.position;
663                 }
664                 if (++fCurrentEntity.position == fCurrentEntity.count) {
665                     int length = fCurrentEntity.position - offset;
666                     if (length == fCurrentEntity.ch.length) {
667                         // bad luck we have to resize our buffer
668
char[] tmp = new char[fCurrentEntity.ch.length << 1];
669                         System.arraycopy(fCurrentEntity.ch, offset,
670                                          tmp, 0, length);
671                         fCurrentEntity.ch = tmp;
672                     }
673                     else {
674                         System.arraycopy(fCurrentEntity.ch, offset,
675                                          fCurrentEntity.ch, 0, length);
676                     }
677                     if (index != -1) {
678                         index = index - offset;
679                     }
680                     offset = 0;
681                     if (load(length, false)) {
682                         break;
683                     }
684                 }
685             }
686             else if (XML11Char.isXML11NameHighSurrogate(ch)) {
687                 if (++fCurrentEntity.position == fCurrentEntity.count) {
688                     int length = fCurrentEntity.position - offset;
689                     if (length == fCurrentEntity.ch.length) {
690                         // bad luck we have to resize our buffer
691
char[] tmp = new char[fCurrentEntity.ch.length << 1];
692                         System.arraycopy(fCurrentEntity.ch, offset,
693                                          tmp, 0, length);
694                         fCurrentEntity.ch = tmp;
695                     }
696                     else {
697                         System.arraycopy(fCurrentEntity.ch, offset,
698                                          fCurrentEntity.ch, 0, length);
699                     }
700                     if (index != -1) {
701                         index = index - offset;
702                     }
703                     offset = 0;
704                     if (load(length, false)) {
705                         sawIncompleteSurrogatePair = true;
706                         --fCurrentEntity.position;
707                         break;
708                     }
709                 }
710                 char ch2 = fCurrentEntity.ch[fCurrentEntity.position];
711                 if ( !XMLChar.isLowSurrogate(ch2) ||
712                      !XML11Char.isXML11Name(XMLChar.supplemental(ch, ch2)) ) {
713                     sawIncompleteSurrogatePair = true;
714                     --fCurrentEntity.position;
715                     break;
716                 }
717                 if (++fCurrentEntity.position == fCurrentEntity.count) {
718                     int length = fCurrentEntity.position - offset;
719                     if (length == fCurrentEntity.ch.length) {
720                         // bad luck we have to resize our buffer
721
char[] tmp = new char[fCurrentEntity.ch.length << 1];
722                         System.arraycopy(fCurrentEntity.ch, offset,
723                                          tmp, 0, length);
724                         fCurrentEntity.ch = tmp;
725                     }
726                     else {
727                         System.arraycopy(fCurrentEntity.ch, offset,
728                                          fCurrentEntity.ch, 0, length);
729                     }
730                     if (index != -1) {
731                         index = index - offset;
732                     }
733                     offset = 0;
734                     if (load(length, false)) {
735                         break;
736                     }
737                 }
738             }
739             else {
740                 break;
741             }
742         }
743         while (true);
744         
745         int length = fCurrentEntity.position - offset;
746         fCurrentEntity.columnNumber += length;
747         
748         if (length > 0) {
749             String JavaDoc prefix = null;
750             String JavaDoc localpart = null;
751             String JavaDoc rawname = fSymbolTable.addSymbol(fCurrentEntity.ch,
752                                                     offset, length);
753             if (index != -1) {
754                 int prefixLength = index - offset;
755                 prefix = fSymbolTable.addSymbol(fCurrentEntity.ch,
756                                                     offset, prefixLength);
757                 int len = length - prefixLength - 1;
758                 int startLocal = index +1;
759                 if (!XML11Char.isXML11NCNameStart(fCurrentEntity.ch[startLocal]) &&
760                     (!XML11Char.isXML11NameHighSurrogate(fCurrentEntity.ch[startLocal]) ||
761                     sawIncompleteSurrogatePair)){
762                     fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
763                                                "IllegalQName",
764                                                null,
765                                                XMLErrorReporter.SEVERITY_FATAL_ERROR);
766                 }
767                 localpart = fSymbolTable.addSymbol(fCurrentEntity.ch,
768                                                    index + 1, len);
769
770             }
771             else {
772                 localpart = rawname;
773             }
774             qname.setValues(prefix, localpart, rawname, null);
775             return true;
776         }
777         return false;
778
779     } // scanQName(QName):boolean
780

781     /**
782      * Scans a range of parsed character data, setting the fields of the
783      * XMLString structure, appropriately.
784      * <p>
785      * <strong>Note:</strong> The characters are consumed.
786      * <p>
787      * <strong>Note:</strong> This method does not guarantee to return
788      * the longest run of parsed character data. This method may return
789      * before markup due to reaching the end of the input buffer or any
790      * other reason.
791      * <p>
792      * <strong>Note:</strong> The fields contained in the XMLString
793      * structure are not guaranteed to remain valid upon subsequent calls
794      * to the entity scanner. Therefore, the caller is responsible for
795      * immediately using the returned character data or making a copy of
796      * the character data.
797      *
798      * @param content The content structure to fill.
799      *
800      * @return Returns the next character on the input, if known. This
801      * value may be -1 but this does <em>note</em> designate
802      * end of file.
803      *
804      * @throws IOException Thrown if i/o error occurs.
805      * @throws EOFException Thrown on end of file.
806      */

807     public int scanContent(XMLString content) throws IOException JavaDoc {
808
809         // load more characters, if needed
810
if (fCurrentEntity.position == fCurrentEntity.count) {
811             load(0, true);
812         }
813         else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
814             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
815             load(1, false);
816             fCurrentEntity.position = 0;
817         }
818
819         // normalize newlines
820
int offset = fCurrentEntity.position;
821         int c = fCurrentEntity.ch[offset];
822         int newlines = 0;
823         boolean external = fCurrentEntity.isExternal();
824         if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
825             do {
826                 c = fCurrentEntity.ch[fCurrentEntity.position++];
827                 if ((c == '\r' ) && external) {
828                     newlines++;
829                     fCurrentEntity.lineNumber++;
830                     fCurrentEntity.columnNumber = 1;
831                     if (fCurrentEntity.position == fCurrentEntity.count) {
832                         offset = 0;
833                         fCurrentEntity.position = newlines;
834                         if (load(newlines, false)) {
835                             break;
836                         }
837                     }
838                     int cc = fCurrentEntity.ch[fCurrentEntity.position];
839                     if (cc == '\n' || cc == 0x85) {
840                         fCurrentEntity.position++;
841                         offset++;
842                     }
843                     /*** NEWLINE NORMALIZATION ***/
844                     else {
845                         newlines++;
846                     }
847                 }
848                 else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {
849                     newlines++;
850                     fCurrentEntity.lineNumber++;
851                     fCurrentEntity.columnNumber = 1;
852                     if (fCurrentEntity.position == fCurrentEntity.count) {
853                         offset = 0;
854                         fCurrentEntity.position = newlines;
855                         if (load(newlines, false)) {
856                             break;
857                         }
858                     }
859                 }
860                 else {
861                     fCurrentEntity.position--;
862                     break;
863                 }
864             } while (fCurrentEntity.position < fCurrentEntity.count - 1);
865             for (int i = offset; i < fCurrentEntity.position; i++) {
866                 fCurrentEntity.ch[i] = '\n';
867             }
868             int length = fCurrentEntity.position - offset;
869             if (fCurrentEntity.position == fCurrentEntity.count - 1) {
870                 content.setValues(fCurrentEntity.ch, offset, length);
871                 return -1;
872             }
873         }
874
875         // inner loop, scanning for content
876
if (external) {
877             while (fCurrentEntity.position < fCurrentEntity.count) {
878                 c = fCurrentEntity.ch[fCurrentEntity.position++];
879                 if (!XML11Char.isXML11Content(c) || c == 0x85 || c == 0x2028) {
880                     fCurrentEntity.position--;
881                     break;
882                 }
883             }
884         }
885         else {
886             while (fCurrentEntity.position < fCurrentEntity.count) {
887                 c = fCurrentEntity.ch[fCurrentEntity.position++];
888                 // In internal entities control characters are allowed to appear unescaped.
889
if (!XML11Char.isXML11InternalEntityContent(c)) {
890                     fCurrentEntity.position--;
891                     break;
892                 }
893             }
894         }
895         int length = fCurrentEntity.position - offset;
896         fCurrentEntity.columnNumber += length - newlines;
897         content.setValues(fCurrentEntity.ch, offset, length);
898
899         // return next character
900
if (fCurrentEntity.position != fCurrentEntity.count) {
901             c = fCurrentEntity.ch[fCurrentEntity.position];
902             // REVISIT: Does this need to be updated to fix the
903
// #x0D ^#x0A newline normalization problem? -Ac
904
if ((c == '\r' || c == 0x85 || c == 0x2028) && external) {
905                 c = '\n';
906             }
907         }
908         else {
909             c = -1;
910         }
911         return c;
912
913     } // scanContent(XMLString):int
914

915     /**
916      * Scans a range of attribute value data, setting the fields of the
917      * XMLString structure, appropriately.
918      * <p>
919      * <strong>Note:</strong> The characters are consumed.
920      * <p>
921      * <strong>Note:</strong> This method does not guarantee to return
922      * the longest run of attribute value data. This method may return
923      * before the quote character due to reaching the end of the input
924      * buffer or any other reason.
925      * <p>
926      * <strong>Note:</strong> The fields contained in the XMLString
927      * structure are not guaranteed to remain valid upon subsequent calls
928      * to the entity scanner. Therefore, the caller is responsible for
929      * immediately using the returned character data or making a copy of
930      * the character data.
931      *
932      * @param quote The quote character that signifies the end of the
933      * attribute value data.
934      * @param content The content structure to fill.
935      *
936      * @return Returns the next character on the input, if known. This
937      * value may be -1 but this does <em>note</em> designate
938      * end of file.
939      *
940      * @throws IOException Thrown if i/o error occurs.
941      * @throws EOFException Thrown on end of file.
942      */

943     public int scanLiteral(int quote, XMLString content)
944         throws IOException JavaDoc {
945
946         // load more characters, if needed
947
if (fCurrentEntity.position == fCurrentEntity.count) {
948             load(0, true);
949         }
950         else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
951             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
952             load(1, false);
953             fCurrentEntity.position = 0;
954         }
955
956         // normalize newlines
957
int offset = fCurrentEntity.position;
958         int c = fCurrentEntity.ch[offset];
959         int newlines = 0;
960         boolean external = fCurrentEntity.isExternal();
961         if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
962             do {
963                 c = fCurrentEntity.ch[fCurrentEntity.position++];
964                 if ((c == '\r' ) && external) {
965                     newlines++;
966                     fCurrentEntity.lineNumber++;
967                     fCurrentEntity.columnNumber = 1;
968                     if (fCurrentEntity.position == fCurrentEntity.count) {
969                         offset = 0;
970                         fCurrentEntity.position = newlines;
971                         if (load(newlines, false)) {
972                             break;
973                         }
974                     }
975                     int cc = fCurrentEntity.ch[fCurrentEntity.position];
976                     if (cc == '\n' || cc == 0x85) {
977                         fCurrentEntity.position++;
978                         offset++;
979                     }
980                     /*** NEWLINE NORMALIZATION ***/
981                     else {
982                         newlines++;
983                     }
984                 }
985                 else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {
986                     newlines++;
987                     fCurrentEntity.lineNumber++;
988                     fCurrentEntity.columnNumber = 1;
989                     if (fCurrentEntity.position == fCurrentEntity.count) {
990                         offset = 0;
991                         fCurrentEntity.position = newlines;
992                         if (load(newlines, false)) {
993                             break;
994                         }
995                     }
996                 }
997                 else {
998                     fCurrentEntity.position--;
999                     break;
1000                }
1001            } while (fCurrentEntity.position < fCurrentEntity.count - 1);
1002            for (int i = offset; i < fCurrentEntity.position; i++) {
1003                fCurrentEntity.ch[i] = '\n';
1004            }
1005            int length = fCurrentEntity.position - offset;
1006            if (fCurrentEntity.position == fCurrentEntity.count - 1) {
1007                content.setValues(fCurrentEntity.ch, offset, length);
1008                return -1;
1009            }
1010        }
1011
1012        // scan literal value
1013
if (external) {
1014            while (fCurrentEntity.position < fCurrentEntity.count) {
1015                c = fCurrentEntity.ch[fCurrentEntity.position++];
1016                if (c == quote || c == '%' || !XML11Char.isXML11Content(c)
1017                    || c == 0x85 || c == 0x2028) {
1018                    fCurrentEntity.position--;
1019                    break;
1020                }
1021            }
1022        }
1023        else {
1024            while (fCurrentEntity.position < fCurrentEntity.count) {
1025                c = fCurrentEntity.ch[fCurrentEntity.position++];
1026                // In internal entities control characters are allowed to appear unescaped.
1027
if ((c == quote && !fCurrentEntity.literal)
1028                    || c == '%' || !XML11Char.isXML11InternalEntityContent(c)) {
1029                    fCurrentEntity.position--;
1030                    break;
1031                }
1032            }
1033        }
1034        int length = fCurrentEntity.position - offset;
1035        fCurrentEntity.columnNumber += length - newlines;
1036        content.setValues(fCurrentEntity.ch, offset, length);
1037
1038        // return next character
1039
if (fCurrentEntity.position != fCurrentEntity.count) {
1040            c = fCurrentEntity.ch[fCurrentEntity.position];
1041            // NOTE: We don't want to accidentally signal the
1042
// end of the literal if we're expanding an
1043
// entity appearing in the literal. -Ac
1044
if (c == quote && fCurrentEntity.literal) {
1045                c = -1;
1046            }
1047        }
1048        else {
1049            c = -1;
1050        }
1051        return c;
1052
1053    } // scanLiteral(int,XMLString):int
1054

1055    /**
1056     * Scans a range of character data up to the specicied delimiter,
1057     * setting the fields of the XMLString structure, appropriately.
1058     * <p>
1059     * <strong>Note:</strong> The characters are consumed.
1060     * <p>
1061     * <strong>Note:</strong> This assumes that the internal buffer is
1062     * at least the same size, or bigger, than the length of the delimiter
1063     * and that the delimiter contains at least one character.
1064     * <p>
1065     * <strong>Note:</strong> This method does not guarantee to return
1066     * the longest run of character data. This method may return before
1067     * the delimiter due to reaching the end of the input buffer or any
1068     * other reason.
1069     * <p>
1070     * <strong>Note:</strong> The fields contained in the XMLString
1071     * structure are not guaranteed to remain valid upon subsequent calls
1072     * to the entity scanner. Therefore, the caller is responsible for
1073     * immediately using the returned character data or making a copy of
1074     * the character data.
1075     *
1076     * @param delimiter The string that signifies the end of the character
1077     * data to be scanned.
1078     * @param data The data structure to fill.
1079     *
1080     * @return Returns true if there is more data to scan, false otherwise.
1081     *
1082     * @throws IOException Thrown if i/o error occurs.
1083     * @throws EOFException Thrown on end of file.
1084     */

1085    public boolean scanData(String JavaDoc delimiter, XMLStringBuffer buffer)
1086        throws IOException JavaDoc {
1087
1088        boolean done = false;
1089        int delimLen = delimiter.length();
1090        char charAt0 = delimiter.charAt(0);
1091        boolean external = fCurrentEntity.isExternal();
1092        do {
1093            // load more characters, if needed
1094
if (fCurrentEntity.position == fCurrentEntity.count) {
1095                load(0, true);
1096            }
1097
1098            boolean bNextEntity = false;
1099
1100            while ((fCurrentEntity.position >= fCurrentEntity.count - delimLen)
1101                && (!bNextEntity))
1102            {
1103              System.arraycopy(fCurrentEntity.ch,
1104                               fCurrentEntity.position,
1105                               fCurrentEntity.ch,
1106                               0,
1107                               fCurrentEntity.count - fCurrentEntity.position);
1108
1109              bNextEntity = load(fCurrentEntity.count - fCurrentEntity.position, false);
1110              fCurrentEntity.position = 0;
1111            }
1112
1113            if (fCurrentEntity.position >= fCurrentEntity.count - delimLen) {
1114                // something must be wrong with the input: e.g., file ends an unterminated comment
1115
int length = fCurrentEntity.count - fCurrentEntity.position;
1116                buffer.append (fCurrentEntity.ch, fCurrentEntity.position, length);
1117                fCurrentEntity.columnNumber += fCurrentEntity.count;
1118                fCurrentEntity.position = fCurrentEntity.count;
1119                load(0,true);
1120                return false;
1121            }
1122
1123            // normalize newlines
1124
int offset = fCurrentEntity.position;
1125            int c = fCurrentEntity.ch[offset];
1126            int newlines = 0;
1127            if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
1128                do {
1129                    c = fCurrentEntity.ch[fCurrentEntity.position++];
1130                    if ((c == '\r' ) && external) {
1131                        newlines++;
1132                        fCurrentEntity.lineNumber++;
1133                        fCurrentEntity.columnNumber = 1;
1134                        if (fCurrentEntity.position == fCurrentEntity.count) {
1135                            offset = 0;
1136                            fCurrentEntity.position = newlines;
1137                            if (load(newlines, false)) {
1138                                break;
1139                            }
1140                        }
1141                        int cc = fCurrentEntity.ch[fCurrentEntity.position];
1142                        if (cc == '\n' || cc == 0x85) {
1143                            fCurrentEntity.position++;
1144                            offset++;
1145                        }
1146                        /*** NEWLINE NORMALIZATION ***/
1147                        else {
1148                            newlines++;
1149                        }
1150                    }
1151                    else if (c == '\n' || ((c == 0x85 || c == 0x2028) && external)) {
1152                        newlines++;
1153                        fCurrentEntity.lineNumber++;
1154                        fCurrentEntity.columnNumber = 1;
1155                        if (fCurrentEntity.position == fCurrentEntity.count) {
1156                            offset = 0;
1157                            fCurrentEntity.position = newlines;
1158                            fCurrentEntity.count = newlines;
1159                            if (load(newlines, false)) {
1160                                break;
1161                            }
1162                        }
1163                    }
1164                    else {
1165                        fCurrentEntity.position--;
1166                        break;
1167                    }
1168                } while (fCurrentEntity.position < fCurrentEntity.count - 1);
1169                for (int i = offset; i < fCurrentEntity.position; i++) {
1170                    fCurrentEntity.ch[i] = '\n';
1171                }
1172                int length = fCurrentEntity.position - offset;
1173                if (fCurrentEntity.position == fCurrentEntity.count - 1) {
1174                    buffer.append(fCurrentEntity.ch, offset, length);
1175                    return true;
1176                }
1177            }
1178
1179            // iterate over buffer looking for delimiter
1180
if (external) {
1181                OUTER: while (fCurrentEntity.position < fCurrentEntity.count) {
1182                    c = fCurrentEntity.ch[fCurrentEntity.position++];
1183                    if (c == charAt0) {
1184                        // looks like we just hit the delimiter
1185
int delimOffset = fCurrentEntity.position - 1;
1186                        for (int i = 1; i < delimLen; i++) {
1187                            if (fCurrentEntity.position == fCurrentEntity.count) {
1188                                fCurrentEntity.position -= i;
1189                                break OUTER;
1190                            }
1191                            c = fCurrentEntity.ch[fCurrentEntity.position++];
1192                            if (delimiter.charAt(i) != c) {
1193                                fCurrentEntity.position--;
1194                                break;
1195                            }
1196                         }
1197                         if (fCurrentEntity.position == delimOffset + delimLen) {
1198                            done = true;
1199                            break;
1200                         }
1201                    }
1202                    else if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
1203                        fCurrentEntity.position--;
1204                        break;
1205                    }
1206                    // In external entities control characters cannot appear
1207
// as literals so do not skip over them.
1208
else if (!XML11Char.isXML11ValidLiteral(c)) {
1209                        fCurrentEntity.position--;
1210                        int length = fCurrentEntity.position - offset;
1211                        fCurrentEntity.columnNumber += length - newlines;
1212                        buffer.append(fCurrentEntity.ch, offset, length);
1213                        return true;
1214                    }
1215                }
1216            }
1217            else {
1218                OUTER: while (fCurrentEntity.position < fCurrentEntity.count) {
1219                    c = fCurrentEntity.ch[fCurrentEntity.position++];
1220                    if (c == charAt0) {
1221                        // looks like we just hit the delimiter
1222
int delimOffset = fCurrentEntity.position - 1;
1223                        for (int i = 1; i < delimLen; i++) {
1224                            if (fCurrentEntity.position == fCurrentEntity.count) {
1225                                fCurrentEntity.position -= i;
1226                                break OUTER;
1227                            }
1228                            c = fCurrentEntity.ch[fCurrentEntity.position++];
1229                            if (delimiter.charAt(i) != c) {
1230                                fCurrentEntity.position--;
1231                                break;
1232                            }
1233                        }
1234                        if (fCurrentEntity.position == delimOffset + delimLen) {
1235                            done = true;
1236                            break;
1237                        }
1238                    }
1239                    else if (c == '\n') {
1240                        fCurrentEntity.position--;
1241                        break;
1242                    }
1243                    // Control characters are allowed to appear as literals
1244
// in internal entities.
1245
else if (!XML11Char.isXML11Valid(c)) {
1246                        fCurrentEntity.position--;
1247                        int length = fCurrentEntity.position - offset;
1248                        fCurrentEntity.columnNumber += length - newlines;
1249                        buffer.append(fCurrentEntity.ch, offset, length);
1250                        return true;
1251                    }
1252                }
1253            }
1254            int length = fCurrentEntity.position - offset;
1255            fCurrentEntity.columnNumber += length - newlines;
1256            if (done) {
1257                length -= delimLen;
1258            }
1259            buffer.append(fCurrentEntity.ch, offset, length);
1260
1261            // return true if string was skipped
1262
} while (!done);
1263        return !done;
1264
1265    } // scanData(String,XMLString)
1266

1267    /**
1268     * Skips a character appearing immediately on the input.
1269     * <p>
1270     * <strong>Note:</strong> The character is consumed only if it matches
1271     * the specified character.
1272     *
1273     * @param c The character to skip.
1274     *
1275     * @return Returns true if the character was skipped.
1276     *
1277     * @throws IOException Thrown if i/o error occurs.
1278     * @throws EOFException Thrown on end of file.
1279     */

1280    public boolean skipChar(int c) throws IOException JavaDoc {
1281
1282        // load more characters, if needed
1283
if (fCurrentEntity.position == fCurrentEntity.count) {
1284            load(0, true);
1285        }
1286
1287        // skip character
1288
int cc = fCurrentEntity.ch[fCurrentEntity.position];
1289        if (cc == c) {
1290            fCurrentEntity.position++;
1291            if (c == '\n') {
1292                fCurrentEntity.lineNumber++;
1293                fCurrentEntity.columnNumber = 1;
1294            }
1295            else {
1296                fCurrentEntity.columnNumber++;
1297            }
1298            return true;
1299        }
1300        else if (c == '\n' && ((cc == 0x2028 || cc == 0x85) && fCurrentEntity.isExternal())) {
1301            fCurrentEntity.position++;
1302            fCurrentEntity.lineNumber++;
1303            fCurrentEntity.columnNumber = 1;
1304            return true;
1305        }
1306        else if (c == '\n' && (cc == '\r' ) && fCurrentEntity.isExternal()) {
1307            // handle newlines
1308
if (fCurrentEntity.position == fCurrentEntity.count) {
1309                fCurrentEntity.ch[0] = (char)cc;
1310                load(1, false);
1311            }
1312            int ccc = fCurrentEntity.ch[++fCurrentEntity.position];
1313            if (ccc == '\n' || ccc == 0x85) {
1314                fCurrentEntity.position++;
1315            }
1316            fCurrentEntity.lineNumber++;
1317            fCurrentEntity.columnNumber = 1;
1318            return true;
1319        }
1320
1321        // character was not skipped
1322
return false;
1323
1324    } // skipChar(int):boolean
1325

1326    /**
1327     * Skips space characters appearing immediately on the input.
1328     * <p>
1329     * <strong>Note:</strong> The characters are consumed only if they are
1330     * space characters.
1331     *
1332     * @return Returns true if at least one space character was skipped.
1333     *
1334     * @throws IOException Thrown if i/o error occurs.
1335     * @throws EOFException Thrown on end of file.
1336     *
1337     * @see com.sun.org.apache.xerces.internal.util.XMLChar#isSpace
1338     * @see com.sun.org.apache.xerces.internal.util.XML11Char#isXML11Space
1339     */

1340    public boolean skipSpaces() throws IOException JavaDoc {
1341
1342        // load more characters, if needed
1343
if (fCurrentEntity.position == fCurrentEntity.count) {
1344            load(0, true);
1345        }
1346
1347        // skip spaces
1348
int c = fCurrentEntity.ch[fCurrentEntity.position];
1349        
1350        // External -- Match: S + 0x85 + 0x2028, and perform end of line normalization
1351
if (fCurrentEntity.isExternal()) {
1352            if (XML11Char.isXML11Space(c)) {
1353                do {
1354                    boolean entityChanged = false;
1355                    // handle newlines
1356
if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
1357                        fCurrentEntity.lineNumber++;
1358                        fCurrentEntity.columnNumber = 1;
1359                        if (fCurrentEntity.position == fCurrentEntity.count - 1) {
1360                            fCurrentEntity.ch[0] = (char)c;
1361                            entityChanged = load(1, true);
1362                            if (!entityChanged)
1363                                // the load change the position to be 1,
1364
// need to restore it when entity not changed
1365
fCurrentEntity.position = 0;
1366                        }
1367                        if (c == '\r') {
1368                            // REVISIT: Does this need to be updated to fix the
1369
// #x0D ^#x0A newline normalization problem? -Ac
1370
int cc = fCurrentEntity.ch[++fCurrentEntity.position];
1371                            if (cc != '\n' && cc != 0x85 ) {
1372                                fCurrentEntity.position--;
1373                            }
1374                        }
1375                    }
1376                    else {
1377                        fCurrentEntity.columnNumber++;
1378                    }
1379                    // load more characters, if needed
1380
if (!entityChanged)
1381                        fCurrentEntity.position++;
1382                    if (fCurrentEntity.position == fCurrentEntity.count) {
1383                        load(0, true);
1384                    }
1385                } while (XML11Char.isXML11Space(c = fCurrentEntity.ch[fCurrentEntity.position]));
1386                return true;
1387            }
1388        }
1389        // Internal -- Match: S (only)
1390
else if (XMLChar.isSpace(c)) {
1391            do {
1392                boolean entityChanged = false;
1393                // handle newlines
1394
if (c == '\n') {
1395                    fCurrentEntity.lineNumber++;
1396                    fCurrentEntity.columnNumber = 1;
1397                    if (fCurrentEntity.position == fCurrentEntity.count - 1) {
1398                        fCurrentEntity.ch[0] = (char)c;
1399                        entityChanged = load(1, true);
1400                        if (!entityChanged)
1401                            // the load change the position to be 1,
1402
// need to restore it when entity not changed
1403
fCurrentEntity.position = 0;
1404                    }
1405                }
1406                else {
1407                    fCurrentEntity.columnNumber++;
1408                }
1409                // load more characters, if needed
1410
if (!entityChanged)
1411                    fCurrentEntity.position++;
1412                if (fCurrentEntity.position == fCurrentEntity.count) {
1413                    load(0, true);
1414                }
1415            } while (XMLChar.isSpace(c = fCurrentEntity.ch[fCurrentEntity.position]));
1416            return true;
1417        }
1418
1419        // no spaces were found
1420
return false;
1421
1422    } // skipSpaces():boolean
1423

1424    /**
1425     * Skips the specified string appearing immediately on the input.
1426     * <p>
1427     * <strong>Note:</strong> The characters are consumed only if they are
1428     * space characters.
1429     *
1430     * @param s The string to skip.
1431     *
1432     * @return Returns true if the string was skipped.
1433     *
1434     * @throws IOException Thrown if i/o error occurs.
1435     * @throws EOFException Thrown on end of file.
1436     */

1437    public boolean skipString(String JavaDoc s) throws IOException JavaDoc {
1438
1439        // load more characters, if needed
1440
if (fCurrentEntity.position == fCurrentEntity.count) {
1441            load(0, true);
1442        }
1443
1444        // skip string
1445
final int length = s.length();
1446        for (int i = 0; i < length; i++) {
1447            char c = fCurrentEntity.ch[fCurrentEntity.position++];
1448            if (c != s.charAt(i)) {
1449                fCurrentEntity.position -= i + 1;
1450                return false;
1451            }
1452            if (i < length - 1 && fCurrentEntity.position == fCurrentEntity.count) {
1453                System.arraycopy(fCurrentEntity.ch, fCurrentEntity.count - i - 1, fCurrentEntity.ch, 0, i + 1);
1454                // REVISIT: Can a string to be skipped cross an
1455
// entity boundary? -Ac
1456
if (load(i + 1, false)) {
1457                    fCurrentEntity.position -= i + 1;
1458                    return false;
1459                }
1460            }
1461        }
1462        fCurrentEntity.columnNumber += length;
1463        return true;
1464
1465    } // skipString(String):boolean
1466

1467} // class XML11EntityScanner
1468

1469
Popular Tags