-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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 org.apache.catalina.startup;
-
-
-/**
- * String constants for the startup package.
- *
- * @author Craig R. McClanahan
- * @author Jean-Francois Arcand
- * @version $Id$
- */
-
-public final class Constants {
-
- public static final String Package = "org.apache.catalina.startup";
-
- public static final String ApplicationContextXml = "META-INF/context.xml";
- public static final String ApplicationWebXml = "/WEB-INF/web.xml";
- public static final String DefaultContextXml = "conf/context.xml";
- public static final String DefaultWebXml = "web.xml";
- public static final String HostContextXml = "context.xml.default";
- public static final String HostWebXml = "web.xml.default";
-
- /**
- * A dummy value used to suppress loading the default web.xml file.
- *
- * <p>
- * It is useful when embedding Tomcat, when the default configuration is
- * done programmatically, e.g. by calling
- * <code>Tomcat.initWebappDefaults(context)</code>.
- *
- * @see Tomcat
- */
- public static final String NoDefaultWebXml = "org/apache/catalina/startup/NO_DEFAULT_XML";
-
- // J2EE
- public static final String J2eeSchemaPublicId_14 =
- "j2ee_1_4.xsd";
- public static final String J2eeSchemaResourcePath_14 =
- "/javax/servlet/resources/j2ee_1_4.xsd";
-
- public static final String JavaeeSchemaPublicId_5 =
- "javaee_5.xsd";
- public static final String JavaeeSchemaResourcePath_5 =
- "/javax/servlet/resources/javaee_5.xsd";
-
- public static final String JavaeeSchemaPublicId_6 =
- "javaee_6.xsd";
- public static final String JavaeeSchemaResourcePath_6 =
- "/javax/servlet/resources/javaee_6.xsd";
-
-
- // W3C
- public static final String W3cSchemaPublicId_10 =
- "xml.xsd";
- public static final String W3cSchemaResourcePath_10 =
- "/javax/servlet/resources/xml.xsd";
-
- public static final String W3cSchemaDTDPublicId_10 =
- "XMLSchema.dtd";
- public static final String W3cSchemaDTDResourcePath_10 =
- "/javax/servlet/resources/XMLSchema.dtd";
-
- public static final String W3cDatatypesDTDPublicId_10 =
- "datatypes.dtd";
- public static final String W3cDatatypesDTDResourcePath_10 =
- "/javax/servlet/resources/datatypes.dtd";
-
-
- // JSP
- public static final String JspSchemaPublicId_20 =
- "jsp_2_0.xsd";
- public static final String JspSchemaResourcePath_20 =
- "/javax/servlet/jsp/resources/jsp_2_0.xsd";
-
- public static final String JspSchemaPublicId_21 =
- "jsp_2_1.xsd";
- public static final String JspSchemaResourcePath_21 =
- "/javax/servlet/jsp/resources/jsp_2_1.xsd";
-
- public static final String JspSchemaPublicId_22 =
- "jsp_2_2.xsd";
- public static final String JspSchemaResourcePath_22 =
- "/javax/servlet/jsp/resources/jsp_2_2.xsd";
-
-
- // TLD
- public static final String TldDtdPublicId_11 =
- "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN";
- public static final String TldDtdResourcePath_11 =
- "/javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd";
-
- public static final String TldDtdPublicId_12 =
- "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN";
- public static final String TldDtdResourcePath_12 =
- "/javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd";
-
- public static final String TldSchemaPublicId_20 =
- "web-jsptaglibrary_2_0.xsd";
- public static final String TldSchemaResourcePath_20 =
- "/javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd";
-
- public static final String TldSchemaPublicId_21 =
- "web-jsptaglibrary_2_1.xsd";
- public static final String TldSchemaResourcePath_21 =
- "/javax/servlet/jsp/resources/web-jsptaglibrary_2_1.xsd";
-
-
- // web.xml
- public static final String WebDtdPublicId_22 =
- "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";
- public static final String WebDtdResourcePath_22 =
- "/javax/servlet/resources/web-app_2_2.dtd";
-
- public static final String WebDtdPublicId_23 =
- "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN";
- public static final String WebDtdResourcePath_23 =
- "/javax/servlet/resources/web-app_2_3.dtd";
-
- public static final String WebSchemaPublicId_24 =
- "web-app_2_4.xsd";
- public static final String WebSchemaResourcePath_24 =
- "/javax/servlet/resources/web-app_2_4.xsd";
-
- public static final String WebSchemaPublicId_25 =
- "web-app_2_5.xsd";
- public static final String WebSchemaResourcePath_25 =
- "/javax/servlet/resources/web-app_2_5.xsd";
-
- public static final String WebSchemaPublicId_30 =
- "web-app_3_0.xsd";
- public static final String WebSchemaResourcePath_30 =
- "/javax/servlet/resources/web-app_3_0.xsd";
-
- public static final String WebCommonSchemaPublicId_30 =
- "web-common_3_0.xsd";
- public static final String WebCommonSchemaResourcePath_30 =
- "/javax/servlet/resources/web-common_3_0.xsd";
-
- public static final String WebFragmentSchemaPublicId_30 =
- "web-fragment_3_0.xsd";
- public static final String WebFragmentSchemaResourcePath_30 =
- "/javax/servlet/resources/web-fragment_3_0.xsd";
-
- // Web service
- public static final String J2eeWebServiceSchemaPublicId_11 =
- "j2ee_web_services_1_1.xsd";
- public static final String J2eeWebServiceSchemaResourcePath_11 =
- "/javax/servlet/resources/j2ee_web_services_1_1.xsd";
-
- public static final String J2eeWebServiceClientSchemaPublicId_11 =
- "j2ee_web_services_client_1_1.xsd";
- public static final String J2eeWebServiceClientSchemaResourcePath_11 =
- "/javax/servlet/resources/j2ee_web_services_client_1_1.xsd";
-
- public static final String JavaeeWebServiceSchemaPublicId_12 =
- "javaee_web_services_1_2.xsd";
- public static final String JavaeeWebServiceSchemaResourcePath_12 =
- "/javax/servlet/resources/javaee_web_services_1_2.xsd";
-
- public static final String JavaeeWebServiceClientSchemaPublicId_12 =
- "javaee_web_services_client_1_2.xsd";
- public static final String JavaeeWebServiceClientSchemaResourcePath_12 =
- "/javax/servlet/resources/javaee_web_services_client_1_2.xsd";
-
- public static final String JavaeeWebServiceSchemaPublicId_13 =
- "javaee_web_services_1_3.xsd";
- public static final String JavaeeWebServiceSchemaResourcePath_13 =
- "/javax/servlet/resources/javaee_web_services_1_3.xsd";
-
- public static final String JavaeeWebServiceClientSchemaPublicId_13 =
- "javaee_web_services_client_1_3.xsd";
- public static final String JavaeeWebServiceClientSchemaResourcePath_13 =
- "/javax/servlet/resources/javaee_web_services_client_1_3.xsd";
-
-}
+/*\r
+ * Licensed to the Apache Software Foundation (ASF) under one or more\r
+ * contributor license agreements. See the NOTICE file distributed with\r
+ * this work for additional information regarding copyright ownership.\r
+ * The ASF licenses this file to You under the Apache License, Version 2.0\r
+ * (the "License"); you may not use this file except in compliance with\r
+ * the License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+\r
+package org.apache.catalina.startup;\r
+\r
+\r
+/**\r
+ * String constants for the startup package.\r
+ *\r
+ * @author Craig R. McClanahan\r
+ * @author Jean-Francois Arcand\r
+ * @version $Id$\r
+ */\r
+\r
+public final class Constants {\r
+\r
+ public static final String Package = "org.apache.catalina.startup";\r
+\r
+ public static final String ApplicationContextXml = "META-INF/context.xml";\r
+ public static final String ApplicationWebXml = "/WEB-INF/web.xml";\r
+ public static final String DefaultContextXml = "conf/context.xml";\r
+ public static final String DefaultWebXml = "conf/web.xml";\r
+ public static final String HostContextXml = "context.xml.default";\r
+ public static final String HostWebXml = "web.xml.default";\r
+\r
+ /**\r
+ * A dummy value used to suppress loading the default web.xml file.\r
+ *\r
+ * <p>\r
+ * It is useful when embedding Tomcat, when the default configuration is\r
+ * done programmatically, e.g. by calling\r
+ * <code>Tomcat.initWebappDefaults(context)</code>.\r
+ *\r
+ * @see Tomcat\r
+ */\r
+ public static final String NoDefaultWebXml = "org/apache/catalina/startup/NO_DEFAULT_XML";\r
+\r
+ // J2EE\r
+ public static final String J2eeSchemaPublicId_14 =\r
+ "j2ee_1_4.xsd";\r
+ public static final String J2eeSchemaResourcePath_14 =\r
+ "/javax/servlet/resources/j2ee_1_4.xsd";\r
+\r
+ public static final String JavaeeSchemaPublicId_5 =\r
+ "javaee_5.xsd";\r
+ public static final String JavaeeSchemaResourcePath_5 =\r
+ "/javax/servlet/resources/javaee_5.xsd";\r
+\r
+ public static final String JavaeeSchemaPublicId_6 =\r
+ "javaee_6.xsd";\r
+ public static final String JavaeeSchemaResourcePath_6 =\r
+ "/javax/servlet/resources/javaee_6.xsd";\r
+\r
+ \r
+ // W3C\r
+ public static final String W3cSchemaPublicId_10 =\r
+ "xml.xsd";\r
+ public static final String W3cSchemaResourcePath_10 =\r
+ "/javax/servlet/resources/xml.xsd";\r
+\r
+ public static final String W3cSchemaDTDPublicId_10 =\r
+ "XMLSchema.dtd";\r
+ public static final String W3cSchemaDTDResourcePath_10 =\r
+ "/javax/servlet/resources/XMLSchema.dtd";\r
+\r
+ public static final String W3cDatatypesDTDPublicId_10 =\r
+ "datatypes.dtd";\r
+ public static final String W3cDatatypesDTDResourcePath_10 =\r
+ "/javax/servlet/resources/datatypes.dtd";\r
+\r
+ \r
+ // JSP\r
+ public static final String JspSchemaPublicId_20 =\r
+ "jsp_2_0.xsd";\r
+ public static final String JspSchemaResourcePath_20 =\r
+ "/javax/servlet/jsp/resources/jsp_2_0.xsd";\r
+ \r
+ public static final String JspSchemaPublicId_21 =\r
+ "jsp_2_1.xsd";\r
+ public static final String JspSchemaResourcePath_21 =\r
+ "/javax/servlet/jsp/resources/jsp_2_1.xsd";\r
+\r
+ public static final String JspSchemaPublicId_22 =\r
+ "jsp_2_2.xsd";\r
+ public static final String JspSchemaResourcePath_22 =\r
+ "/javax/servlet/jsp/resources/jsp_2_2.xsd";\r
+\r
+\r
+ // TLD\r
+ public static final String TldDtdPublicId_11 =\r
+ "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN";\r
+ public static final String TldDtdResourcePath_11 =\r
+ "/javax/servlet/jsp/resources/web-jsptaglibrary_1_1.dtd";\r
+\r
+ public static final String TldDtdPublicId_12 =\r
+ "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN";\r
+ public static final String TldDtdResourcePath_12 =\r
+ "/javax/servlet/jsp/resources/web-jsptaglibrary_1_2.dtd";\r
+\r
+ public static final String TldSchemaPublicId_20 =\r
+ "web-jsptaglibrary_2_0.xsd";\r
+ public static final String TldSchemaResourcePath_20 =\r
+ "/javax/servlet/jsp/resources/web-jsptaglibrary_2_0.xsd";\r
+\r
+ public static final String TldSchemaPublicId_21 =\r
+ "web-jsptaglibrary_2_1.xsd";\r
+ public static final String TldSchemaResourcePath_21 =\r
+ "/javax/servlet/jsp/resources/web-jsptaglibrary_2_1.xsd";\r
+\r
+ \r
+ // web.xml\r
+ public static final String WebDtdPublicId_22 =\r
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN";\r
+ public static final String WebDtdResourcePath_22 =\r
+ "/javax/servlet/resources/web-app_2_2.dtd";\r
+\r
+ public static final String WebDtdPublicId_23 =\r
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN";\r
+ public static final String WebDtdResourcePath_23 =\r
+ "/javax/servlet/resources/web-app_2_3.dtd";\r
+\r
+ public static final String WebSchemaPublicId_24 =\r
+ "web-app_2_4.xsd";\r
+ public static final String WebSchemaResourcePath_24 =\r
+ "/javax/servlet/resources/web-app_2_4.xsd";\r
+\r
+ public static final String WebSchemaPublicId_25 =\r
+ "web-app_2_5.xsd";\r
+ public static final String WebSchemaResourcePath_25 =\r
+ "/javax/servlet/resources/web-app_2_5.xsd";\r
+\r
+ public static final String WebSchemaPublicId_30 =\r
+ "web-app_3_0.xsd";\r
+ public static final String WebSchemaResourcePath_30 =\r
+ "/javax/servlet/resources/web-app_3_0.xsd";\r
+\r
+ public static final String WebCommonSchemaPublicId_30 =\r
+ "web-common_3_0.xsd";\r
+ public static final String WebCommonSchemaResourcePath_30 =\r
+ "/javax/servlet/resources/web-common_3_0.xsd";\r
+\r
+ public static final String WebFragmentSchemaPublicId_30 =\r
+ "web-fragment_3_0.xsd";\r
+ public static final String WebFragmentSchemaResourcePath_30 =\r
+ "/javax/servlet/resources/web-fragment_3_0.xsd";\r
+ \r
+ // Web service\r
+ public static final String J2eeWebServiceSchemaPublicId_11 =\r
+ "j2ee_web_services_1_1.xsd";\r
+ public static final String J2eeWebServiceSchemaResourcePath_11 =\r
+ "/javax/servlet/resources/j2ee_web_services_1_1.xsd";\r
+ \r
+ public static final String J2eeWebServiceClientSchemaPublicId_11 =\r
+ "j2ee_web_services_client_1_1.xsd";\r
+ public static final String J2eeWebServiceClientSchemaResourcePath_11 =\r
+ "/javax/servlet/resources/j2ee_web_services_client_1_1.xsd";\r
+\r
+ public static final String JavaeeWebServiceSchemaPublicId_12 =\r
+ "javaee_web_services_1_2.xsd";\r
+ public static final String JavaeeWebServiceSchemaResourcePath_12 =\r
+ "/javax/servlet/resources/javaee_web_services_1_2.xsd";\r
+\r
+ public static final String JavaeeWebServiceClientSchemaPublicId_12 =\r
+ "javaee_web_services_client_1_2.xsd";\r
+ public static final String JavaeeWebServiceClientSchemaResourcePath_12 =\r
+ "/javax/servlet/resources/javaee_web_services_client_1_2.xsd";\r
+\r
+ public static final String JavaeeWebServiceSchemaPublicId_13 =\r
+ "javaee_web_services_1_3.xsd";\r
+ public static final String JavaeeWebServiceSchemaResourcePath_13 =\r
+ "/javax/servlet/resources/javaee_web_services_1_3.xsd";\r
+\r
+ public static final String JavaeeWebServiceClientSchemaPublicId_13 =\r
+ "javaee_web_services_client_1_3.xsd";\r
+ public static final String JavaeeWebServiceClientSchemaResourcePath_13 =\r
+ "/javax/servlet/resources/javaee_web_services_client_1_3.xsd";\r
+\r
+}\r
import java.io.UnsupportedEncodingException;
import java.net.JarURLConnection;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
DefaultWebXmlCacheEntry entry = hostWebXmlCache.get(host);
- File globalWebXml = getGlobalWebXml();
- File hostWebXml = getHostWebXml();
+ InputSource globalWebXml = getGlobalWebXmlSource();
+ InputSource hostWebXml = getHostWebXmlSource();
long globalTimeStamp = 0;
long hostTimeStamp = 0;
if (globalWebXml != null) {
- globalTimeStamp = globalWebXml.lastModified();
+ try {
+ File f = new File(new URI(globalWebXml.getSystemId()));
+ globalTimeStamp = f.lastModified();
+ } catch (URISyntaxException e) {
+ globalTimeStamp = -1;
+ }
}
if (hostWebXml != null) {
- hostTimeStamp = hostWebXml.lastModified();
+ try {
+ File f = new File(new URI(hostWebXml.getSystemId()));
+ hostTimeStamp = f.lastModified();
+ } catch (URISyntaxException e) {
+ hostTimeStamp = -1;
+ }
}
if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp &&
entry.getHostTimeStamp() == hostTimeStamp) {
- addWatchedResource(globalWebXml);
- addWatchedResource(hostWebXml);
return entry.getWebXml();
}
entry = hostWebXmlCache.get(host);
if (entry != null && entry.getGlobalTimeStamp() == globalTimeStamp &&
entry.getHostTimeStamp() == hostTimeStamp) {
- addWatchedResource(globalWebXml);
- addWatchedResource(hostWebXml);
return entry.getWebXml();
}
webXmlDefaultFragment.setAlwaysAddWelcomeFiles(false);
// Parse global web.xml if present
- if (globalWebXml == null || !globalWebXml.isFile()) {
+ if (globalWebXml == null) {
// This is unusual enough to log
log.info(sm.getString("contextConfig.defaultMissing"));
- globalTimeStamp = 0;
} else {
- parseWebXml(getWebXmlSource(globalWebXml.getName(),
- globalWebXml.getParent()),
- webXmlDefaultFragment,
- false);
- globalTimeStamp = globalWebXml.lastModified();
+ parseWebXml(globalWebXml, webXmlDefaultFragment, false);
}
// Parse host level web.xml if present
// Additive apart from welcome pages
webXmlDefaultFragment.setReplaceWelcomeFiles(true);
- if (hostWebXml == null || !hostWebXml.isFile()) {
- hostTimeStamp = 0;
- } else {
- parseWebXml(getWebXmlSource(hostWebXml.getName(),
- hostWebXml.getParent()),
- webXmlDefaultFragment,
- false);
- hostTimeStamp = hostWebXml.lastModified();
- }
-
- entry = new DefaultWebXmlCacheEntry(webXmlDefaultFragment,
- globalTimeStamp, hostTimeStamp);
+ parseWebXml(hostWebXml, webXmlDefaultFragment, false);
- hostWebXmlCache.put(host, entry);
+ // Don't update the cache if an error occurs
+ if (globalTimeStamp != -1 && hostTimeStamp != -1) {
+ entry = new DefaultWebXmlCacheEntry(webXmlDefaultFragment,
+ globalTimeStamp, hostTimeStamp);
+ hostWebXmlCache.put(host, entry);
+ }
- addWatchedResource(globalWebXml);
- addWatchedResource(hostWebXml);
return webXmlDefaultFragment;
}
}
- private void addWatchedResource(File f) {
- if (f != null) {
- context.addWatchedResource(f.getAbsolutePath());
- }
- }
+
private void convertJsps(WebXml webXml) {
Map<String,String> jspInitParams;
ServletDef jspServlet = webXml.getServlets().get("jsp");
/**
- * Identify the default web.xml to be used.
+ * Identify the default web.xml to be used and obtain an input source for
+ * it.
*/
- protected File getGlobalWebXml() {
+ protected InputSource getGlobalWebXmlSource() {
// Is a default web.xml specified for the Context?
if (defaultWebXml == null && context instanceof StandardContext) {
defaultWebXml = ((StandardContext) context).getDefaultWebXml();
if (Constants.NoDefaultWebXml.equals(defaultWebXml)) {
return null;
}
-
- // In an embedded environment, configBase might not be set
- File configBase = getConfigBase();
- if (configBase == null)
- return null;
-
- String basePath = null;
- try {
- basePath = configBase.getCanonicalPath();
- } catch (IOException e) {
- log.error(sm.getString("contextConfig.baseError"), e);
- return null;
- }
-
- return new File(basePath, defaultWebXml);
+ return getWebXmlSource(defaultWebXml, getBaseDir());
}
+
/**
- * Identify the host web.xml to be used.
+ * Identify the host web.xml to be used and obtain an input source for
+ * it.
*/
- protected File getHostWebXml() {
+ protected InputSource getHostWebXmlSource() {
String resourceName = getHostConfigPath(Constants.HostWebXml);
// In an embedded environment, configBase might not be set
try {
basePath = configBase.getCanonicalPath();
} catch (IOException e) {
- log.error(sm.getString("contextConfig.baseError"), e);
+ log.error(sm.getString("contectConfig.baseError"), e);
return null;
}
- return new File(basePath, resourceName);
+ return getWebXmlSource(resourceName, basePath);
}
/**
if(stream != null) {
source =
new InputSource(getClass().getClassLoader().getResource(
- filename).toString());
+ filename).toURI().toString());
}
} else {
- source = new InputSource("file://" + file.getAbsolutePath());
+ source = new InputSource(file.getAbsoluteFile().toURI().toString());
stream = new FileInputStream(file);
+ context.addWatchedResource(file.getAbsolutePath());
}
if (stream != null && source != null) {