From c37e9162e24649b5380afe513ac97f6b0215327e Mon Sep 17 00:00:00 2001 From: fhanik Date: Wed, 11 Mar 2009 22:05:12 +0000 Subject: [PATCH] Allow xmlBase to be configurable, just like appBase. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@752651 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/Host.java | 16 +++++++ java/org/apache/catalina/core/StandardHost.java | 29 +++++++++++++ java/org/apache/catalina/startup/HostConfig.java | 53 ++++++++++++------------ webapps/docs/config/host.xml | 13 +++++- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/java/org/apache/catalina/Host.java b/java/org/apache/catalina/Host.java index 0ad833c86..515dc88f9 100644 --- a/java/org/apache/catalina/Host.java +++ b/java/org/apache/catalina/Host.java @@ -68,6 +68,22 @@ public interface Host extends Container { /** + * Return the XML root for this Host. This can be an absolute + * pathname, a relative pathname, or a URL. + * If null, defaults to ${catalina.base}/conf/ directory + */ + public String getXmlBase(); + + /** + * Set the Xml root for this Host. This can be an absolute + * pathname, a relative pathname, or a URL. + * If null, defaults to ${catalina.base}/conf/ directory + * + * @param xmlBase The new XML root + */ + public void setXmlBase(String xmlBase); + + /** * Return the application root for this Host. This can be an absolute * pathname, a relative pathname, or a URL. */ diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java index 73762e6e3..10083a7ec 100644 --- a/java/org/apache/catalina/core/StandardHost.java +++ b/java/org/apache/catalina/core/StandardHost.java @@ -79,6 +79,10 @@ public class StandardHost */ private String appBase = "."; + /** + * The XML root for this Host. + */ + private String xmlBase = null; /** * The auto deploy flag for this Host. @@ -170,6 +174,16 @@ public class StandardHost } + /** + * Return the XML root for this Host. This can be an absolute + * pathname, a relative pathname, or a URL. + * If null, defaults to ${catalina.base}/conf/ directory + */ + public String getXmlBase() { + + return (this.xmlBase); + + } /** * Set the application root for this Host. This can be an absolute @@ -184,6 +198,21 @@ public class StandardHost support.firePropertyChange("appBase", oldAppBase, this.appBase); } + + /** + * Set the Xml root for this Host. This can be an absolute + * pathname, a relative pathname, or a URL. + * If null, defaults to ${catalina.base}/conf/ directory + * + * @param xmlBase The new XML root + */ + public void setXmlBase(String xmlBase) { + + String oldXmlBase = this.xmlBase; + this.xmlBase = xmlBase; + support.firePropertyChange("xmlBase", oldXmlBase, this.xmlBase); + + } /** diff --git a/java/org/apache/catalina/startup/HostConfig.java b/java/org/apache/catalina/startup/HostConfig.java index a2a7cd833..015bb9aa7 100644 --- a/java/org/apache/catalina/startup/HostConfig.java +++ b/java/org/apache/catalina/startup/HostConfig.java @@ -304,6 +304,9 @@ public class HostConfig setUnpackWARs(((StandardHost) host).isUnpackWARs()); setXmlNamespaceAware(((StandardHost) host).getXmlNamespaceAware()); setXmlValidation(((StandardHost) host).getXmlValidation()); + if (((StandardHost) host).getXmlBase()!=null) { + + } } } catch (ClassCastException e) { log.error(sm.getString("hostConfig.cce", event.getLifecycle()), e); @@ -394,6 +397,18 @@ public class HostConfig return (digester); } + protected File returnCanonicalPath(String path) { + File file = new File(path); + File base = new File(System.getProperty("catalina.base")); + if (!file.isAbsolute()) + file = new File(base,path); + try { + return file.getCanonicalFile(); + } catch (IOException e) { + return file; + } + } + /** * Return a File object representing the "application root" directory @@ -404,17 +419,9 @@ public class HostConfig if (appBase != null) { return appBase; } - - File file = new File(host.getAppBase()); - if (!file.isAbsolute()) - file = new File(System.getProperty("catalina.base"), - host.getAppBase()); - try { - appBase = file.getCanonicalFile(); - } catch (IOException e) { - appBase = file; - } - return (appBase); + + appBase = returnCanonicalPath(host.getAppBase()); + return appBase; } @@ -428,17 +435,11 @@ public class HostConfig if (configBase != null) { return configBase; } - - File file = new File(System.getProperty("catalina.base"), "conf"); - Container parent = host.getParent(); - if ((parent != null) && (parent instanceof Engine)) { - file = new File(file, parent.getName()); - } - file = new File(file, host.getName()); - try { - configBase = file.getCanonicalFile(); - } catch (IOException e) { - configBase = file; + + if (host.getXmlBase()!=null) { + configBase = returnCanonicalPath(host.getXmlBase()); + } else { + configBase = returnCanonicalPath("conf"); } return (configBase); @@ -748,7 +749,7 @@ public class HostConfig InputStream istream = null; BufferedOutputStream ostream = null; File xml = new File - (configBase, file.substring(0, file.lastIndexOf(".")) + ".xml"); + (configBase(), file.substring(0, file.lastIndexOf(".")) + ".xml"); if (deployXML && !xml.exists()) { try { jar = new JarFile(war); @@ -756,7 +757,7 @@ public class HostConfig if (entry != null) { istream = jar.getInputStream(entry); - configBase.mkdirs(); + configBase().mkdirs(); ostream = new BufferedOutputStream @@ -950,8 +951,8 @@ public class HostConfig digester.reset(); } } - configBase.mkdirs(); - File xmlCopy = new File(configBase, file + ".xml"); + configBase().mkdirs(); + File xmlCopy = new File(configBase(), file + ".xml"); InputStream is = null; OutputStream os = null; try { diff --git a/webapps/docs/config/host.xml b/webapps/docs/config/host.xml index 492a9aef8..211e97e03 100644 --- a/webapps/docs/config/host.xml +++ b/webapps/docs/config/host.xml @@ -85,6 +85,17 @@ Deployment for more information on automatic recognition and deployment of web applications to be deployed automatically.

+ + +

The XML Base directory for this virtual host. + This is the pathname of a directory that may contain context XML descriptors + to be deployed on this virtual host. You may specify an + absolute pathname for this directory, or a pathname that is relative + to the $CATALINA_BASE directory. See + Automatic Application + Deployment for more information on automatic recognition and + deployment of web applications to be deployed automatically.

+

This flag value indicates if new web applications, dropped in to @@ -155,7 +166,7 @@ applications from interacting with the container's configuration. The administrator will then be responsible for providing an external context configuration file, and put it in - $CATALINA_BASE/conf/[enginename]/[hostname]/. + $CATALINA_BASE/conf/[enginename]/[hostname]/ unless the attribute xmlBase is specified. The flag's value defaults to true.

-- 2.11.0