xincludehandler.java

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

JAVA
1,684
字号
                encoding,                augmentations);        }    }    /* (non-Javadoc)     * @see com.sun.org.apache.xerces.internal.xni.XMLDTDHandler#unparsedEntityDecl(java.lang.String, com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier, java.lang.String, com.sun.org.apache.xerces.internal.xni.Augmentations)     */    public void unparsedEntityDecl(        String name,        XMLResourceIdentifier identifier,        String notation,        Augmentations augmentations)        throws XNIException {        this.addUnparsedEntity(name, identifier, notation, augmentations);        if (fDTDHandler != null) {            fDTDHandler.unparsedEntityDecl(                name,                identifier,                notation,                augmentations);        }    }    /* (non-Javadoc)     * @see com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource#getDTDHandler()     */    public XMLDTDHandler getDTDHandler() {        return fDTDHandler;    }    /* (non-Javadoc)     * @see com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource#setDTDHandler(com.sun.org.apache.xerces.internal.xni.XMLDTDHandler)     */    public void setDTDHandler(XMLDTDHandler handler) {        fDTDHandler = handler;    }    // XIncludeHandler methods    private void setErrorReporter(XMLErrorReporter reporter) {        fErrorReporter = reporter;        if (fErrorReporter != null) {            fErrorReporter.putMessageFormatter(                XIncludeMessageFormatter.XINCLUDE_DOMAIN, fXIncludeMessageFormatter);            // this ensures the proper location is displayed in error messages            if (fDocLocation != null) {                fErrorReporter.setDocumentLocator(fDocLocation);            }        }    }    protected void handleFallbackElement() {        if (!getSawInclude(fDepth - 1)) {            if (getState() == STATE_IGNORE) {                return;            }            reportFatalError("FallbackParent");        }                setSawInclude(fDepth, false);        fNamespaceContext.setContextInvalid();        if (getSawFallback(fDepth)) {            reportFatalError("MultipleFallbacks");        }        else {            setSawFallback(fDepth, true);        }        // Either the state is STATE_EXPECT_FALLBACK or it's STATE_IGNORE.        // If we're ignoring, we want to stay ignoring. But if we're expecting this fallback element,        // we want to signal that we should process the children.        if (getState() == STATE_EXPECT_FALLBACK) {            setState(STATE_NORMAL_PROCESSING);        }    }    protected boolean handleIncludeElement(XMLAttributes attributes)        throws XNIException {        if (getSawInclude(fDepth - 1)) {            reportFatalError("IncludeChild", new Object[] { XINCLUDE_INCLUDE });        }        if (getState() == STATE_IGNORE) {            return true;        }        setSawInclude(fDepth, true);        fNamespaceContext.setContextInvalid();        // TODO: does Java use IURIs by default?        //       [Definition: An internationalized URI reference, or IURI, is a URI reference that directly uses [Unicode] characters.]        // TODO: figure out what section 4.1.1 of the XInclude spec is talking about        //       has to do with disallowed ASCII character escaping        //       this ties in with the above IURI section, but I suspect Java already does it                String href = attributes.getValue(XINCLUDE_ATTR_HREF);        String parse = attributes.getValue(XINCLUDE_ATTR_PARSE);        String xpointer =  attributes.getValue(XPOINTER);        String accept = attributes.getValue(XINCLUDE_ATTR_ACCEPT);        String acceptLanguage = attributes.getValue(XINCLUDE_ATTR_ACCEPT_LANGUAGE);                if (parse == null) {            parse = XINCLUDE_PARSE_XML;        }        if (href == null) {            href = XMLSymbols.EMPTY_STRING;        }        if (href.length() == 0 && XINCLUDE_PARSE_XML.equals(parse)) {            if (xpointer == null) {                reportFatalError("XpointerMissing");            }            else {                // When parse="xml" and an xpointer is specified treat                 // all absences of the href attribute as a resource error.                Locale locale = (fErrorReporter != null) ? fErrorReporter.getLocale() : null;                String reason = fXIncludeMessageFormatter.formatMessage(locale, "XPointerStreamability", null);                reportResourceError("XMLResourceError", new Object[] { href, reason });                return false;            }        }        URI hrefURI = null;                // Check whether href is correct and perform escaping as per section 4.1.1 of the XInclude spec.        // Report fatal error if the href value contains a fragment identifier or if the value after        // escaping is a syntactically invalid URI or IRI.        try {            hrefURI = new URI(href, true);            if (hrefURI.getFragment() != null) {                reportFatalError("HrefFragmentIdentifierIllegal", new Object[] {href});            }        }        catch (URI.MalformedURIException exc) {            String newHref = escapeHref(href);            if (href != newHref) {                href = newHref;                try {                    hrefURI = new URI(href, true);                    if (hrefURI.getFragment() != null) {                        reportFatalError("HrefFragmentIdentifierIllegal", new Object[] {href});                    }                }                catch (URI.MalformedURIException exc2) {                    reportFatalError("HrefSyntacticallyInvalid", new Object[] {href});                }            }            else {                reportFatalError("HrefSyntacticallyInvalid", new Object[] {href});            }        }                // Verify that if an accept and/or an accept-language attribute exist        // that the value(s) don't contain disallowed characters.        if (accept != null && !isValidInHTTPHeader(accept)) {            reportFatalError("AcceptMalformed", null);            accept = null;        }        if (acceptLanguage != null && !isValidInHTTPHeader(acceptLanguage)) {            reportFatalError("AcceptLanguageMalformed", null);            acceptLanguage = null;        }        XMLInputSource includedSource = null;        if (fEntityResolver != null) {            try {                XMLResourceIdentifier resourceIdentifier =                    new XMLResourceIdentifierImpl(                        null,                        href,                        fCurrentBaseURI.getExpandedSystemId(),                        XMLEntityManager.expandSystemId(                            href,                            fCurrentBaseURI.getExpandedSystemId(),                            false));                includedSource =                    fEntityResolver.resolveEntity(resourceIdentifier);                                if (includedSource != null &&                    !(includedSource instanceof HTTPInputSource) &&                    (accept != null || acceptLanguage != null) &&                    includedSource.getCharacterStream() == null &&                    includedSource.getByteStream() == null) {                                        includedSource = createInputSource(includedSource.getPublicId(), includedSource.getSystemId(),                         includedSource.getBaseSystemId(), accept, acceptLanguage);                }            }            catch (IOException e) {                reportResourceError(                    "XMLResourceError",                    new Object[] { href, e.getMessage()});                return false;            }        }        if (includedSource == null) {            // setup an HTTPInputSource if either of the content negotation attributes were specified.            if (accept != null || acceptLanguage != null) {                includedSource = createInputSource(null, href, fCurrentBaseURI.getExpandedSystemId(), accept, acceptLanguage);            }            else {                includedSource = new XMLInputSource(null, href, fCurrentBaseURI.getExpandedSystemId());            }        }                if (parse.equals(XINCLUDE_PARSE_XML)) {            // Instead of always creating a new configuration, the first one can be reused            if ((xpointer != null && fXPointerChildConfig == null)             		|| (xpointer == null && fXIncludeChildConfig == null) ) {            	            	String parserName = XINCLUDE_DEFAULT_CONFIGURATION;            	if (xpointer != null)            		parserName = "com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration";            	                fChildConfig =                    (XMLParserConfiguration)ObjectFactory.newInstance(                        parserName,                        ObjectFactory.findClassLoader(),                        true);                // use the same symbol table, error reporter, entity resolver, security manager and buffer size.                if (fSymbolTable != null) fChildConfig.setProperty(SYMBOL_TABLE, fSymbolTable);                if (fErrorReporter != null) fChildConfig.setProperty(ERROR_REPORTER, fErrorReporter);                if (fEntityResolver != null) fChildConfig.setProperty(ENTITY_RESOLVER, fEntityResolver);                fChildConfig.setProperty(SECURITY_MANAGER, fSecurityManager);                fChildConfig.setProperty(BUFFER_SIZE, new Integer(fBufferSize));                                // features must be copied to child configuration                fNeedCopyFeatures = true;                // use the same namespace context                fChildConfig.setProperty(                    Constants.XERCES_PROPERTY_PREFIX                        + Constants.NAMESPACE_CONTEXT_PROPERTY,                    fNamespaceContext);                fChildConfig.setFeature(                            XINCLUDE_FIXUP_BASE_URIS,                            fFixupBaseURIs);                fChildConfig.setFeature(                            XINCLUDE_FIXUP_LANGUAGE,                            fFixupLanguage);                                               // If the xpointer attribute is present                if (xpointer != null ) {                	                    XPointerHandler newHandler =                        (XPointerHandler)fChildConfig.getProperty(                            Constants.XERCES_PROPERTY_PREFIX                                + Constants.XPOINTER_HANDLER_PROPERTY);                	fXPtrProcessor = newHandler;                	// ???                	((XPointerHandler)fXPtrProcessor).setProperty(                            Constants.XERCES_PROPERTY_PREFIX                            + Constants.NAMESPACE_CONTEXT_PROPERTY,                        fNamespaceContext);                    ((XPointerHandler)fXPtrProcessor).setProperty(XINCLUDE_FIXUP_BASE_URIS,                            new Boolean(fFixupBaseURIs));                    ((XPointerHandler)fXPtrProcessor).setProperty(                            XINCLUDE_FIXUP_LANGUAGE,                            new Boolean (fFixupLanguage));                                        if (fErrorReporter != null)                     	((XPointerHandler)fXPtrProcessor).setProperty(ERROR_REPORTER, fErrorReporter);                	// ???                                        newHandler.setParent(this);                     newHandler.setDocumentHandler(this.getDocumentHandler());                    fXPointerChildConfig = fChildConfig;                                       } else {                    XIncludeHandler newHandler =                        (XIncludeHandler)fChildConfig.getProperty(                            Constants.XERCES_PROPERTY_PREFIX                                + Constants.XINCLUDE_HANDLER_PROPERTY);                	newHandler.setParent(this);                    newHandler.setDocumentHandler(this.getDocumentHandler());                    fXIncludeChildConfig = fChildConfig;                }            }            // If an xpointer attribute is present            if (xpointer != null ) {            	fChildConfig = fXPointerChildConfig ;            	                // Parse the XPointer expression                try {                    ((XPointerProcessor)fXPtrProcessor).parseXPointer(xpointer);                                    } catch (XNIException ex) {                    // report the XPointer error as a resource error                    reportResourceError(                            "XMLResourceError",                            new Object[] { href, ex.getMessage()});                        return false;                }            } else {            	fChildConfig = fXIncludeChildConfig;            }            // set all features on parserConfig to match this parser configuration            if (fNeedCopyFeatures) {                copyFeatures(fSettings, fChildConfig);            }            fNeedCopyFeatures = false;            try {                fNamespaceContext.pushScope();                fChildConfig.parse(includedSource);                // necessary to make sure proper location is reported in errors                if (fErrorReporter != null) {                    fErrorReporter.setDocumentLocator(fDocLocation);                }                // If the xpointer attribute is present                if (xpointer != null ) {                 	// and it was not resolved                	if (!((XPointerProcessor)fXPtrProcessor).isXPointerResolved()) {                        Locale locale = (fErrorReporter != null) ? fErrorReporter.getLocale() : null;                        String reason = fXIncludeMessageFormatter.formatMessage(locale, "XPointerResolutionUnsuccessful", null);                        reportResourceError("XMLResourceError", new Object[] {href, reason});                		// use the fallback                		return false;                	}                }            }            catch (XNIException e) {                // necessary to make sure proper location is repo

⌨️ 快捷键说明

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