286N/A/*
286N/A * reserved comment block
286N/A * DO NOT REMOVE OR ALTER!
286N/A */
286N/A/*
286N/A * The Apache Software License, Version 1.1
286N/A *
286N/A *
286N/A * Copyright (c) 1999-2004 The Apache Software Foundation.
286N/A * All rights reserved.
286N/A *
286N/A * Redistribution and use in source and binary forms, with or without
286N/A * modification, are permitted provided that the following conditions
286N/A * are met:
286N/A *
286N/A * 1. Redistributions of source code must retain the above copyright
286N/A * notice, this list of conditions and the following disclaimer.
286N/A *
286N/A * 2. Redistributions in binary form must reproduce the above copyright
286N/A * notice, this list of conditions and the following disclaimer in
286N/A * the documentation and/or other materials provided with the
286N/A * distribution.
286N/A *
286N/A * 3. The end-user documentation included with the redistribution,
286N/A * if any, must include the following acknowledgment:
286N/A * "This product includes software developed by the
286N/A * Apache Software Foundation (http://www.apache.org/)."
286N/A * Alternately, this acknowledgment may appear in the software itself,
286N/A * if and wherever such third-party acknowledgments normally appear.
286N/A *
286N/A * 4. The names "Xerces" and "Apache Software Foundation" must
286N/A * not be used to endorse or promote products derived from this
286N/A * software without prior written permission. For written
286N/A * permission, please contact apache@apache.org.
286N/A *
286N/A * 5. Products derived from this software may not be called "Apache",
286N/A * nor may "Apache" appear in their name, without prior written
286N/A * permission of the Apache Software Foundation.
286N/A *
286N/A * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
286N/A * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
286N/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
286N/A * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
286N/A * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
286N/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
286N/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
286N/A * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
286N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
286N/A * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
286N/A * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
286N/A * SUCH DAMAGE.
286N/A * ====================================================================
286N/A *
286N/A * This software consists of voluntary contributions made by many
286N/A * individuals on behalf of the Apache Software Foundation and was
286N/A * originally based on software copyright (c) 1999, International
286N/A * Business Machines, Inc., http://www.apache.org. For more
286N/A * information on the Apache Software Foundation, please see
286N/A * <http://www.apache.org/>.
286N/A */
286N/A
286N/Apackage com.sun.org.apache.xerces.internal.impl;
286N/A
286N/Aimport java.io.IOException;
286N/A
286N/Aimport com.sun.org.apache.xerces.internal.util.SymbolTable;
286N/Aimport com.sun.org.apache.xerces.internal.util.XML11Char;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLChar;
286N/Aimport com.sun.org.apache.xerces.internal.util.XMLStringBuffer;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XMLString;
286N/Aimport com.sun.org.apache.xerces.internal.xni.XNIException;
286N/A
286N/A/**
286N/A * This class is responsible for scanning the declarations found
286N/A * in the internal and external subsets of a DTD in an XML document.
286N/A * The scanner acts as the sources for the DTD information which is
286N/A * communicated to the DTD handlers.
286N/A * <p>
286N/A * This component requires the following features and properties from the
286N/A * component manager that uses it:
286N/A * <ul>
286N/A * <li>http://xml.org/sax/features/validation</li>
286N/A * <li>http://apache.org/xml/features/scanner/notify-char-refs</li>
286N/A * <li>http://apache.org/xml/properties/internal/symbol-table</li>
286N/A * <li>http://apache.org/xml/properties/internal/error-reporter</li>
286N/A * <li>http://apache.org/xml/properties/internal/entity-manager</li>
286N/A * </ul>
286N/A *
286N/A * @xerces.internal
286N/A *
286N/A * @author Arnaud Le Hors, IBM
286N/A * @author Andy Clark, IBM
286N/A * @author Glenn Marcy, IBM
286N/A * @author Eric Ye, IBM
286N/A *
286N/A */
286N/Apublic class XML11DTDScannerImpl
286N/A extends XMLDTDScannerImpl {
286N/A
286N/A /** Array of 3 strings. */
286N/A private String[] fStrings = new String[3];
286N/A
286N/A /** String. */
286N/A private XMLString fString = new XMLString();
286N/A
286N/A /** String buffer. */
286N/A private XMLStringBuffer fStringBuffer = new XMLStringBuffer();
286N/A
286N/A /** String buffer. */
286N/A private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();
286N/A private XMLStringBuffer fStringBuffer3 = new XMLStringBuffer();
286N/A
286N/A //
286N/A // Constructors
286N/A //
286N/A
286N/A /** Default constructor. */
286N/A public XML11DTDScannerImpl() {super();} // <init>()
286N/A
286N/A /** Constructor for he use of non-XMLComponentManagers. */
286N/A public XML11DTDScannerImpl(SymbolTable symbolTable,
286N/A XMLErrorReporter errorReporter, XMLEntityManager entityManager) {
286N/A super(symbolTable, errorReporter, entityManager);
286N/A }
286N/A
286N/A //
286N/A // XMLDTDScanner methods
286N/A //
286N/A
286N/A //
286N/A // XMLScanner methods
286N/A //
286N/A // NOTE: this is a carbon copy of the code in XML11DocumentScannerImpl;
286N/A // we need to override these methods in both places. Ah for
286N/A // multiple inheritance...
286N/A // This needs to be refactored!!! - NG
286N/A /**
286N/A * Scans public ID literal.
286N/A *
286N/A * [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
286N/A * [13] PubidChar::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
286N/A *
286N/A * The returned string is normalized according to the following rule,
286N/A * from http://www.w3.org/TR/REC-xml#dt-pubid:
286N/A *
286N/A * Before a match is attempted, all strings of white space in the public
286N/A * identifier must be normalized to single space characters (#x20), and
286N/A * leading and trailing white space must be removed.
286N/A *
286N/A * @param literal The string to fill in with the public ID literal.
286N/A * @return True on success.
286N/A *
286N/A * <strong>Note:</strong> This method uses fStringBuffer, anything in it at
286N/A * the time of calling is lost.
286N/A */
286N/A protected boolean scanPubidLiteral(XMLString literal)
286N/A throws IOException, XNIException
286N/A {
286N/A int quote = fEntityScanner.scanChar();
286N/A if (quote != '\'' && quote != '"') {
286N/A reportFatalError("QuoteRequiredInPublicID", null);
286N/A return false;
286N/A }
286N/A
286N/A fStringBuffer.clear();
286N/A // skip leading whitespace
286N/A boolean skipSpace = true;
286N/A boolean dataok = true;
286N/A while (true) {
286N/A int c = fEntityScanner.scanChar();
286N/A // REVISIT: it could really only be \n or 0x20; all else is normalized, no? - neilg
286N/A if (c == ' ' || c == '\n' || c == '\r' || c == 0x85 || c == 0x2028) {
286N/A if (!skipSpace) {
286N/A // take the first whitespace as a space and skip the others
286N/A fStringBuffer.append(' ');
286N/A skipSpace = true;
286N/A }
286N/A }
286N/A else if (c == quote) {
286N/A if (skipSpace) {
286N/A // if we finished on a space let's trim it
286N/A fStringBuffer.length--;
286N/A }
286N/A literal.setValues(fStringBuffer);
286N/A break;
286N/A }
286N/A else if (XMLChar.isPubid(c)) {
286N/A fStringBuffer.append((char)c);
286N/A skipSpace = false;
286N/A }
286N/A else if (c == -1) {
286N/A reportFatalError("PublicIDUnterminated", null);
286N/A return false;
286N/A }
286N/A else {
286N/A dataok = false;
286N/A reportFatalError("InvalidCharInPublicID",
286N/A new Object[]{Integer.toHexString(c)});
286N/A }
286N/A }
286N/A return dataok;
286N/A }
286N/A
286N/A /**
286N/A * Normalize whitespace in an XMLString converting all whitespace
286N/A * characters to space characters.
286N/A */
286N/A protected void normalizeWhitespace(XMLString value) {
286N/A int end = value.offset + value.length;
286N/A for (int i = value.offset; i < end; ++i) {
286N/A int c = value.ch[i];
286N/A if (XMLChar.isSpace(c)) {
286N/A value.ch[i] = ' ';
286N/A }
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Normalize whitespace in an XMLString converting all whitespace
286N/A * characters to space characters.
286N/A */
286N/A protected void normalizeWhitespace(XMLString value, int fromIndex) {
286N/A int end = value.offset + value.length;
286N/A for (int i = value.offset + fromIndex; i < end; ++i) {
286N/A int c = value.ch[i];
286N/A if (XMLChar.isSpace(c)) {
286N/A value.ch[i] = ' ';
286N/A }
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Checks whether this string would be unchanged by normalization.
286N/A *
286N/A * @return -1 if the value would be unchanged by normalization,
286N/A * otherwise the index of the first whitespace character which
286N/A * would be transformed.
286N/A */
286N/A protected int isUnchangedByNormalization(XMLString value) {
286N/A int end = value.offset + value.length;
286N/A for (int i = value.offset; i < end; ++i) {
286N/A int c = value.ch[i];
286N/A if (XMLChar.isSpace(c)) {
286N/A return i - value.offset;
286N/A }
286N/A }
286N/A return -1;
286N/A }
286N/A
286N/A // returns true if the given character is not
286N/A // valid with respect to the version of
286N/A // XML understood by this scanner.
286N/A protected boolean isInvalid(int value) {
286N/A return (!XML11Char.isXML11Valid(value));
286N/A } // isInvalid(int): boolean
286N/A
286N/A // returns true if the given character is not
286N/A // valid or may not be used outside a character reference
286N/A // with respect to the version of XML understood by this scanner.
286N/A protected boolean isInvalidLiteral(int value) {
286N/A return (!XML11Char.isXML11ValidLiteral(value));
286N/A } // isInvalidLiteral(int): boolean
286N/A
286N/A // returns true if the given character is
286N/A // a valid nameChar with respect to the version of
286N/A // XML understood by this scanner.
286N/A protected boolean isValidNameChar(int value) {
286N/A return (XML11Char.isXML11Name(value));
286N/A } // isValidNameChar(int): boolean
286N/A
286N/A // returns true if the given character is
286N/A // a valid nameStartChar with respect to the version of
286N/A // XML understood by this scanner.
286N/A protected boolean isValidNameStartChar(int value) {
286N/A return (XML11Char.isXML11NameStart(value));
286N/A } // isValidNameStartChar(int): boolean
286N/A
286N/A // returns true if the given character is
286N/A // a valid NCName character with respect to the version of
286N/A // XML understood by this scanner.
286N/A protected boolean isValidNCName(int value) {
286N/A return (XML11Char.isXML11NCName(value));
286N/A } // isValidNCName(int): boolean
286N/A
286N/A // returns true if the given character is
286N/A // a valid high surrogate for a nameStartChar
286N/A // with respect to the version of XML understood
286N/A // by this scanner.
286N/A protected boolean isValidNameStartHighSurrogate(int value) {
286N/A return XML11Char.isXML11NameHighSurrogate(value);
286N/A } // isValidNameStartHighSurrogate(int): boolean
286N/A
286N/A // note that, according to 4.3.4 of the XML 1.1 spec, XML 1.1
286N/A // documents may invoke 1.0 entities; thus either version decl (or none!)
286N/A // is allowed to appear in this context
286N/A protected boolean versionSupported(String version) {
286N/A return version.equals("1.1") || version.equals ("1.0");
286N/A } // versionSupported(String): boolean
286N/A
286N/A // returns the error message key for unsupported
286N/A // versions of XML with respect to the version of
286N/A // XML understood by this scanner.
286N/A protected String getVersionNotSupportedKey () {
286N/A return "VersionNotSupported11";
286N/A } // getVersionNotSupportedKey: String
286N/A
286N/A} // class XML11DTDScannerImpl