domconfigurationimpl.java

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

JAVA
1,118
字号
     * The parser can use this method to instruct this configuration     * to begin parsing an XML document from any valid input source     * (a character stream, a byte stream, or a URI).     * <p>     * Parsers may not invoke this method while a parse is in progress.     * Once a parse is complete, the parser may then parse another XML     * document.     * <p>     * This method is synchronous: it will not return until parsing     * has ended.  If a client application wants to terminate     * parsing early, it should throw an exception.     *     * @param source The input source for the top-level of the     *               XML document.     *     * @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.     */    public void parse(XMLInputSource inputSource)        throws XNIException, IOException{        // no-op    }    /**     * 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;    } // 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) {        //no-op    } // setDTDHandler(XMLDTDHandler)    /** Returns the registered DTD handler. */    public XMLDTDHandler getDTDHandler() {        return null;    } // getDTDHandler():XMLDTDHandler    /**     * Sets the DTD content model handler.     *     * @param handler The DTD content model handler.     */    public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {        //no-op    } // setDTDContentModelHandler(XMLDTDContentModelHandler)    /** Returns the registered DTD content model handler. */    public XMLDTDContentModelHandler getDTDContentModelHandler() {        return null;    } // 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) {        if (resolver !=null) {            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) {        if (errorHandler != null) {            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() {        return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);    } // getErrorHandler():XMLErrorHandler    /**     * Set the state of a feature.     *     * Set the state of any feature in a SAX2 parser.  The parser     * might not recognize the feature, and if it does recognize     * it, it might not be able to fulfill the request.     *     * @param featureId The unique identifier (URI) of the feature.     * @param state The requested state of the feature (true or false).     *     * @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the     *            requested feature is not known.     */    public void setFeature(String featureId, boolean state)        throws XMLConfigurationException {        // save state if noone "objects"        super.setFeature(featureId, state);    } // setFeature(String,boolean)    /**     * setProperty     *     * @param propertyId     * @param value     */    public void setProperty(String propertyId, Object value)        throws XMLConfigurationException {        // store value if noone "objects"        super.setProperty(propertyId, value);    } // setProperty(String,Object)    /**     * 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)    /** Returns the locale. */    public Locale getLocale() {        return fLocale;    } // getLocale():Locale    /**     * DOM Level 3 WD - Experimental.     * setParameter     */    public void setParameter(String name, Object value) throws DOMException {        // REVISIT: Recognizes DOM L3 default features only.        //          Does not yet recognize Xerces features.		if(value instanceof Boolean){	   		boolean state = ((Boolean)value).booleanValue();            if (name.equalsIgnoreCase(Constants.DOM_COMMENTS)) {                features = (short) (state ? features | COMMENTS : features & ~COMMENTS);            }            else if (name.equalsIgnoreCase(Constants.DOM_DATATYPE_NORMALIZATION)) {                setFeature(NORMALIZE_DATA, state);                features =                    (short) (state ? features | DTNORMALIZATION : features & ~DTNORMALIZATION);                if (state) {                    features = (short) (features | VALIDATE);                }            }            else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACES)) {                features = (short) (state ? features | NAMESPACES : features & ~NAMESPACES);            }            else if (name.equalsIgnoreCase(Constants.DOM_CDATA_SECTIONS)) {                features = (short) (state ? features | CDATA : features & ~CDATA);            }            else if (name.equalsIgnoreCase(Constants.DOM_ENTITIES)) {                features = (short) (state ? features | ENTITIES : features & ~ENTITIES);            }            else if (name.equalsIgnoreCase(Constants.DOM_SPLIT_CDATA)) {                features = (short) (state ? features | SPLITCDATA : features & ~SPLITCDATA);            }            else if (name.equalsIgnoreCase(Constants.DOM_VALIDATE)) {                features = (short) (state ? features | VALIDATE : features & ~VALIDATE);            }            else if (name.equalsIgnoreCase(Constants.DOM_WELLFORMED)) {                features = (short) (state ? features | WELLFORMED : features & ~WELLFORMED );            }            else if (name.equalsIgnoreCase(Constants.DOM_INFOSET)) {                // Setting to false has no effect.                if (state) {                    features = (short) (features | INFOSET_TRUE_PARAMS);                    features = (short) (features & ~INFOSET_FALSE_PARAMS);                    setFeature(NORMALIZE_DATA, false);                }            }            else if (name.equalsIgnoreCase(Constants.DOM_NORMALIZE_CHARACTERS)                    || name.equalsIgnoreCase(Constants.DOM_CANONICAL_FORM)                    || name.equalsIgnoreCase(Constants.DOM_VALIDATE_IF_SCHEMA)                    || name.equalsIgnoreCase(Constants.DOM_CHECK_CHAR_NORMALIZATION)                    ) {                if (state) { // true is not supported                    String msg =                        DOMMessageFormatter.formatMessage(                            DOMMessageFormatter.DOM_DOMAIN,                            "FEATURE_NOT_SUPPORTED",                            new Object[] { name });                    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);                }            }            else if (name.equalsIgnoreCase(Constants.DOM_NAMESPACE_DECLARATIONS)                    || name.equalsIgnoreCase(Constants.DOM_ELEMENT_CONTENT_WHITESPACE)) {                if (!state) { // false is not supported                    String msg =                        DOMMessageFormatter.formatMessage(                            DOMMessageFormatter.DOM_DOMAIN,                            "FEATURE_NOT_SUPPORTED",                            new Object[] { name });                   throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);                }            }            else if (name.equalsIgnoreCase(SEND_PSVI) ){                // REVISIT: turning augmentation of PSVI is not support,                // because in this case we won't be able to retrieve element                // default value.                if (!state) { // false is not supported                    String msg =                        DOMMessageFormatter.formatMessage(                            DOMMessageFormatter.DOM_DOMAIN,                            "FEATURE_NOT_SUPPORTED",                            new Object[] { name });                    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);                }            }            else if (name.equalsIgnoreCase(Constants.DOM_PSVI)){                  features = (short) (state ? features | PSVI : features & ~PSVI);            }            else {                String msg =                    DOMMessageFormatter.formatMessage(                        DOMMessageFormatter.DOM_DOMAIN,                        "FEATURE_NOT_FOUND",                        new Object[] { name });                throw new DOMException(DOMException.NOT_FOUND_ERR, msg);            }        }        else { // set properties            if (name.equalsIgnoreCase(Constants.DOM_ERROR_HANDLER)) {                if (value instanceof DOMErrorHandler || value == null) {                    fErrorHandlerWrapper.setErrorHandler((DOMErrorHandler)value);                    setErrorHandler(fErrorHandlerWrapper);                }                else {                    // REVISIT: type mismatch                    String msg =                        DOMMessageFormatter.formatMessage(                            DOMMessageFormatter.DOM_DOMAIN,                            "TYPE_MISMATCH_ERR",                            new Object[] { name });                    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);                }            }            else if (name.equalsIgnoreCase(Constants.DOM_RESOURCE_RESOLVER)) {                if (value instanceof LSResourceResolver || value == null) {                    try {                        setEntityResolver(new DOMEntityResolverWrapper((LSResourceResolver) value));                    }                    catch (XMLConfigurationException e) {}                }                else {                    // REVISIT: type mismatch                    String msg =                        DOMMessageFormatter.formatMessage(                            DOMMessageFormatter.DOM_DOMAIN,                            "TYPE_MISMATCH_ERR",                            new Object[] { name });                    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);                }            }            else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_LOCATION)) {                if (value instanceof String || value == null) {                    try {                        String schemaType = (String) getProperty(                        Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE);                        if (schemaType == Constants.NS_XMLSCHEMA || value == null) {                            // map DOM schema-location to JAXP schemaSource property                            setProperty(                                Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_SOURCE,                                value);                        }                        else {                            // schemaType must not be null.                            // REVISIT: allow pre-parsing DTD grammars                            String msg =                                DOMMessageFormatter.formatMessage(                                    DOMMessageFormatter.DOM_DOMAIN,                                    "FEATURE_NOT_SUPPORTED",                                    new Object[] { name });                            throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);                        }                    }                    catch (XMLConfigurationException e) {}                }                else {                    // REVISIT: type mismatch                    String msg =                        DOMMessageFormatter.formatMessage(                            DOMMessageFormatter.DOM_DOMAIN,                            "TYPE_MISMATCH_ERR",                            new Object[] { name });                    throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);                }            }            else if (name.equalsIgnoreCase(Constants.DOM_SCHEMA_TYPE)) {                if (value instanceof String || value == null) {                    try {                        if (value == null) {                            setProperty(                                Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE,                                null);                  		                        }                        else if (value.equals(Constants.NS_XMLSCHEMA)) {                            // REVISIT: when add support to DTD validation                            setProperty(                                Constants.JAXP_PROPERTY_PREFIX + Constants.SCHEMA_LANGUAGE,                                Constants.NS_XMLSCHEMA);                        }	                                                else if (value.equals(Constants.NS_DTD)) {                            // REVISIT: revalidation against DTDs is not supported                             String msg = DOMMessageFormatter.formatMessage(                            DOMMessageFormatter.DOM_DOMAIN,                            "FEATURE_NOT_SUPPORTED",                            new Object[] { name });

⌨️ 快捷键说明

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