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

📄 xmldocumentfragmentscannerimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                reportFatalError("ElementUnterminated",                        new Object[]{fElementQName.rawname});            }            fEmptyElement = true;            return true;        } else if (!isValidNameStartChar(c) || !sawSpace) {            reportFatalError("ElementUnterminated", new Object[]{fElementQName.rawname});        }                return false;    }        public boolean hasAttributes(){        return fAttributes.getLength() > 0 ? true : false ;    }            /**     * Scans an attribute.     * <p>     * <pre>     * [41] Attribute ::= Name Eq AttValue     * </pre>     * <p>     * <strong>Note:</strong> This method assumes that the next     * character on the stream is the first character of the attribute     * name.     * <p>     * <strong>Note:</strong> This method uses the fAttributeQName and     * fQName variables. The contents of these variables will be     * destroyed.     *     * @param attributes The attributes list for the scanned attribute.     */        /**     * protected void scanAttribute(AttributeIteratorImpl attributes)     * throws IOException, XNIException {     * if (DEBUG_START_END_ELEMENT) System.out.println(">>> scanAttribute()");     *     *     * // name     * if (fNamespaces) {     * fEntityScanner.scanQName(fAttributeQName);     * }     * else {     * String name = fEntityScanner.scanName();     * fAttributeQName.setValues(null, name, name, null);     * }     *     * // equals     * fEntityScanner.skipSpaces();     * if (!fEntityScanner.skipChar('=')) {     * reportFatalError("EqRequiredInAttribute",     * new Object[]{fAttributeQName.rawname});     * }     * fEntityScanner.skipSpaces();     *     *     * // content     * int oldLen = attributes.getLength();     */    /**xxx there is one check of duplicate attribute that has been removed.     * attributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, null);     *     * // WFC: Unique Att Spec     * if (oldLen == attributes.getLength()) {     * reportFatalError("AttributeNotUnique",     * new Object[]{fCurrentElement.rawname,     * fAttributeQName.rawname});     * }     */        /*        //REVISIT: one more case needs to be included: external PE and standalone is no        boolean isVC =  fHasExternalDTD && !fStandalone;        scanAttributeValue(fTempString, fTempString2,                           fAttributeQName.rawname, attributes,                           oldLen, isVC);             //attributes.setValue(oldLen, fTempString.toString());        //attributes.setNonNormalizedValue(oldLen, fTempString2.toString());        //attributes.setSpecified(oldLen, true);             AttributeImpl attribute = new AttributeImpl(fAttributeQName.prefix,fAttributeQName.localpart,fAttributeQName.uri,fTempString.toString(),fTempString2.toString(),XMLSymbols.fCDATASymbol,true);        fAttributes.addAttribute(attribute);        if (DEBUG_START_END_ELEMENT) System.out.println("<<< scanAttribute()");    } // scanAttribute(XMLAttributes)          */        /** return the attribute iterator implementation */    public XMLAttributesIteratorImpl getAttributeIterator(){        if(dtdGrammarUtil != null && fAddDefaultAttr){            dtdGrammarUtil.addDTDDefaultAttrs(fElementQName,fAttributes);            fAddDefaultAttr = false;        }        return fAttributes;    }        /** return if the doucment is standalone */    public boolean isStandAlone(){        return fStandalone ;    }    /**     * Scans an attribute name value pair.     * <p>     * <pre>     * [41] Attribute ::= Name Eq AttValue     * </pre>     * <p>     * <strong>Note:</strong> This method assumes that the next     * character on the stream is the first character of the attribute     * name.     * <p>     * <strong>Note:</strong> This method uses the fAttributeQName and     * fQName variables. The contents of these variables will be     * destroyed.     *     * @param attributes The attributes list for the scanned attribute.     */        protected void scanAttribute(XMLAttributes attributes)    throws IOException, XNIException {        if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +">>> scanAttribute()");                // name        if (fNamespaces) {            fEntityScanner.scanQName(fAttributeQName);        } else {            String name = fEntityScanner.scanName();            fAttributeQName.setValues(null, name, name, null);        }                // equals        fEntityScanner.skipSpaces();        if (!fEntityScanner.skipChar('=')) {            reportFatalError("EqRequiredInAttribute",                new Object[] {fCurrentElement.rawname, fAttributeQName.rawname});        }        fEntityScanner.skipSpaces();                int attIndex = 0 ;        //REVISIT: one more case needs to be included: external PE and standalone is no        boolean isVC =  fHasExternalDTD && !fStandalone;        //fTempString would store attribute value        ///fTempString2 would store attribute non-normalized value                //this function doesn't use 'attIndex'. We are adding the attribute later        //after we have figured out that current attribute is not namespace declaration        //since scanAttributeValue doesn't use attIndex parameter therefore we        //can safely add the attribute later..        XMLString tmpStr = getString();                scanAttributeValue(tmpStr, fTempString2,                fAttributeQName.rawname, attributes,                attIndex, isVC);        // content        int oldLen = attributes.getLength();        //if the attribute name already exists.. new value is replaced with old value        attIndex = attributes.addAttribute(fAttributeQName, XMLSymbols.fCDATASymbol, null);                // WFC: Unique Att Spec        //attributes count will be same if the current attribute  name already exists for this element name.        //this means there are two duplicate attributes.        if (oldLen == attributes.getLength()) {            reportFatalError("AttributeNotUnique",                    new Object[]{fCurrentElement.rawname,                            fAttributeQName.rawname});        }                //tmpString contains attribute value        //we are passing null as the attribute value        attributes.setValue(attIndex, null, tmpStr);        ///xxx: nonNormalizedValue is not being set as it is not required by SAX & DOM        //attributes.setNonNormalizedValue(oldLen, fTempString2.toString());        attributes.setSpecified(attIndex, true);                if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +"<<< scanAttribute()");            } // scanAttribute(XMLAttributes)        /**     * Scans element content.     *     * @return Returns the next character on the stream.     */    //CHANGED:    //EARLIER: scanContent()    //NOW: scanContent(XMLStringBuffer)    //It makes things easy if this functions takes XMLStringBuffer as parameter..    //this function appends the data to the buffer.    protected int scanContent(XMLStringBuffer content) throws IOException, XNIException {        //set the fTempString length to 0 before passing it on to scanContent        //scanContent sets the correct co-ordinates as per the content read        fTempString.length = 0;        int c = fEntityScanner.scanContent(fTempString);        content.append(fTempString);        fTempString.length = 0;        if (c == '\r') {            // happens when there is the character reference &#13;            //xxx: We know the next chracter.. we should just skip it and add ']' directlry            fEntityScanner.scanChar();            content.append((char)c);            c = -1;        } else if (c == ']') {            //fStringBuffer.clear();            //xxx: We know the next chracter.. we should just skip it and add ']' directlry            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);                }            }            fInScanContent = false;            c = -1;        }        if (fDocumentHandler != null && content.length > 0) {            //fDocumentHandler.characters(content, null);        }        return c;            } // scanContent():int            /**     * Scans a CDATA section.     * <p>     * <strong>Note:</strong> This method uses the fTempString and     * fStringBuffer variables.     *     * @param complete True if the CDATA section is to be scanned     *                 completely.     *     * @return True if CDATA is completely scanned.     */    //CHANGED:    protected boolean scanCDATASection(XMLStringBuffer contentBuffer, boolean complete)    throws IOException, XNIException {                // call handler        if (fDocumentHandler != null) {            //fDocumentHandler.startCDATA(null);        }                while (true) {            //scanData will fill the contentBuffer            if (!fEntityScanner.scanData("]]>", contentBuffer)) {                break ;                /** We dont need all this code if we pass ']]>' as delimeter..                 * int brackets = 2;                 * while (fEntityScanner.skipChar(']')) {                 * brackets++;                 * }                 *                 * //When we find more than 2 square brackets                 * if (fDocumentHandler != null && brackets > 2) {                 * //we dont need to clear the buffer..                 * //contentBuffer.clear();                 * for (int i = 2; i < brackets; i++) {                 * contentBuffer.append(']');                 * }                 * fDocumentHandler.characters(contentBuffer, null);                 * }                 *                 * if (fEntityScanner.skipChar('>')) {                 * break;                 * }                 * if (fDocumentHandler != null) {                 * //we dont need to clear the buffer now..                 * //contentBuffer.clear();                 * contentBuffer.append("]]");                 * fDocumentHandler.characters(contentBuffer, null);                 * }                 **/            } else {                int c = fEntityScanner.peekChar();                if (c != -1 && isInvalidLiteral(c)) {                    if (XMLChar.isHighSurrogate(c)) {                        //contentBuffer.clear();                        //scan surrogates if any....                        scanSurrogates(contentBuffer);                    } else {                        reportFatalError("InvalidCharInCDSect",                                new Object[]{Integer.toString(c,16)});                                fEntityScanner.scanChar();                    }                }                //by this time we have also read surrogate contents if any...                if (fDocumentHandler != null) {                    //fDocumentHandler.characters(contentBuffer, null);                }            }        }        fMarkupDepth--;                if (fDocumentHandler != null && contentBuffer.length > 0) {            //fDocumentHandler.characters(contentBuffer, null);        }                // call handler        if (fDocumentHandler != null) {            //fDocumentHandler.endCDATA(null);        }                return true;            } // scanCDATASection(XMLStringBuffer, boolean):boolean        /**     * Scans an end element.     * <p>     * <pre>     * [42] ETag ::= '&lt;/' Name S? '>'     * </pre>     * <p>     * <strong>Note:</strong> This method uses the fElementQName variable.     * The contents of this variable will be destroyed. The caller should     * copy the needed information out of this variable before calling     * this method.     *     * @return The element depth.     */    protected int scanEndElement() throws IOException, XNIException {        if (DEBUG_START_END_ELEMENT) System.out.println(this.getClass().toString() +">>> scanEndElement()");                // pop context        QName endElementName = fElementStack.popElement();                String rawname = endElementName.rawname;        if(DEBUG)System.ou

⌨️ 快捷键说明

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