📄 facesdtdresolver.java
字号:
/* * Copyright 2002-2004 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package de.mindmatters.faces;import java.io.IOException;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.springframework.core.io.ClassPathResource;import org.springframework.core.io.Resource;import org.xml.sax.EntityResolver;import org.xml.sax.InputSource;import org.xml.sax.SAXException;/** * EntityResolver implementation for the JSF 1.0 and JSF 1.1 DTD, to load the * DTD from the jsf-spring class path (or JAR file). * * <p> * Fetches "web-facesconfig_1_0.dtd" or "web-facesconfig_1_0.dtd" from the class * path resource "/de/mindmatters/faces/web-facesconfig_1_0.dtd" or * "/de/mindmatters/faces/web-facesconfig_1_1.dtd", no matter whether specified * as some local URL that includes "web-facesconfig" in the DTD name or as * "http://java.sun.com/dtd/web-facesconfig_1_0.dtd" and * "http://java.sun.com/dtd/web-facesconfig_1_1.dtd" respectively. * </p> * * @author Andreas Kuhrwahl */public final class FacesDtdResolver implements EntityResolver { /** * The name prefix of the faces dtds (used for loading dtds form class * path). */ private static final String DTD_NAME = "web-facesconfig"; /** For logging. */ protected final Log logger = LogFactory.getLog(getClass()); /** * {@inheritDoc} */ public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException { if (logger.isDebugEnabled()) { logger.debug("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); } InputSource source = null; if (systemId != null && systemId.indexOf(DTD_NAME) > systemId.lastIndexOf("/")) { final String dtdFile = systemId.substring(systemId .indexOf(DTD_NAME)); if (logger.isDebugEnabled()) { logger.debug("Trying to locate [" + dtdFile + "] in jsf-spring jar"); } try { final Resource resource = new ClassPathResource(dtdFile, getClass()); source = new InputSource(resource.getInputStream()); source.setPublicId(publicId); source.setSystemId(systemId); if (logger.isDebugEnabled()) { logger.debug("Found faces DTD [" + systemId + "] in classpath"); } } catch (IOException ex) { if (logger.isDebugEnabled()) { logger.debug("Could not resolve faces DTD [" + systemId + "]: not found in class path", ex); } } } return source; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -