Allow xmlBase to be configurable, just like appBase.
authorfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 11 Mar 2009 22:05:12 +0000 (22:05 +0000)
committerfhanik <fhanik@13f79535-47bb-0310-9956-ffa450edef68>
Wed, 11 Mar 2009 22:05:12 +0000 (22:05 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@752651 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/Host.java
java/org/apache/catalina/core/StandardHost.java
java/org/apache/catalina/startup/HostConfig.java
webapps/docs/config/host.xml

index 0ad833c..515dc88 100644 (file)
@@ -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.
      */
index 73762e6..10083a7 100644 (file)
@@ -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);
+
+    }
 
 
     /**
index a2a7cd8..015bb9a 100644 (file)
@@ -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 {
index 492a9ae..211e97e 100644 (file)
         Deployment</a> for more information on automatic recognition and
         deployment of web applications to be deployed automatically.</p>
       </attribute>
+      
+      <attribute name="xmlBase" required="false">
+        <p>The <em>XML Base</em> 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 <code>$CATALINA_BASE</code> directory.  See
+        <a href="#Automatic Application Deployment">Automatic Application
+        Deployment</a> for more information on automatic recognition and
+        deployment of web applications to be deployed automatically.</p>
+      </attribute>
 
       <attribute name="autoDeploy" required="false">
         <p>This flag value indicates if new web applications, dropped in to
         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 
-        <code>$CATALINA_BASE/conf/[enginename]/[hostname]/</code>.
+        <code>$CATALINA_BASE/conf/[enginename]/[hostname]/</code> unless the attribute <code>xmlBase</code> is specified.
         The flag's value defaults to <code>true</code>.</p>
       </attribute>