⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xml11documentscannerimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * The Apache Software License, Version 1.1 * * * Copyright (c) 1999-2004 The Apache Software Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by the *        Apache Software Foundation (http://www.apache.org/)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Xerces" and "Apache Software Foundation" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", *    nor may "Apache" appear in their name, without prior written *    permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation and was * originally based on software copyright (c) 1999, International * Business Machines, Inc., http://www.apache.org.  For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package com.sun.org.apache.xerces.internal.impl;import java.io.IOException;import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;import com.sun.org.apache.xerces.internal.util.XML11Char;import com.sun.org.apache.xerces.internal.util.XMLChar;import com.sun.org.apache.xerces.internal.util.XMLStringBuffer;import com.sun.org.apache.xerces.internal.xni.XMLString;import com.sun.org.apache.xerces.internal.xni.XNIException;/** * This class is responsible for scanning XML document structure * and content. The scanner acts as the source for the document * information which is communicated to the document handler. * <p> * This component requires the following features and properties from the * component manager that uses it: * <ul> *  <li>http://xml.org/sax/features/namespaces</li> *  <li>http://xml.org/sax/features/validation</li> *  <li>http://apache.org/xml/features/nonvalidating/load-external-dtd</li> *  <li>http://apache.org/xml/features/scanner/notify-char-refs</li> *  <li>http://apache.org/xml/features/scanner/notify-builtin-refs</li> *  <li>http://apache.org/xml/properties/internal/symbol-table</li> *  <li>http://apache.org/xml/properties/internal/error-reporter</li> *  <li>http://apache.org/xml/properties/internal/entity-manager</li> *  <li>http://apache.org/xml/properties/internal/dtd-scanner</li> * </ul> * * @xerces.internal * * @author Glenn Marcy, IBM * @author Andy Clark, IBM * @author Arnaud  Le Hors, IBM * @author Eric Ye, IBM * * @version $Id: XML11DocumentScannerImpl.java,v 1.2 2005/08/16 22:51:38 jeffsuttor Exp $ */public class XML11DocumentScannerImpl    extends XMLDocumentScannerImpl {    /** Array of 3 strings. */    private String[] fStrings = new String[3];        /** String buffer. */    private XMLStringBuffer fStringBuffer = new XMLStringBuffer();    private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer();    private XMLStringBuffer fStringBuffer3 = new XMLStringBuffer();    //    // Constructors    //    /** Default constructor. */    public XML11DocumentScannerImpl() {super();} // <init>()    //    // overridden methods    //    // XMLDocumentFragmentImpl methods    /**     * Scans element content.     *     * @return Returns the next character on the stream.     */    protected int scanContent(XMLStringBuffer content) throws IOException, XNIException {                fTempString.length = 0;        int c = fEntityScanner.scanContent(fTempString);        content.append(fTempString);                if (c == '\r' || c == 0x85 || c == 0x2028) {            // happens when there is the character reference &#13;            // but scanContent doesn't do entity expansions...            // is this *really* necessary???  - NG            fEntityScanner.scanChar();            content.append((char)c);            c = -1;        }        /*if (fDocumentHandler != null && content.length > 0) {            fDocumentHandler.characters(content, null);        } */        if (c == ']') {            content.append((char)fEntityScanner.scanChar());            // remember where we are in case we get an endEntity before we            // could flush the buffer out - this happens when we're parsing an            // entity which ends with a ]            fInScanContent = true;            //            // We work on a single character basis to handle cases such as:            // ']]]>' which we might otherwise miss.            //            if (fEntityScanner.skipChar(']')) {                content.append(']');                 while (fEntityScanner.skipChar(']')) {                    content.append(']');                 }                if (fEntityScanner.skipChar('>')) {                    reportFatalError("CDEndInContent", null);                }            }            /*if (fDocumentHandler != null && fStringBuffer.length != 0) {                fDocumentHandler.characters(fStringBuffer, null);            }*/            fInScanContent = false;            c = -1;        }        return c;    } // scanContent():int    /**     * Scans an attribute value and normalizes whitespace converting all     * whitespace characters to space characters.     *      * [10] AttValue ::= '"' ([^<&"] | Reference)* '"' | "'" ([^<&'] | Reference)* "'"     *     * @param value The XMLString to fill in with the value.     * @param nonNormalizedValue The XMLString to fill in with the      *                           non-normalized value.     * @param atName The name of the attribute being parsed (for error msgs).     * @param checkEntities true if undeclared entities should be reported as VC violation,       *                      false if undeclared entities should be reported as WFC violation.     * @param eleName The name of element to which this attribute belongs.     *     * @return true if the non-normalized and normalized value are the same     *      * <strong>Note:</strong> This method uses fStringBuffer2, anything in it     * at the time of calling is lost.     **/    protected boolean scanAttributeValue(XMLString value,                                       XMLString nonNormalizedValue,                                      String atName,                                      boolean checkEntities,String eleName)        throws IOException, XNIException    {        // quote        int quote = fEntityScanner.peekChar();        if (quote != '\'' && quote != '"') {            reportFatalError("OpenQuoteExpected", new Object[]{eleName,atName});        }        fEntityScanner.scanChar();        int entityDepth = fEntityDepth;        int c = fEntityScanner.scanLiteral(quote, value);        if (DEBUG_ATTR_NORMALIZATION) {            System.out.println("** scanLiteral -> \""                               + value.toString() + "\"");        }                int fromIndex = 0;        if (c == quote && (fromIndex = isUnchangedByNormalization(value)) == -1) {            /** Both the non-normalized and normalized attribute values are equal. **/            nonNormalizedValue.setValues(value);            int cquote = fEntityScanner.scanChar();            if (cquote != quote) {                reportFatalError("CloseQuoteExpected", new Object[]{eleName,atName});            }            return true;        }        fStringBuffer2.clear();        fStringBuffer2.append(value);        normalizeWhitespace(value, fromIndex);        if (DEBUG_ATTR_NORMALIZATION) {            System.out.println("** normalizeWhitespace -> \""                               + value.toString() + "\"");        }        if (c != quote) {            fScanningAttribute = true;            fStringBuffer.clear();            do {                fStringBuffer.append(value);                if (DEBUG_ATTR_NORMALIZATION) {                    System.out.println("** value2: \""                                       + fStringBuffer.toString() + "\"");                }                if (c == '&') {                    fEntityScanner.skipChar('&');                    if (entityDepth == fEntityDepth) {                        fStringBuffer2.append('&');                    }                    if (fEntityScanner.skipChar('#')) {                        if (entityDepth == fEntityDepth) {                            fStringBuffer2.append('#');                        }                        int ch = scanCharReferenceValue(fStringBuffer, fStringBuffer2);                        if (ch != -1) {                            if (DEBUG_ATTR_NORMALIZATION) {                                System.out.println("** value3: \""                                                   + fStringBuffer.toString()                                                   + "\"");                            }                        }                    }                    else {                        String entityName = fEntityScanner.scanName();                        if (entityName == null) {                            reportFatalError("NameRequiredInReference", null);                        }                        else if (entityDepth == fEntityDepth) {                            fStringBuffer2.append(entityName);                        }                        if (!fEntityScanner.skipChar(';')) {                            reportFatalError("SemicolonRequiredInReference",                                             new Object []{entityName});                        }                        else if (entityDepth == fEntityDepth) {                            fStringBuffer2.append(';');                        }                        if (entityName == fAmpSymbol) {                            fStringBuffer.append('&');                            if (DEBUG_ATTR_NORMALIZATION) {                                System.out.println("** value5: \""                                                   + fStringBuffer.toString()                                                   + "\"");                            }                        }                        else if (entityName == fAposSymbol) {                            fStringBuffer.append('\'');                            if (DEBUG_ATTR_NORMALIZATION) {                                System.out.println("** value7: \""                                                   + fStringBuffer.toString()                                                   + "\"");                            }                        }                        else if (entityName == fLtSymbol) {                            fStringBuffer.append('<');                            if (DEBUG_ATTR_NORMALIZATION) {                                System.out.println("** value9: \""                                                   + fStringBuffer.toString()                                                   + "\"");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -