xmldtdscannerimpl.java

来自「JAVA的一些源码 JAVA2 STANDARD EDITION DEVELO」· Java 代码 · 共 1,765 行 · 第 1/5 页

JAVA
1,765
字号
        fEntityManager.setEntityHandler(this);        fStandalone = standalone;        if (fScannerState == SCANNER_STATE_TEXT_DECL) {            // call handler            if (fDTDHandler != null) {                fDTDHandler.startDTD(fEntityScanner, null);                fStartDTDCalled = true;            }            // set starting state for internal subset            setScannerState(SCANNER_STATE_MARKUP_DECL);        }        // keep dispatching "events"        do {            if (!scanDecls(complete)) {                // call handler                if (fDTDHandler != null && hasExternalSubset == false) {                    fDTDHandler.endDTD(null);                }                // we're done, set starting state for external subset                setScannerState(SCANNER_STATE_TEXT_DECL);                return false;            }        } while (complete);        // return that there is more to scan        return true;    } // scanDTDInternalSubset(boolean,boolean,boolean):boolean    //    // XMLComponent methods    //    /**     * reset     *      * @param componentManager      */    public void reset(XMLComponentManager componentManager)        throws XMLConfigurationException {                super.reset(componentManager);        init();    } // reset(XMLComponentManager)    // this is made for something like XMLDTDLoader--XMLComponentManager-free operation...    public void reset() {        super.reset();        init();    }    /**     * Returns a list of feature identifiers that are recognized by     * this component. This method may return null if no features     * are recognized by this component.     */    public String[] getRecognizedFeatures() {        return (String[])(RECOGNIZED_FEATURES.clone());    } // getRecognizedFeatures():String[]    /**     * Returns a list of property identifiers that are recognized by     * this component. This method may return null if no properties     * are recognized by this component.     */    public String[] getRecognizedProperties() {        return (String[])(RECOGNIZED_PROPERTIES.clone());    } // getRecognizedProperties():String[]    /**      * Returns the default state for a feature, or null if this     * component does not want to report a default value for this     * feature.     *     * @param featureId The feature identifier.     *     * @since Xerces 2.2.0     */    public Boolean getFeatureDefault(String featureId) {        for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) {            if (RECOGNIZED_FEATURES[i].equals(featureId)) {                return FEATURE_DEFAULTS[i];            }        }        return null;    } // getFeatureDefault(String):Boolean    /**      * Returns the default state for a property, or null if this     * component does not want to report a default value for this     * property.      *     * @param propertyId The property identifier.     *     * @since Xerces 2.2.0     */    public Object getPropertyDefault(String propertyId) {        for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) {            if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) {                return PROPERTY_DEFAULTS[i];            }        }        return null;    } // getPropertyDefault(String):Object    //    // XMLDTDSource methods    //    /**     * setDTDHandler     *      * @param dtdHandler      */    public void setDTDHandler(XMLDTDHandler dtdHandler) {        fDTDHandler = dtdHandler;    } // setDTDHandler(XMLDTDHandler)    /**     * getDTDHandler     *      * @return the XMLDTDHandler     */    public XMLDTDHandler getDTDHandler() {        return fDTDHandler;    } // getDTDHandler():  XMLDTDHandler    //    // XMLDTDContentModelSource methods    //    /**     * setDTDContentModelHandler     *      * @param dtdContentModelHandler      */    public void setDTDContentModelHandler(XMLDTDContentModelHandler                                          dtdContentModelHandler) {        fDTDContentModelHandler = dtdContentModelHandler;    } // setDTDContentModelHandler    /**     * getDTDContentModelHandler     *      * @return XMLDTDContentModelHandler      */    public XMLDTDContentModelHandler getDTDContentModelHandler() {        return fDTDContentModelHandler ;    } // setDTDContentModelHandler    //    // XMLEntityHandler methods    //    /**     * This method notifies of the start of an entity. The DTD has the      * pseudo-name of "[dtd]" parameter entity names start with '%'; and      * general entities are just specified by their name.     *      * @param name     The name of the entity.     * @param identifier The resource identifier.     * @param encoding The auto-detected IANA encoding name of the entity     *                 stream. This value will be null in those situations     *                 where the entity encoding is not auto-detected (e.g.     *                 internal entities or a document entity that is     *                 parsed from a java.io.Reader).     * @param augs     Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void startEntity(String name,                             XMLResourceIdentifier identifier,                            String encoding, Augmentations augs) throws XNIException {        super.startEntity(name, identifier, encoding, augs);        boolean dtdEntity = name.equals("[dtd]");        if (dtdEntity) {            // call handler            if (fDTDHandler != null && !fStartDTDCalled ) {                fDTDHandler.startDTD(fEntityScanner, null);            }            if (fDTDHandler != null) {                fDTDHandler.startExternalSubset(identifier,null);            }            fEntityManager.startExternalSubset();            fExtEntityDepth++;        }        else if (name.charAt(0) == '%') {            pushPEStack(fMarkUpDepth, fReportEntity);            if (fEntityScanner.isExternal()) {                fExtEntityDepth++;            }        }        // call handler        if (fDTDHandler != null && !dtdEntity && fReportEntity) {            fDTDHandler.startParameterEntity(name, identifier, encoding, augs);        }    } // startEntity(String,XMLResourceIdentifier,String)    /**     * This method notifies the end of an entity. The DTD has the pseudo-name     * of "[dtd]" parameter entity names start with '%'; and general entities      * are just specified by their name.     *      * @param name The name of the entity.     * @param augs Additional information that may include infoset augmentations     *     * @throws XNIException Thrown by handler to signal an error.     */    public void endEntity(String name, Augmentations augs)         throws XNIException {        super.endEntity(name, augs);        // if there is no data after the doctype        //          if (fScannerState == SCANNER_STATE_END_OF_INPUT)            return;        // Handle end of PE        boolean reportEntity = fReportEntity;        if (name.startsWith("%")) {            reportEntity = peekReportEntity();            // check well-formedness of the enity            int startMarkUpDepth = popPEStack();            // throw fatalError if this entity was incomplete and            // was a freestanding decl            if(startMarkUpDepth == 0 &&                    startMarkUpDepth < fMarkUpDepth) {                fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,                                   "ILL_FORMED_PARAMETER_ENTITY_WHEN_USED_IN_DECL",                                   new Object[]{ fEntityManager.fCurrentEntity.name},                                   XMLErrorReporter.SEVERITY_FATAL_ERROR);            }            if (startMarkUpDepth != fMarkUpDepth) {                reportEntity = false;                if (fValidation) {                // Proper nesting of parameter entities is a Validity Constraint                // and must not be enforced when validation is off                fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,                                           "ImproperDeclarationNesting",                                           new Object[]{ name },                                           XMLErrorReporter.SEVERITY_ERROR);                }            }            if (fEntityScanner.isExternal()) {                fExtEntityDepth--;            }        }        // call handler        boolean dtdEntity = name.equals("[dtd]");        if (fDTDHandler != null && !dtdEntity && reportEntity) {            fDTDHandler.endParameterEntity(name, augs);        }        // end DTD        if (dtdEntity) {            if (fIncludeSectDepth != 0) {                reportFatalError("IncludeSectUnterminated", null);            }            fScannerState = SCANNER_STATE_END_OF_INPUT;            // call handler            fEntityManager.endExternalSubset();            if (fDTDHandler != null) {                fDTDHandler.endExternalSubset(null);                fDTDHandler.endDTD(null);            }            fExtEntityDepth--;        }    } // endEntity(String)    // helper methods    /**     * Sets the scanner state.     *     * @param state The new scanner state.     */    protected final void setScannerState(int state) {        fScannerState = state;        if (DEBUG_SCANNER_STATE) {            System.out.print("### setScannerState: ");            System.out.print(getScannerStateName(state));            System.out.println();        }    } // setScannerState(int)    //    // Private methods    //    /** Returns the scanner state name. */    private static String getScannerStateName(int state) {        if (DEBUG_SCANNER_STATE) {            switch (state) {                case SCANNER_STATE_END_OF_INPUT: return "SCANNER_STATE_END_OF_INPUT";                case SCANNER_STATE_TEXT_DECL: return "SCANNER_STATE_TEXT_DECL";                case SCANNER_STATE_MARKUP_DECL: return "SCANNER_STATE_MARKUP_DECL";            }        }        return "??? ("+state+')';    } // getScannerStateName(int):String    protected final boolean scanningInternalSubset() {        return fExtEntityDepth == 0;    }    /**     * start a parameter entity dealing with the textdecl if there is any     *     * @param name The name of the parameter entity to start (without the '%')     * @param literal Whether this is happening within a literal     */    protected void startPE(String name, boolean literal)         throws IOException, XNIException {        int depth = fPEDepth;        String pName = "%"+name;        if (fValidation && !fEntityManager.isDeclaredEntity(pName)) {            fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN,"EntityNotDeclared",                                         new Object[]{name}, XMLErrorReporter.SEVERITY_ERROR);        }        fEntityManager.startEntity(fSymbolTable.addSymbol(pName),                                   literal);        // if we actually got a new entity and it's external        // parse text decl if there is any        if (depth != fPEDepth && fEntityScanner.isExternal()) {            scanTextDecl();        }    }    /**      * Dispatch an XML "event".     *     * @param complete True if this method is intended to scan     *                 and dispatch as much as possible.                      *     * @return True if a TextDecl was scanned.     *     * @throws IOException  Thrown on i/o error.     * @throws XNIException Thrown on parse error.     *     */

⌨️ 快捷键说明

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