< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11EntityScanner.java

Print this page
rev 903 : 8153781: Issue in XMLScanner: EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET
   1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 
   5 /*
   6  * Copyright 2005 The Apache Software Foundation.





   7  *
   8  * Licensed under the Apache License, Version 2.0 (the "License");
   9  * you may not use this file except in compliance with the License.
  10  * You may obtain a copy of the License at
  11  *
  12  *      http://www.apache.org/licenses/LICENSE-2.0
  13  *
  14  * Unless required by applicable law or agreed to in writing, software
  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.xerces.internal.impl;
  22 
  23 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  24 import com.sun.org.apache.xerces.internal.util.XML11Char;
  25 import com.sun.org.apache.xerces.internal.util.XMLChar;
  26 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
  27 import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
  28 import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
  29 import com.sun.org.apache.xerces.internal.xni.QName;
  30 import com.sun.org.apache.xerces.internal.xni.XMLString;
  31 import java.io.IOException;
  32 
  33 /**
  34  * Implements the entity scanner methods in
  35  * the context of XML 1.1.
  36  *
  37  * @xerces.internal
  38  *
  39  * @author Michael Glavassevich, IBM
  40  * @author Neil Graham, IBM
  41  */
  42 
  43 public class XML11EntityScanner
  44     extends XMLEntityScanner {
  45 
  46     //
  47     // Constructors


 798      * to the entity scanner. Therefore, the caller is responsible for
 799      * immediately using the returned character data or making a copy of
 800      * the character data.
 801      *
 802      * @param content The content structure to fill.
 803      *
 804      * @return Returns the next character on the input, if known. This
 805      *         value may be -1 but this does <em>note</em> designate
 806      *         end of file.
 807      *
 808      * @throws IOException  Thrown if i/o error occurs.
 809      * @throws EOFException Thrown on end of file.
 810      */
 811     public int scanContent(XMLString content) throws IOException {
 812 
 813         // load more characters, if needed
 814         if (fCurrentEntity.position == fCurrentEntity.count) {
 815             load(0, true, true);
 816         }
 817         else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
 818             invokeListeners(0);
 819             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
 820             load(1, false, false);
 821             fCurrentEntity.position = 0;
 822             fCurrentEntity.startPosition = 0;
 823         }
 824 
 825         // normalize newlines
 826         int offset = fCurrentEntity.position;
 827         int c = fCurrentEntity.ch[offset];
 828         int newlines = 0;
 829         boolean external = fCurrentEntity.isExternal();
 830         if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
 831             do {
 832                 c = fCurrentEntity.ch[fCurrentEntity.position++];
 833                 if ((c == '\r' ) && external) {
 834                     newlines++;
 835                     fCurrentEntity.lineNumber++;
 836                     fCurrentEntity.columnNumber = 1;
 837                     if (fCurrentEntity.position == fCurrentEntity.count) {
 838                         offset = 0;


 943      * the character data.
 944      *
 945      * @param quote   The quote character that signifies the end of the
 946      *                attribute value data.
 947      * @param content The content structure to fill.
 948      *
 949      * @return Returns the next character on the input, if known. This
 950      *         value may be -1 but this does <em>note</em> designate
 951      *         end of file.
 952      *
 953      * @throws IOException  Thrown if i/o error occurs.
 954      * @throws EOFException Thrown on end of file.
 955      */
 956     public int scanLiteral(int quote, XMLString content)
 957         throws IOException {
 958         // load more characters, if needed
 959         if (fCurrentEntity.position == fCurrentEntity.count) {
 960             load(0, true, true);
 961         }
 962         else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
 963             invokeListeners(0);
 964             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
 965             load(1, false, false);
 966             fCurrentEntity.startPosition = 0;
 967             fCurrentEntity.position = 0;
 968         }
 969 
 970         // normalize newlines
 971         int offset = fCurrentEntity.position;
 972         int c = fCurrentEntity.ch[offset];
 973         int newlines = 0;
 974         boolean external = fCurrentEntity.isExternal();
 975         if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
 976             do {
 977                 c = fCurrentEntity.ch[fCurrentEntity.position++];
 978                 if ((c == '\r' ) && external) {
 979                     newlines++;
 980                     fCurrentEntity.lineNumber++;
 981                     fCurrentEntity.columnNumber = 1;
 982                     if (fCurrentEntity.position == fCurrentEntity.count) {
 983                         offset = 0;


1380         //it is possible that end of document is reached and
1381         //fCurrentEntity becomes null
1382         //nothing was read so entity changed  'false' should be returned.
1383         if(fCurrentEntity == null){
1384             return false ;
1385         }
1386 
1387         // skip spaces
1388         int c = fCurrentEntity.ch[fCurrentEntity.position];
1389 
1390         // External --  Match: S + 0x85 + 0x2028, and perform end of line normalization
1391         if (fCurrentEntity.isExternal()) {
1392             if (XML11Char.isXML11Space(c)) {
1393                 do {
1394                     boolean entityChanged = false;
1395                     // handle newlines
1396                     if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
1397                         fCurrentEntity.lineNumber++;
1398                         fCurrentEntity.columnNumber = 1;
1399                         if (fCurrentEntity.position == fCurrentEntity.count - 1) {
1400                             invokeListeners(0);
1401                             fCurrentEntity.ch[0] = (char)c;
1402                             entityChanged = load(1, true, false);
1403                             if (!entityChanged) {
1404                                 // the load change the position to be 1,
1405                                 // need to restore it when entity not changed
1406                                 fCurrentEntity.startPosition = 0;
1407                                 fCurrentEntity.position = 0;
1408                             } else if(fCurrentEntity == null){
1409                                 return true ;
1410                             }
1411 
1412                         }
1413                         if (c == '\r') {
1414                             // REVISIT: Does this need to be updated to fix the
1415                             //          #x0D ^#x0A newline normalization problem? -Ac
1416                             int cc = fCurrentEntity.ch[++fCurrentEntity.position];
1417                             if (cc != '\n' && cc != 0x85 ) {
1418                                 fCurrentEntity.position--;
1419                             }
1420                         }


1429                         load(0, true, true);
1430 
1431                         if(fCurrentEntity == null){
1432                         return true ;
1433                         }
1434 
1435                     }
1436                 } while (XML11Char.isXML11Space(c = fCurrentEntity.ch[fCurrentEntity.position]));
1437                 return true;
1438             }
1439         }
1440         // Internal -- Match: S (only)
1441         else if (XMLChar.isSpace(c)) {
1442             do {
1443                 boolean entityChanged = false;
1444                 // handle newlines
1445                 if (c == '\n') {
1446                     fCurrentEntity.lineNumber++;
1447                     fCurrentEntity.columnNumber = 1;
1448                     if (fCurrentEntity.position == fCurrentEntity.count - 1) {

1449                         fCurrentEntity.ch[0] = (char)c;
1450                         entityChanged = load(1, true, true);
1451                         if (!entityChanged) {
1452                             // the load change the position to be 1,
1453                             // need to restore it when entity not changed
1454                             fCurrentEntity.startPosition = 0;
1455                             fCurrentEntity.position = 0;
1456                         } else if(fCurrentEntity == null){
1457                         return true ;
1458                         }
1459                     }
1460                 }
1461                 else {
1462                     fCurrentEntity.columnNumber++;
1463                 }
1464                 // load more characters, if needed
1465                 if (!entityChanged)
1466                     fCurrentEntity.position++;
1467                 if (fCurrentEntity.position == fCurrentEntity.count) {
1468                     load(0, true, true);
1469 
1470                     if(fCurrentEntity == null){


   1 /*
   2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
   3  */
   4 
   5 /*
   6  * Licensed to the Apache Software Foundation (ASF) under one or more
   7  * contributor license agreements.  See the NOTICE file distributed with
   8  * this work for additional information regarding copyright ownership.
   9  * The ASF licenses this file to You under the Apache License, Version 2.0
  10  * (the "License"); you may not use this file except in compliance with
  11  * the License.  You may obtain a copy of the License at
  12  *
  13  *     http://www.apache.org/licenses/LICENSE-2.0




  14  *
  15  * Unless required by applicable law or agreed to in writing, software
  16  * distributed under the License is distributed on an "AS IS" BASIS,
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18  * See the License for the specific language governing permissions and
  19  * limitations under the License.
  20  */
  21 
  22 package com.sun.org.apache.xerces.internal.impl;
  23 
  24 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  25 import com.sun.org.apache.xerces.internal.util.XML11Char;
  26 import com.sun.org.apache.xerces.internal.util.XMLChar;
  27 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;

  28 import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager.Limit;
  29 import com.sun.org.apache.xerces.internal.xni.QName;
  30 import com.sun.org.apache.xerces.internal.xni.XMLString;
  31 import java.io.IOException;
  32 
  33 /**
  34  * Implements the entity scanner methods in
  35  * the context of XML 1.1.
  36  *
  37  * @xerces.internal
  38  *
  39  * @author Michael Glavassevich, IBM
  40  * @author Neil Graham, IBM
  41  */
  42 
  43 public class XML11EntityScanner
  44     extends XMLEntityScanner {
  45 
  46     //
  47     // Constructors


 798      * to the entity scanner. Therefore, the caller is responsible for
 799      * immediately using the returned character data or making a copy of
 800      * the character data.
 801      *
 802      * @param content The content structure to fill.
 803      *
 804      * @return Returns the next character on the input, if known. This
 805      *         value may be -1 but this does <em>note</em> designate
 806      *         end of file.
 807      *
 808      * @throws IOException  Thrown if i/o error occurs.
 809      * @throws EOFException Thrown on end of file.
 810      */
 811     public int scanContent(XMLString content) throws IOException {
 812 
 813         // load more characters, if needed
 814         if (fCurrentEntity.position == fCurrentEntity.count) {
 815             load(0, true, true);
 816         }
 817         else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
 818             invokeListeners(1);
 819             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
 820             load(1, false, false);
 821             fCurrentEntity.position = 0;
 822             fCurrentEntity.startPosition = 0;
 823         }
 824 
 825         // normalize newlines
 826         int offset = fCurrentEntity.position;
 827         int c = fCurrentEntity.ch[offset];
 828         int newlines = 0;
 829         boolean external = fCurrentEntity.isExternal();
 830         if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
 831             do {
 832                 c = fCurrentEntity.ch[fCurrentEntity.position++];
 833                 if ((c == '\r' ) && external) {
 834                     newlines++;
 835                     fCurrentEntity.lineNumber++;
 836                     fCurrentEntity.columnNumber = 1;
 837                     if (fCurrentEntity.position == fCurrentEntity.count) {
 838                         offset = 0;


 943      * the character data.
 944      *
 945      * @param quote   The quote character that signifies the end of the
 946      *                attribute value data.
 947      * @param content The content structure to fill.
 948      *
 949      * @return Returns the next character on the input, if known. This
 950      *         value may be -1 but this does <em>note</em> designate
 951      *         end of file.
 952      *
 953      * @throws IOException  Thrown if i/o error occurs.
 954      * @throws EOFException Thrown on end of file.
 955      */
 956     public int scanLiteral(int quote, XMLString content)
 957         throws IOException {
 958         // load more characters, if needed
 959         if (fCurrentEntity.position == fCurrentEntity.count) {
 960             load(0, true, true);
 961         }
 962         else if (fCurrentEntity.position == fCurrentEntity.count - 1) {
 963             invokeListeners(1);
 964             fCurrentEntity.ch[0] = fCurrentEntity.ch[fCurrentEntity.count - 1];
 965             load(1, false, false);
 966             fCurrentEntity.startPosition = 0;
 967             fCurrentEntity.position = 0;
 968         }
 969 
 970         // normalize newlines
 971         int offset = fCurrentEntity.position;
 972         int c = fCurrentEntity.ch[offset];
 973         int newlines = 0;
 974         boolean external = fCurrentEntity.isExternal();
 975         if (c == '\n' || ((c == '\r' || c == 0x85 || c == 0x2028) && external)) {
 976             do {
 977                 c = fCurrentEntity.ch[fCurrentEntity.position++];
 978                 if ((c == '\r' ) && external) {
 979                     newlines++;
 980                     fCurrentEntity.lineNumber++;
 981                     fCurrentEntity.columnNumber = 1;
 982                     if (fCurrentEntity.position == fCurrentEntity.count) {
 983                         offset = 0;


1380         //it is possible that end of document is reached and
1381         //fCurrentEntity becomes null
1382         //nothing was read so entity changed  'false' should be returned.
1383         if(fCurrentEntity == null){
1384             return false ;
1385         }
1386 
1387         // skip spaces
1388         int c = fCurrentEntity.ch[fCurrentEntity.position];
1389 
1390         // External --  Match: S + 0x85 + 0x2028, and perform end of line normalization
1391         if (fCurrentEntity.isExternal()) {
1392             if (XML11Char.isXML11Space(c)) {
1393                 do {
1394                     boolean entityChanged = false;
1395                     // handle newlines
1396                     if (c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
1397                         fCurrentEntity.lineNumber++;
1398                         fCurrentEntity.columnNumber = 1;
1399                         if (fCurrentEntity.position == fCurrentEntity.count - 1) {
1400                             invokeListeners(1);
1401                             fCurrentEntity.ch[0] = (char)c;
1402                             entityChanged = load(1, true, false);
1403                             if (!entityChanged) {
1404                                 // the load change the position to be 1,
1405                                 // need to restore it when entity not changed
1406                                 fCurrentEntity.startPosition = 0;
1407                                 fCurrentEntity.position = 0;
1408                             } else if(fCurrentEntity == null){
1409                                 return true ;
1410                             }
1411 
1412                         }
1413                         if (c == '\r') {
1414                             // REVISIT: Does this need to be updated to fix the
1415                             //          #x0D ^#x0A newline normalization problem? -Ac
1416                             int cc = fCurrentEntity.ch[++fCurrentEntity.position];
1417                             if (cc != '\n' && cc != 0x85 ) {
1418                                 fCurrentEntity.position--;
1419                             }
1420                         }


1429                         load(0, true, true);
1430 
1431                         if(fCurrentEntity == null){
1432                         return true ;
1433                         }
1434 
1435                     }
1436                 } while (XML11Char.isXML11Space(c = fCurrentEntity.ch[fCurrentEntity.position]));
1437                 return true;
1438             }
1439         }
1440         // Internal -- Match: S (only)
1441         else if (XMLChar.isSpace(c)) {
1442             do {
1443                 boolean entityChanged = false;
1444                 // handle newlines
1445                 if (c == '\n') {
1446                     fCurrentEntity.lineNumber++;
1447                     fCurrentEntity.columnNumber = 1;
1448                     if (fCurrentEntity.position == fCurrentEntity.count - 1) {
1449                         invokeListeners(1);
1450                         fCurrentEntity.ch[0] = (char)c;
1451                         entityChanged = load(1, true, false);
1452                         if (!entityChanged) {
1453                             // the load change the position to be 1,
1454                             // need to restore it when entity not changed
1455                             fCurrentEntity.startPosition = 0;
1456                             fCurrentEntity.position = 0;
1457                         } else if(fCurrentEntity == null){
1458                         return true ;
1459                         }
1460                     }
1461                 }
1462                 else {
1463                     fCurrentEntity.columnNumber++;
1464                 }
1465                 // load more characters, if needed
1466                 if (!entityChanged)
1467                     fCurrentEntity.position++;
1468                 if (fCurrentEntity.position == fCurrentEntity.count) {
1469                     load(0, true, true);
1470 
1471                     if(fCurrentEntity == null){


< prev index next >