xml11dtdconfiguration.java

来自「JAVA 所有包」· Java 代码 · 共 1,338 行 · 第 1/4 页

JAVA
1,338
字号
     *     * @param symbolTable The symbol table to use.     */    public XML11DTDConfiguration(SymbolTable symbolTable) {        this(symbolTable, null, null);    } // <init>(SymbolTable)    /**     * Constructs a parser configuration using the specified symbol table and     * grammar pool.     * <p>     * <strong>REVISIT:</strong>      * Grammar pool will be updated when the new validation engine is     * implemented.     *     * @param symbolTable The symbol table to use.     * @param grammarPool The grammar pool to use.     */    public XML11DTDConfiguration(SymbolTable symbolTable, XMLGrammarPool grammarPool) {        this(symbolTable, grammarPool, null);    } // <init>(SymbolTable,XMLGrammarPool)    /**     * Constructs a parser configuration using the specified symbol table,     * grammar pool, and parent settings.     * <p>     * <strong>REVISIT:</strong>      * Grammar pool will be updated when the new validation engine is     * implemented.     *     * @param symbolTable    The symbol table to use.     * @param grammarPool    The grammar pool to use.     * @param parentSettings The parent settings.     */    public XML11DTDConfiguration(        SymbolTable symbolTable,        XMLGrammarPool grammarPool,        XMLComponentManager parentSettings) {				super(parentSettings);		// create a vector to hold all the components in use		// XML 1.0 specialized components		fComponents = new ArrayList();		// XML 1.1 specialized components		fXML11Components = new ArrayList();		// Common components for XML 1.1. and XML 1.0		fCommonComponents = new ArrayList();		// create storage for recognized features and properties		fRecognizedFeatures = new ArrayList();		fRecognizedProperties = new ArrayList();		// create table for features and properties		fFeatures = new HashMap();		fProperties = new HashMap();        // add default recognized features        final String[] recognizedFeatures =            {               	CONTINUE_AFTER_FATAL_ERROR, LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl				VALIDATION,                 				NAMESPACES, 				EXTERNAL_GENERAL_ENTITIES,  				EXTERNAL_PARAMETER_ENTITIES,				PARSER_SETTINGS			};        addRecognizedFeatures(recognizedFeatures);		// set state for default features		fFeatures.put(VALIDATION, Boolean.FALSE);		fFeatures.put(NAMESPACES, Boolean.TRUE);		fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);		fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);		fFeatures.put(CONTINUE_AFTER_FATAL_ERROR, Boolean.FALSE);		fFeatures.put(LOAD_EXTERNAL_DTD, Boolean.TRUE);		fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);        // add default recognized properties        final String[] recognizedProperties =            {				     				SYMBOL_TABLE,				ERROR_HANDLER,  				ENTITY_RESOLVER,                ERROR_REPORTER,                ENTITY_MANAGER,                DOCUMENT_SCANNER,                DTD_SCANNER,                DTD_PROCESSOR,                DTD_VALIDATOR,				DATATYPE_VALIDATOR_FACTORY,				VALIDATION_MANAGER,				XML_STRING,                XMLGRAMMAR_POOL,                 JAXP_SCHEMA_SOURCE,                JAXP_SCHEMA_LANGUAGE};        addRecognizedProperties(recognizedProperties);				if (symbolTable == null) {			symbolTable = new SymbolTable();		}		fSymbolTable = symbolTable;		fProperties.put(SYMBOL_TABLE, fSymbolTable);		        fGrammarPool = grammarPool;        if (fGrammarPool != null) {			fProperties.put(XMLGRAMMAR_POOL, fGrammarPool);        }        fEntityManager = new XMLEntityManager();		fProperties.put(ENTITY_MANAGER, fEntityManager);        addCommonComponent(fEntityManager);        fErrorReporter = new XMLErrorReporter();        fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());		fProperties.put(ERROR_REPORTER, fErrorReporter);        addCommonComponent(fErrorReporter);        fNamespaceScanner = new XMLNSDocumentScannerImpl();		fProperties.put(DOCUMENT_SCANNER, fNamespaceScanner);        addComponent((XMLComponent) fNamespaceScanner);        fDTDScanner = new XMLDTDScannerImpl();		fProperties.put(DTD_SCANNER, fDTDScanner);        addComponent((XMLComponent) fDTDScanner);        fDTDProcessor = new XMLDTDProcessor();		fProperties.put(DTD_PROCESSOR, fDTDProcessor);        addComponent((XMLComponent) fDTDProcessor);        fDTDValidator = new XMLNSDTDValidator();		fProperties.put(DTD_VALIDATOR, fDTDValidator);        addComponent(fDTDValidator);                fDatatypeValidatorFactory = DTDDVFactory.getInstance();		fProperties.put(DATATYPE_VALIDATOR_FACTORY, fDatatypeValidatorFactory);        fValidationManager = new ValidationManager();		fProperties.put(VALIDATION_MANAGER, fValidationManager);                fVersionDetector = new XMLVersionDetector();                // 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        }        		fConfigUpdated = false;    } // <init>(SymbolTable,XMLGrammarPool)    //    // Public methods    //    /**     * 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)    /**     * 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 {        fLocale = locale;        fErrorReporter.setLocale(locale);    } // setLocale(Locale)    	/**	 * Sets the document handler on the last component in the pipeline	 * to receive information about the document.	 * 	 * @param documentHandler   The document handler.	 */	public void setDocumentHandler(XMLDocumentHandler documentHandler) {		fDocumentHandler = documentHandler;		if (fLastComponent != null) {			fLastComponent.setDocumentHandler(fDocumentHandler);			if (fDocumentHandler !=null){				fDocumentHandler.setDocumentSource(fLastComponent);			}		}	} // setDocumentHandler(XMLDocumentHandler)	/** Returns the registered document handler. */	public XMLDocumentHandler getDocumentHandler() {		return fDocumentHandler;	} // getDocumentHandler():XMLDocumentHandler	/**	 * Sets the DTD handler.	 * 	 * @param dtdHandler The DTD handler.	 */	public void setDTDHandler(XMLDTDHandler dtdHandler) {		fDTDHandler = dtdHandler;	} // setDTDHandler(XMLDTDHandler)	/** Returns the registered DTD handler. */	public XMLDTDHandler getDTDHandler() {		return fDTDHandler;	} // getDTDHandler():XMLDTDHandler	/**	 * Sets the DTD content model handler.	 * 	 * @param handler The DTD content model handler.	 */	public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {		fDTDContentModelHandler = handler;	} // setDTDContentModelHandler(XMLDTDContentModelHandler)	/** Returns the registered DTD content model handler. */	public XMLDTDContentModelHandler getDTDContentModelHandler() {		return fDTDContentModelHandler;	} // getDTDContentModelHandler():XMLDTDContentModelHandler	/**	 * Sets the resolver used to resolve external entities. The EntityResolver	 * interface supports resolution of public and system identifiers.	 *	 * @param resolver The new entity resolver. Passing a null value will	 *                 uninstall the currently installed resolver.	 */	public void setEntityResolver(XMLEntityResolver resolver) {		fProperties.put(ENTITY_RESOLVER, resolver);	} // setEntityResolver(XMLEntityResolver)	/**	 * Return the current entity resolver.	 *	 * @return The current entity resolver, or null if none	 *         has been registered.	 * @see #setEntityResolver	 */	public XMLEntityResolver getEntityResolver() {		return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);	} // getEntityResolver():XMLEntityResolver		/**	 * Allow an application to register an error event handler.	 *	 * <p>If the application does not register an error handler, all	 * error events reported by the SAX parser will be silently	 * ignored; however, normal processing may not continue.  It is	 * highly recommended that all SAX applications implement an	 * error handler to avoid unexpected bugs.</p>	 *	 * <p>Applications may register a new or different handler in the	 * middle of a parse, and the SAX parser must begin using the new	 * handler immediately.</p>	 *	 * @param errorHandler The error handler.	 * @exception java.lang.NullPointerException If the handler 	 *            argument is null.	 * @see #getErrorHandler	 */	public void setErrorHandler(XMLErrorHandler errorHandler) {		fProperties.put(ERROR_HANDLER, errorHandler);	} // setErrorHandler(XMLErrorHandler)	/**	 * Return the current error handler.	 *	 * @return The current error handler, or null if none	 *         has been registered.	 * @see #setErrorHandler	 */	public XMLErrorHandler getErrorHandler() {		// REVISIT: Should this be a property?		return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);	} // getErrorHandler():XMLErrorHandler    /**     * 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();    }    /**     * 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) {

⌨️ 快捷键说明

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