tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1387318 - in /tomcat/sandbox/trunk-resources: java/org/apache/catalina/ java/org/apache/catalina/core/ java/org/apache/catalina/loader/ java/org/apache/catalina/startup/ java/org/apache/catalina/webresources/ test/org/apache/catalina/webre...
Date Tue, 18 Sep 2012 18:58:27 GMT
Author: markt
Date: Tue Sep 18 18:58:26 2012
New Revision: 1387318

URL: http://svn.apache.org/viewvc?rev=1387318&view=rev
Log:
Make it possible to configure the WebResourceRoot in a context.xml file (tested with default
and custom implementation)

Modified:
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/loader/WebappClassLoader.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextRuleSet.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
    tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
    tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java (original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/WebResourceRoot.java Tue Sep 18
18:58:26 2012
@@ -172,12 +172,6 @@ public interface WebResourceRoot extends
     boolean write(String path, InputStream is);
 
     /**
-     * Obtain the unique name for the Context with which these resources are
-     * associated (for logging etc).
-     */
-    String getContextName();
-
-    /**
      *
      * @param url   Identifies the root of the new {@link WebResourceSet}. It
      *              must point to a JAR, directory or file.
@@ -215,13 +209,29 @@ public interface WebResourceRoot extends
     void createWebResourceSet(ResourceSetType type, String base,
             String webAppMount, String internalPath);
 
+
     /**
-     *
-     * @return
+     * Obtain the web application this WebResourceRoot is associated with.
+     */
+    Context getContext();
+
+    /**
+     * Set the web application this WebResourceRoot is associated with.
      */
-    boolean getAddWebinfClassesResources();
+    void setContext(Context context);
 
+    /**
+     * Configure if this resources allow the use of symbolic links.
+     *
+     * @param allowLinking  <code>true</code> if symbolic links are allowed.
+     */
     void setAllowLinking(boolean allowLinking);
+
+    /**
+     * Determine if this resources allow the use of symbolic links.
+     *
+     * @return  <code>true</code> if symbolic links are allowed
+     */
     boolean getAllowLinking();
 
     public static enum ResourceSetType {

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/core/StandardContext.java Tue
Sep 18 18:58:26 2012
@@ -2455,6 +2455,12 @@ public class StandardContext extends Con
                 return;
 
             this.resources = resources;
+            if (oldResources != null) {
+                oldResources.setContext(null);
+            }
+            if (resources != null) {
+                resources.setContext(this);
+            }
 
             support.firePropertyChange("resources", oldResources,
                     resources);

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/loader/WebappClassLoader.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/loader/WebappClassLoader.java?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/loader/WebappClassLoader.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/loader/WebappClassLoader.java
Tue Sep 18 18:58:26 2012
@@ -489,7 +489,7 @@ public class WebappClassLoader
         if (resources == null) {
             return "Unknown";
         } else {
-            return resources.getContextName();
+            return resources.getContext().getName();
         }
     }
 

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextRuleSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextRuleSet.java?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextRuleSet.java (original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/startup/ContextRuleSet.java Tue
Sep 18 18:58:26 2012
@@ -164,12 +164,12 @@ public class ContextRuleSet extends Rule
         digester.addRuleSet(new RealmRuleSet(prefix + "Context/"));
 
         digester.addObjectCreate(prefix + "Context/Resources",
-                                 "org.apache.naming.resources.FileDirContext",
+                                 "org.apache.catalina.webresources.StandardRoot",
                                  "className");
         digester.addSetProperties(prefix + "Context/Resources");
         digester.addSetNext(prefix + "Context/Resources",
                             "setResources",
-                            "javax.naming.directory.DirContext");
+                            "org.apache.catalina.WebResourceRoot");
 
         digester.addObjectCreate(prefix + "Context/ResourceLink",
                 "org.apache.catalina.deploy.ContextResourceLink");

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/DirResourceSet.java
Tue Sep 18 18:58:26 2012
@@ -81,7 +81,7 @@ public class DirResourceSet extends Abst
 
         this.webAppMount = webAppMount;
 
-        if (root.getAddWebinfClassesResources()) {
+        if (root.getContext().getAddWebinfClassesResources()) {
             WebResource unpackedResourceJar =
                     getResource("/WEB-INF/classes/META-INF/resources");
             if (unpackedResourceJar.exists()) {

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/LocalStrings.properties
Tue Sep 18 18:58:26 2012
@@ -30,4 +30,5 @@ standardRoot.checkStateNotStarted=The re
 standardRoot.createInvalidFile=Unable to create WebResourceSet from [{0}]
 standardRoot.createNoFileResourceSet=The FileResourceSet feature has not yet been implemented
 standardRoot.createUnknownType=Unable to create WebResourceSet of unknown type [{0}]
+standardRoot.noContext=A Context has not been configured for this WebResourceRoot
 standardRoot.startInvalidMain=The main resource set specified [{0}] is not valid
\ No newline at end of file

Modified: tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
(original)
+++ tomcat/sandbox/trunk-resources/java/org/apache/catalina/webresources/StandardRoot.java
Tue Sep 18 18:58:26 2012
@@ -54,7 +54,7 @@ public class StandardRoot extends Lifecy
     protected static final StringManager sm =
             StringManager.getManager(Constants.Package);
 
-    private final Context context;
+    private Context context;
     private boolean allowLinking = false;
     private ArrayList<WebResourceSet> preResources = new ArrayList<>();
     private WebResourceSet main;
@@ -73,6 +73,17 @@ public class StandardRoot extends Lifecy
     }
 
 
+    /**
+     * Creates a new standard implementation of {@link WebResourceRoot}. A no
+     * argument constructor is required for this to work with the digester.
+     * {@link #setContext(Context)} must be called before this component is
+     * initialized.
+     *
+     */
+    public StandardRoot() {
+        // NO-OP
+    }
+
     public StandardRoot(Context context) {
         this.context = context;
     }
@@ -262,13 +273,13 @@ public class StandardRoot extends Lifecy
     }
 
     @Override
-    public String getContextName() {
-        return context.getName();
+    public Context getContext() {
+        return context;
     }
 
     @Override
-    public boolean getAddWebinfClassesResources() {
-        return context.getAddWebinfClassesResources();
+    public void setContext(Context context) {
+        this.context = context;
     }
 
     private void checkState() {
@@ -316,6 +327,16 @@ public class StandardRoot extends Lifecy
     // --------------------------------------------------------------- Lifecycle
 
     @Override
+    protected void initInternal() throws LifecycleException {
+        if (context == null) {
+            throw new IllegalStateException(
+                    sm.getString("standardRoot.noContext"));
+        }
+
+        super.initInternal();
+    }
+
+    @Override
     protected void startInternal() throws LifecycleException {
         String docBase = context.getDocBase();
 

Modified: tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
URL: http://svn.apache.org/viewvc/tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java?rev=1387318&r1=1387317&r2=1387318&view=diff
==============================================================================
--- tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
(original)
+++ tomcat/sandbox/trunk-resources/test/org/apache/catalina/webresources/TesterWebResourceRoot.java
Tue Sep 18 18:58:26 2012
@@ -20,6 +20,7 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.Set;
 
+import org.apache.catalina.Context;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.LifecycleState;
@@ -112,11 +113,16 @@ public class TesterWebResourceRoot imple
     }
 
     @Override
-    public String getContextName() {
+    public Context getContext() {
         return null;
     }
 
     @Override
+    public void setContext(Context context) {
+        // NO-OP
+    }
+
+    @Override
     public void createWebResourceSet(ResourceSetType type, URL url,
             String webAppPath, String internalPath) {
         // NO-OP
@@ -129,11 +135,6 @@ public class TesterWebResourceRoot imple
     }
 
     @Override
-    public boolean getAddWebinfClassesResources() {
-        return false;
-    }
-
-    @Override
     public void setAllowLinking(boolean allowLinking) {
         // NO-OP
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message