dtdconfiguration.java

来自「JAVA 所有包」· Java 代码 · 共 849 行 · 第 1/3 页

JAVA
849
字号
        // add default recognized features        final String[] recognizedFeatures = {            //WARN_ON_DUPLICATE_ATTDEF,     // from XMLDTDScannerImpl            //WARN_ON_UNDECLARED_ELEMDEF,   // from XMLDTDScannerImpl            //ALLOW_JAVA_ENCODINGS,         // from XMLEntityManager            CONTINUE_AFTER_FATAL_ERROR,            LOAD_EXTERNAL_DTD,    // from XMLDTDScannerImpl            //NOTIFY_BUILTIN_REFS,  // from XMLDocumentFragmentScannerImpl            //NOTIFY_CHAR_REFS,		// from XMLDocumentFragmentScannerImpl            //WARN_ON_DUPLICATE_ENTITYDEF,  // from XMLEntityManager        };        addRecognizedFeatures(recognizedFeatures);        // set state for default features        //setFeature(WARN_ON_DUPLICATE_ATTDEF, false);  // from XMLDTDScannerImpl        //setFeature(WARN_ON_UNDECLARED_ELEMDEF, false);  // from XMLDTDScannerImpl        //setFeature(ALLOW_JAVA_ENCODINGS, false);      // from XMLEntityManager        setFeature(CONTINUE_AFTER_FATAL_ERROR, false);        setFeature(LOAD_EXTERNAL_DTD, true);      // from XMLDTDScannerImpl        //setFeature(NOTIFY_BUILTIN_REFS, false);   // from XMLDocumentFragmentScannerImpl        //setFeature(NOTIFY_CHAR_REFS, false);      // from XMLDocumentFragmentScannerImpl        //setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false);   // from XMLEntityManager        // add default recognized properties        final String[] recognizedProperties = {            ERROR_REPORTER,                         ENTITY_MANAGER,             DOCUMENT_SCANNER,            DTD_SCANNER,            DTD_PROCESSOR,            DTD_VALIDATOR,            NAMESPACE_BINDER,            XMLGRAMMAR_POOL,               DATATYPE_VALIDATOR_FACTORY,            VALIDATION_MANAGER,            JAXP_SCHEMA_SOURCE,            JAXP_SCHEMA_LANGUAGE        };        addRecognizedProperties(recognizedProperties);        fGrammarPool = grammarPool;        if(fGrammarPool != null){            setProperty(XMLGRAMMAR_POOL, fGrammarPool);        }        fEntityManager = createEntityManager();        setProperty(ENTITY_MANAGER, fEntityManager);        addComponent(fEntityManager);        fErrorReporter = createErrorReporter();        fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());        setProperty(ERROR_REPORTER, fErrorReporter);        addComponent(fErrorReporter);        fScanner = createDocumentScanner();        setProperty(DOCUMENT_SCANNER, fScanner);        if (fScanner instanceof XMLComponent) {            addComponent((XMLComponent)fScanner);        }        fDTDScanner = createDTDScanner();        if (fDTDScanner != null) {            setProperty(DTD_SCANNER, fDTDScanner);            if (fDTDScanner instanceof XMLComponent) {                addComponent((XMLComponent)fDTDScanner);            }        }        fDTDProcessor = createDTDProcessor();        if (fDTDProcessor != null) {            setProperty(DTD_PROCESSOR, fDTDProcessor);            if (fDTDProcessor instanceof XMLComponent) {                addComponent((XMLComponent)fDTDProcessor);            }        }        fDTDValidator = createDTDValidator();        if (fDTDValidator != null) {            setProperty(DTD_VALIDATOR, fDTDValidator);            addComponent(fDTDValidator);        }        fNamespaceBinder = createNamespaceBinder();        if (fNamespaceBinder != null) {            setProperty(NAMESPACE_BINDER, fNamespaceBinder);            addComponent(fNamespaceBinder);        }                fDatatypeValidatorFactory = createDatatypeValidatorFactory();        if (fDatatypeValidatorFactory != null) {            setProperty(DATATYPE_VALIDATOR_FACTORY,                        fDatatypeValidatorFactory);        }        fValidationManager = createValidationManager();        if (fValidationManager != null) {            setProperty (VALIDATION_MANAGER, fValidationManager);        }        // add message formatters        if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {            XMLMessageFormatter xmft = new XMLMessageFormatter();            fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);            fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);        }        // set locale        try {            setLocale(Locale.getDefault());        }        catch (XNIException e) {            // do nothing            // REVISIT: What is the right thing to do? -Ac        }    } // <init>(SymbolTable,XMLGrammarPool)    //    // Public methods    //    /**     * Set the locale to use for messages.     *     * @param locale The locale object to use for localization of messages.     *     * @exception XNIException Thrown if the parser does not support the     *                         specified locale.     */    public void setLocale(Locale locale) throws XNIException {        super.setLocale(locale);        fErrorReporter.setLocale(locale);    } // setLocale(Locale)    //    // XMLPullParserConfiguration methods    //    // parsing    /**     * Sets the input source for the document to parse.     *     * @param inputSource The document's input source.     *     * @exception XMLConfigurationException Thrown if there is a      *                        configuration error when initializing the     *                        parser.     * @exception IOException Thrown on I/O error.     *     * @see #parse(boolean)     */    public void setInputSource(XMLInputSource inputSource)        throws XMLConfigurationException, IOException {                // REVISIT: this method used to reset all the components and        //          construct the pipeline. Now reset() is called        //          in parse (boolean) just before we parse the document        //          Should this method still throw exceptions..?        fInputSource = inputSource;            } // setInputSource(XMLInputSource)    /**     * Parses the document in a pull parsing fashion.     *     * @param complete True if the pull parser should parse the     *                 remaining document completely.     *     * @return True if there is more document to parse.     *     * @exception XNIException Any XNI exception, possibly wrapping      *                         another exception.     * @exception IOException  An IO exception from the parser, possibly     *                         from a byte stream or character stream     *                         supplied by the parser.     *     * @see #setInputSource     */    public boolean parse(boolean complete) throws XNIException, IOException {        //        // reset and configure pipeline and set InputSource.        if (fInputSource !=null) {            try {                // resets and sets the pipeline.                reset();                fScanner.setInputSource(fInputSource);                fInputSource = null;            }             catch (XNIException ex) {                if (PRINT_EXCEPTION_STACK_TRACE)                    ex.printStackTrace();                throw ex;            }             catch (IOException ex) {                if (PRINT_EXCEPTION_STACK_TRACE)                    ex.printStackTrace();                throw ex;            }             catch (RuntimeException ex) {                if (PRINT_EXCEPTION_STACK_TRACE)                    ex.printStackTrace();                throw ex;            }            catch (Exception ex) {                if (PRINT_EXCEPTION_STACK_TRACE)                    ex.printStackTrace();                throw new XNIException(ex);            }        }        try {            return fScanner.scanDocument(complete);        }         catch (XNIException ex) {            if (PRINT_EXCEPTION_STACK_TRACE)                ex.printStackTrace();            throw ex;        }         catch (IOException ex) {            if (PRINT_EXCEPTION_STACK_TRACE)                ex.printStackTrace();            throw ex;        }         catch (RuntimeException ex) {            if (PRINT_EXCEPTION_STACK_TRACE)                ex.printStackTrace();            throw ex;        }        catch (Exception ex) {            if (PRINT_EXCEPTION_STACK_TRACE)                ex.printStackTrace();            throw new XNIException(ex);        }    } // parse(boolean):boolean    /**     * If the application decides to terminate parsing before the xml document     * is fully parsed, the application should call this method to free any     * resource allocated during parsing. For example, close all opened streams.     */    public void cleanup() {        fEntityManager.closeReaders();    }        //    // XMLParserConfiguration methods    //    /**     * Parses the specified input source.     *     * @param source The input source.     *     * @exception XNIException Throws exception on XNI error.     * @exception java.io.IOException Throws exception on i/o error.     */    public void parse(XMLInputSource source) throws XNIException, IOException {        if (fParseInProgress) {            // REVISIT - need to add new error message            throw new XNIException("FWK005 parse may not be called while parsing.");        }        fParseInProgress = true;        try {            setInputSource(source);            parse(true);        }         catch (XNIException ex) {            if (PRINT_EXCEPTION_STACK_TRACE)                ex.printStackTrace();            throw ex;        }         catch (IOException ex) {            if (PRINT_EXCEPTION_STACK_TRACE)                ex.printStackTrace();            throw ex;        }        catch (RuntimeException ex) {            if (PRINT_EXCEPTION_STACK_TRACE)                ex.printStackTrace();

⌨️ 快捷键说明

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