< prev index next >

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

Print this page
rev 903 : 8153781: Issue in XMLScanner: EXPECTED_SQUARE_BRACKET_TO_CLOSE_INTERNAL_SUBSET
   1 /*
   2  * Copyright (c) 2003, 2016, 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 import com.sun.xml.internal.stream.dtd.nonvalidating.DTDGrammar;
  23 import java.io.EOFException;
  24 import java.io.IOException;
  25 

  26 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  27 

  28 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  29 import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
  30 import com.sun.org.apache.xerces.internal.util.XMLChar;
  31 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
  32 

  33 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
  34 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
  35 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
  36 import com.sun.org.apache.xerces.internal.xni.XMLString;
  37 import com.sun.org.apache.xerces.internal.xni.XNIException;
  38 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  39 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  40 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  41 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  42 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  43 import com.sun.org.apache.xerces.internal.xni.Augmentations;
  44 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  45 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
  46 import com.sun.org.apache.xerces.internal.impl.Constants;
  47 import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer;
  48 import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
  49 
  50 /**
  51  * This class is responsible for scanning the declarations found
  52  * in the internal and external subsets of a DTD in an XML document.
  53  * The scanner acts as the sources for the DTD information which is
  54  * communicated to the DTD handlers.
  55  * <p>
  56  * This component requires the following features and properties from the
  57  * component manager that uses it:
  58  * <ul>
  59  *  <li>http://xml.org/sax/features/validation</li>
  60  *  <li>http://apache.org/xml/features/scanner/notify-char-refs</li>
  61  *  <li>http://apache.org/xml/properties/internal/symbol-table</li>
  62  *  <li>http://apache.org/xml/properties/internal/error-reporter</li>
  63  *  <li>http://apache.org/xml/properties/internal/entity-manager</li>
  64  * </ul>
  65  *
  66  * @author Arnaud  Le Hors, IBM
  67  * @author Andy Clark, IBM
  68  * @author Glenn Marcy, IBM


 370                 // we're done scanning DTD.
 371                 fLimitAnalyzer.reset(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT);
 372                 return false;
 373             }
 374         } while (complete);
 375 
 376         // return that there is more to scan
 377         return true;
 378 
 379     } // scanDTDInternalSubset(boolean,boolean,boolean):boolean
 380 
 381     /**
 382      * Skip the DTD if javax.xml.stream.supportDTD is false.
 383      *
 384      * @param supportDTD The value of the property javax.xml.stream.supportDTD.
 385      * @return true if DTD is skipped, false otherwise.
 386      * @throws java.io.IOException if i/o error occurs
 387      */
 388     @Override
 389     public boolean skipDTD(boolean supportDTD) throws IOException {
 390         if (!supportDTD) {
 391             fStringBuffer.clear();
 392             if (!fEntityScanner.scanData("]", fStringBuffer)) {
 393                 fEntityScanner.fCurrentEntity.position--;
 394             }
 395 
 396             return true;












 397         }
 398         return false;

 399     }
 400 
 401     //
 402     // XMLComponent methods
 403     //
 404 
 405     /**
 406      * reset
 407      *
 408      * @param componentManager
 409      */
 410     public void reset(XMLComponentManager componentManager)
 411     throws XMLConfigurationException {
 412 
 413         super.reset(componentManager);
 414         init();
 415 
 416     } // reset(XMLComponentManager)
 417 
 418     // this is made for something like XMLDTDLoader--XMLComponentManager-free operation...


   1 /*
   2  * Copyright (c) 2003, 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.Constants;
  25 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
  26 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
  27 import com.sun.org.apache.xerces.internal.impl.XMLEntityHandler;
  28 import com.sun.org.apache.xerces.internal.util.SymbolTable;
  29 import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl;
  30 import com.sun.org.apache.xerces.internal.util.XMLChar;
  31 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
  32 import com.sun.org.apache.xerces.internal.utils.XMLLimitAnalyzer;
  33 import com.sun.org.apache.xerces.internal.utils.XMLSecurityManager;
  34 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler;
  35 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler;
  36 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
  37 import com.sun.org.apache.xerces.internal.xni.XMLString;
  38 import com.sun.org.apache.xerces.internal.xni.XNIException;
  39 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent;
  40 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager;
  41 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException;
  42 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner;
  43 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource;
  44 import com.sun.org.apache.xerces.internal.xni.Augmentations;
  45 import com.sun.xml.internal.stream.dtd.nonvalidating.DTDGrammar;
  46 import java.io.EOFException;
  47 import java.io.IOException;


  48 
  49 /**
  50  * This class is responsible for scanning the declarations found
  51  * in the internal and external subsets of a DTD in an XML document.
  52  * The scanner acts as the sources for the DTD information which is
  53  * communicated to the DTD handlers.
  54  * <p>
  55  * This component requires the following features and properties from the
  56  * component manager that uses it:
  57  * <ul>
  58  *  <li>http://xml.org/sax/features/validation</li>
  59  *  <li>http://apache.org/xml/features/scanner/notify-char-refs</li>
  60  *  <li>http://apache.org/xml/properties/internal/symbol-table</li>
  61  *  <li>http://apache.org/xml/properties/internal/error-reporter</li>
  62  *  <li>http://apache.org/xml/properties/internal/entity-manager</li>
  63  * </ul>
  64  *
  65  * @author Arnaud  Le Hors, IBM
  66  * @author Andy Clark, IBM
  67  * @author Glenn Marcy, IBM


 369                 // we're done scanning DTD.
 370                 fLimitAnalyzer.reset(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT);
 371                 return false;
 372             }
 373         } while (complete);
 374 
 375         // return that there is more to scan
 376         return true;
 377 
 378     } // scanDTDInternalSubset(boolean,boolean,boolean):boolean
 379 
 380     /**
 381      * Skip the DTD if javax.xml.stream.supportDTD is false.
 382      *
 383      * @param supportDTD The value of the property javax.xml.stream.supportDTD.
 384      * @return true if DTD is skipped, false otherwise.
 385      * @throws java.io.IOException if i/o error occurs
 386      */
 387     @Override
 388     public boolean skipDTD(boolean supportDTD) throws IOException {
 389         if (supportDTD)
 390             return false;



 391 
 392         fStringBuffer.clear();
 393         while (fEntityScanner.scanData("]", fStringBuffer)) {
 394             int c = fEntityScanner.peekChar();
 395             if (c != -1) {
 396                 if (XMLChar.isHighSurrogate(c)) {
 397                     scanSurrogates(fStringBuffer);
 398                 }
 399                 if (isInvalidLiteral(c)) {
 400                     reportFatalError("InvalidCharInDTD",
 401                         new Object[] { Integer.toHexString(c) });
 402                     fEntityScanner.scanChar();
 403                 }
 404             }
 405         }
 406         fEntityScanner.fCurrentEntity.position--;
 407         return true;
 408     }
 409 
 410     //
 411     // XMLComponent methods
 412     //
 413 
 414     /**
 415      * reset
 416      *
 417      * @param componentManager
 418      */
 419     public void reset(XMLComponentManager componentManager)
 420     throws XMLConfigurationException {
 421 
 422         super.reset(componentManager);
 423         init();
 424 
 425     } // reset(XMLComponentManager)
 426 
 427     // this is made for something like XMLDTDLoader--XMLComponentManager-free operation...


< prev index next >