xmldocumentfragmentscannerimpl.java

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

JAVA
1,788
字号
    public boolean scanDocument(boolean complete)         throws IOException, XNIException {                // reset entity scanner        fEntityScanner = fEntityManager.getEntityScanner();                // keep dispatching "events"        fEntityManager.setEntityHandler(this);        do {            if (!fDispatcher.dispatch(complete)) {                return false;            }        } while (complete);        // return success        return true;    } // scanDocument(boolean):boolean    //    // XMLComponent methods    //    /**     * Resets the component. The component can query the component manager     * about any features and properties that affect the operation of the     * component.     *      * @param componentManager The component manager.     *     * @throws SAXException Thrown by component on initialization error.     *                      For example, if a feature or property is     *                      required for the operation of the component, the     *                      component manager may throw a      *                      SAXNotRecognizedException or a     *                      SAXNotSupportedException.     */    public void reset(XMLComponentManager componentManager)        throws XMLConfigurationException {        super.reset(componentManager);        // other settings        //fDocumentSystemId = null;        // sax features        fAttributes.setNamespaces(fNamespaces);        // initialize vars        fMarkupDepth = 0;        fCurrentElement = null;        fElementStack.clear();        fHasExternalDTD = false;        fStandalone = false;        fInScanContent = false;		// setup dispatcher        try {            fSecurityManager = (SecurityManager)componentManager.getProperty(Constants.SECURITY_MANAGER);        } catch (XMLConfigurationException e) {            fSecurityManager = null;        }        		fElementAttributeLimit = (fSecurityManager != null)?fSecurityManager.getElementAttrLimit():0;		setScannerState(SCANNER_STATE_CONTENT);		setDispatcher(fContentDispatcher);        if (fParserSettings) {            // parser settings have changed. reset them.        	            // xerces features            try {                fNotifyBuiltInRefs = componentManager.getFeature(NOTIFY_BUILTIN_REFS);            } catch (XMLConfigurationException e) {                fNotifyBuiltInRefs = false;            }                        // xerces properties            try {                Object resolver = componentManager.getProperty(ENTITY_RESOLVER);                fExternalSubsetResolver = (resolver instanceof ExternalSubsetResolver) ?                    (ExternalSubsetResolver) resolver : null;            }            catch (XMLConfigurationException e) {                fExternalSubsetResolver = null;            }        }    } // reset(XMLComponentManager)    /**     * 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[]    /**     * Sets the state of a feature. This method is called by the component     * manager any time after reset when a feature changes state.      * <p>     * <strong>Note:</strong> Components should silently ignore features     * that do not affect the operation of the component.     *      * @param featureId The feature identifier.     * @param state     The state of the feature.     *     * @throws SAXNotRecognizedException The component should not throw     *                                   this exception.     * @throws SAXNotSupportedException The component should not throw     *                                  this exception.     */    public void setFeature(String featureId, boolean state)        throws XMLConfigurationException {        super.setFeature(featureId, state);                    // Xerces properties        if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {            final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();            if (suffixLength == Constants.NOTIFY_BUILTIN_REFS_FEATURE.length() &&                 featureId.endsWith(Constants.NOTIFY_BUILTIN_REFS_FEATURE)) {                fNotifyBuiltInRefs = state;            }        }    } // setFeature(String,boolean)    /**     * 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[]    /**     * Sets the value of a property. This method is called by the component     * manager any time after reset when a property changes value.      * <p>     * <strong>Note:</strong> Components should silently ignore properties     * that do not affect the operation of the component.     *      * @param propertyId The property identifier.     * @param value      The value of the property.     *     * @throws SAXNotRecognizedException The component should not throw     *                                   this exception.     * @throws SAXNotSupportedException The component should not throw     *                                  this exception.     */    public void setProperty(String propertyId, Object value)        throws XMLConfigurationException {                super.setProperty(propertyId, value);        // Xerces properties        if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {            final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();            if (suffixLength == Constants.ENTITY_MANAGER_PROPERTY.length() &&                 propertyId.endsWith(Constants.ENTITY_MANAGER_PROPERTY)) {                fEntityManager = (XMLEntityManager)value;                return;            }            if (suffixLength == Constants.ENTITY_RESOLVER_PROPERTY.length() &&                 propertyId.endsWith(Constants.ENTITY_RESOLVER_PROPERTY)) {                fExternalSubsetResolver = (value instanceof ExternalSubsetResolver) ?                    (ExternalSubsetResolver) value : null;                return;            }        }            } // setProperty(String,Object)    /**      * 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    //    // XMLDocumentSource methods    //    /**     * setDocumentHandler     *      * @param documentHandler      */    public void setDocumentHandler(XMLDocumentHandler documentHandler) {        fDocumentHandler = documentHandler;    } // setDocumentHandler(XMLDocumentHandler)    /** Returns the document handler */    public XMLDocumentHandler getDocumentHandler(){        return fDocumentHandler;    }    //    // 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 {        // keep track of this entity before fEntityDepth is increased        if (fEntityDepth == fEntityStack.length) {            int[] entityarray = new int[fEntityStack.length * 2];            System.arraycopy(fEntityStack, 0, entityarray, 0, fEntityStack.length);            fEntityStack = entityarray;        }        fEntityStack[fEntityDepth] = fMarkupDepth;        super.startEntity(name, identifier, encoding, augs);        // WFC:  entity declared in external subset in standalone doc        if(fStandalone && fEntityManager.isEntityDeclInExternalSubset(name)) {            reportFatalError("MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE",                new Object[]{name});        }        // call handler        if (fDocumentHandler != null && !fScanningAttribute) {            if (!name.equals("[xml]")) {                fDocumentHandler.startGeneralEntity(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 {        // flush possible pending output buffer - see scanContent        if (fInScanContent && fStringBuffer.length != 0            && fDocumentHandler != null) {            fDocumentHandler.characters(fStringBuffer, null);            fStringBuffer.length = 0; // make sure we know it's been flushed        }        super.endEntity(name, augs);        // make sure markup is properly balanced        if (fMarkupDepth != fEntityStack[fEntityDepth]) {            reportFatalError("MarkupEntityMismatch", null);        }        // call handler        if (fDocumentHandler != null && !fScanningAttribute) {            if (!name.equals("[xml]")) {                fDocumentHandler.endGeneralEntity(name, augs);            }        }            } // endEntity(String)    //    // Protected methods    //    // dispatcher factory methods    /** Creates a content dispatcher. */    protected Dispatcher createContentDispatcher() {        return new FragmentContentDispatcher();    } // createContentDispatcher():Dispatcher    // scanning methods    /**     * Scans an XML or text declaration.     * <p>     * <pre>     * [23] XMLDecl ::= '&lt;?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'     * [24] VersionInfo ::= S 'version' Eq (' VersionNum ' | " VersionNum ")     * [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' |  "'" EncName "'" )     * [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*     * [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'")     *                 | ('"' ('yes' | 'no') '"'))     *     * [77] TextDecl ::= '&lt;?xml' VersionInfo? EncodingDecl S? '?>'     * </pre>     *     * @param scanningTextDecl True if a text declaration is to     *                         be scanned instead of an XML     *                         declaration.     */    protected void scanXMLDeclOrTextDecl(boolean scanningTextDecl)         throws IOException, XNIException {        // scan decl        super.scanXMLDeclOrTextDecl(scanningTextDecl, fStrings);        fMarkupDepth--;        // pseudo-attribute values        String version = fStrings[0];        String encoding = fStrings[1];        String standalone = fStrings[2];

⌨️ 快捷键说明

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