You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2006/12/08 03:16:12 UTC

svn commit: r483778 - in /tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry: TapestryFilter.java internal/services/AssetDispatcher.java

Author: hlship
Date: Thu Dec  7 18:16:12 2006
New Revision: 483778

URL: http://svn.apache.org/viewvc?view=rev&rev=483778
Log:
Correct some errant comments.

Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/TapestryFilter.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/TapestryFilter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/TapestryFilter.java?view=diff&rev=483778&r1=483777&r2=483778
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/TapestryFilter.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/TapestryFilter.java Thu Dec  7 18:16:12 2006
@@ -12,171 +12,170 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry;
-
-import static java.lang.String.format;
-
-import java.io.IOException;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.tapestry.internal.InternalConstants;
-import org.apache.tapestry.ioc.IOCUtilities;
-import org.apache.tapestry.ioc.Registry;
-import org.apache.tapestry.ioc.RegistryBuilder;
+package org.apache.tapestry;
+
+import static java.lang.String.format;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tapestry.internal.InternalConstants;
+import org.apache.tapestry.ioc.IOCUtilities;
+import org.apache.tapestry.ioc.Registry;
+import org.apache.tapestry.ioc.RegistryBuilder;
 import org.apache.tapestry.ioc.internal.util.InternalUtils;
-import org.apache.tapestry.services.ComponentClassResolver;
-import org.apache.tapestry.services.HttpServletRequestHandler;
-import org.apache.tapestry.services.Infrastructure;
-import org.apache.tapestry.services.ServletApplicationInitializer;
-import org.apache.tapestry.services.TapestryModule;
-
-/**
- * The TapestryFilter is responsible for intercepting all requests into the web application. It
- * identifies the requests that are relevant to Tapestry, and lets the servlet container handle the
- * rest. It is also responsible for initializating Tapestry.
- * 
- * 
- */
-public class TapestryFilter implements Filter
-{
-    private final Log _log = LogFactory.getLog(TapestryFilter.class);
-
-    private FilterConfig _config;
-
-    private Registry _registry;
-
-    private HttpServletRequestHandler _handler;
-
-    /**
-     * Initializes the filter by building the {@link Registry}. The registry contains
-     * {@link org.apache.tapestry.ioc.services.TapestryIOCModule} and {@link TapestryModule}, any
-     * modules identified by {@link #addModules(RegistryBuilder)}, plus the application module.
-     * <p>
-     * The application module is optional.
-     * <p>
-     * The application module is identified as <em>package</em>.services.<em>Name</em>Module,
-     * where <em>package</em> is defined by the <code>tapestry.app-package</code> filter init
-     * parameter and <em>Name</em> is the capitalization of the filter name (as specified in
-     * web.xml).
-     */
-    public final void init(FilterConfig filterConfig) throws ServletException
-    {
-        _config = filterConfig;
-
-        long start = System.currentTimeMillis();
-
-        RegistryBuilder builder = new RegistryBuilder();
-
-        builder.add(TapestryModule.class);
-
-        // Note: configured as a <context-param>, not a filter <init-param>
-        String appPackage = _config.getServletContext().getInitParameter(
-                InternalConstants.TAPESTRY_APP_PACKAGE_PARAM);
-        String filterName = _config.getFilterName();
-
-        String className = appPackage + ".services." + InternalUtils.capitalize(filterName) + "Module";
-
-        try
-        {
-            // TapestryFilter is possibly loaded by a parent class loader of the application class
-            // loader. The context class loader should have the approprite view to the module class,
-            // if any.
-
-            Class moduleClass = Thread.currentThread().getContextClassLoader().loadClass(className);
-            builder.add(moduleClass);
-        }
-        catch (ClassNotFoundException ex)
-        {
-            // That's OK, not all applications will have a module class, even though any
-            // non-trivial application will.
-        }
-
-        addModules(builder);
-
-        _registry = builder.build();
-
-        long toRegistry = System.currentTimeMillis();
-
-        Infrastructure infra = _registry
-                .getService("tapestry.Infrastructure", Infrastructure.class);
-        infra.setMode("servlet");
-
-        // It would be nice to move this logic inside ApplicationInitializer,
-        // may have to pass in the FilterConfig, or maybe a wrapper around
-        // it.
-
-        ComponentClassResolver resolver = _registry.getService(
-                "tapestry.ComponentClassResolver",
-                ComponentClassResolver.class);
-
-        resolver.setApplicationPackage(appPackage);
-
-        ServletApplicationInitializer ai = _registry.getService(
-                "tapestry.ServletApplicationInitializer",
-                ServletApplicationInitializer.class);
-
-        ai.initializeApplication(filterConfig.getServletContext());
-
-        _handler = _registry.getService(
-                "tapestry.HttpServletRequestHandler",
-                HttpServletRequestHandler.class);
-
-        long toFinish = System.currentTimeMillis();
-
-        _log.info(format("Startup time: %,d ms to build IoC Registry, %,d ms overall.", toRegistry
-                - start, toFinish - start));
-    }
-
-    /**
-     * Adds additional modules to the builder. This implementation adds any modules identified by
-     * {@link IOCUtilities#addDefaultModules(RegistryBuilder)}. Most subclasses will invoke this
-     * implementation, and add additional modules to the RegistryBuilder besides.
-     * {@link org.apache.tapestry.ioc.services.TapestryIOCModule} and {@link TapestryModule} will
-     * already have been added, as will an application module if present.
-     * 
-     * @param builder
-     */
-    protected void addModules(RegistryBuilder builder)
-    {
-        IOCUtilities.addDefaultModules(builder);
-    }
-
-    public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
-            throws IOException, ServletException
-    {
-        try
-        {
-            boolean handled = _handler.service(
-                    (HttpServletRequest) request,
-                    (HttpServletResponse) response);
-
-            if (!handled)
-                chain.doFilter(request, response);
-        }
-        finally
-        {
-            _registry.cleanupThread();
-        }
-    }
-
-    /** Shuts down and discards the registry. */
-    public final void destroy()
-    {
-        _registry.shutdown();
-
-        _registry = null;
-        _config = null;
-        _handler = null;
-    }
-
-}
+import org.apache.tapestry.services.ComponentClassResolver;
+import org.apache.tapestry.services.HttpServletRequestHandler;
+import org.apache.tapestry.services.Infrastructure;
+import org.apache.tapestry.services.ServletApplicationInitializer;
+import org.apache.tapestry.services.TapestryModule;
+
+/**
+ * The TapestryFilter is responsible for intercepting all requests into the web application. It
+ * identifies the requests that are relevant to Tapestry, and lets the servlet container handle the
+ * rest. It is also responsible for initializating Tapestry.
+ */
+public class TapestryFilter implements Filter
+{
+    private final Log _log = LogFactory.getLog(TapestryFilter.class);
+
+    private FilterConfig _config;
+
+    private Registry _registry;
+
+    private HttpServletRequestHandler _handler;
+
+    /**
+     * Initializes the filter by building the {@link Registry}. The registry contains
+     * {@link org.apache.tapestry.ioc.services.TapestryIOCModule} and {@link TapestryModule}, any
+     * modules identified by {@link #addModules(RegistryBuilder)}, plus the application module.
+     * <p>
+     * The application module is optional.
+     * <p>
+     * The application module is identified as <em>package</em>.services.<em>Name</em>Module,
+     * where <em>package</em> is defined by the <code>tapestry.app-package</code> context init
+     * parameter and <em>Name</em> is the capitalization of the filter name (as specified in
+     * web.xml).
+     */
+    public final void init(FilterConfig filterConfig) throws ServletException
+    {
+        _config = filterConfig;
+
+        long start = System.currentTimeMillis();
+
+        RegistryBuilder builder = new RegistryBuilder();
+
+        builder.add(TapestryModule.class);
+
+        // Note: configured as a <context-param>, not a filter <init-param>
+        String appPackage = _config.getServletContext().getInitParameter(
+                InternalConstants.TAPESTRY_APP_PACKAGE_PARAM);
+        String filterName = _config.getFilterName();
+
+        String className = appPackage + ".services." + InternalUtils.capitalize(filterName)
+                + "Module";
+
+        try
+        {
+            // TapestryFilter is possibly loaded by a parent class loader of the application class
+            // loader. The context class loader should have the approprite view to the module class,
+            // if any.
+
+            Class moduleClass = Thread.currentThread().getContextClassLoader().loadClass(className);
+            builder.add(moduleClass);
+        }
+        catch (ClassNotFoundException ex)
+        {
+            // That's OK, not all applications will have a module class, even though any
+            // non-trivial application will.
+        }
+
+        addModules(builder);
+
+        _registry = builder.build();
+
+        long toRegistry = System.currentTimeMillis();
+
+        Infrastructure infra = _registry
+                .getService("tapestry.Infrastructure", Infrastructure.class);
+        infra.setMode("servlet");
+
+        // It would be nice to move this logic inside ApplicationInitializer,
+        // may have to pass in the FilterConfig, or maybe a wrapper around
+        // it.
+
+        ComponentClassResolver resolver = _registry.getService(
+                "tapestry.ComponentClassResolver",
+                ComponentClassResolver.class);
+
+        resolver.setApplicationPackage(appPackage);
+
+        ServletApplicationInitializer ai = _registry.getService(
+                "tapestry.ServletApplicationInitializer",
+                ServletApplicationInitializer.class);
+
+        ai.initializeApplication(filterConfig.getServletContext());
+
+        _handler = _registry.getService(
+                "tapestry.HttpServletRequestHandler",
+                HttpServletRequestHandler.class);
+
+        long toFinish = System.currentTimeMillis();
+
+        _log.info(format("Startup time: %,d ms to build IoC Registry, %,d ms overall.", toRegistry
+                - start, toFinish - start));
+    }
+
+    /**
+     * Adds additional modules to the builder. This implementation adds any modules identified by
+     * {@link IOCUtilities#addDefaultModules(RegistryBuilder)}. Most subclasses will invoke this
+     * implementation, and add additional modules to the RegistryBuilder besides.
+     * {@link org.apache.tapestry.ioc.services.TapestryIOCModule} and {@link TapestryModule} will
+     * already have been added, as will an application module if present.
+     * 
+     * @param builder
+     */
+    protected void addModules(RegistryBuilder builder)
+    {
+        IOCUtilities.addDefaultModules(builder);
+    }
+
+    public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+            throws IOException, ServletException
+    {
+        try
+        {
+            boolean handled = _handler.service(
+                    (HttpServletRequest) request,
+                    (HttpServletResponse) response);
+
+            if (!handled)
+                chain.doFilter(request, response);
+        }
+        finally
+        {
+            _registry.cleanupThread();
+        }
+    }
+
+    /** Shuts down and discards the registry. */
+    public final void destroy()
+    {
+        _registry.shutdown();
+
+        _registry = null;
+        _config = null;
+        _handler = null;
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java?view=diff&rev=483778&r1=483777&r2=483778
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/AssetDispatcher.java Thu Dec  7 18:16:12 2006
@@ -29,9 +29,11 @@
 
 /**
  * Recognizes requests where the path begins with "/asset/" and delivers the content therein as a
- * bytestream. Also handles requests that are simply polling for a change to the file. Eventually,
- * will require a checksum as part of the path, for files with a particular extension (such as
- * .class), so that malicous clients can't troll for code.
+ * bytestream. Also handles requests that are simply polling for a change to the file.
+ * 
+ * @see ResourceStreamer
+ * @see ClasspathAssetAliasManager
+ * @see ResourceCache
  */
 public class AssetDispatcher implements Dispatcher
 {
@@ -41,10 +43,10 @@
 
     private final ResourceCache _resourceCache;
 
-    public static final String IF_MODIFIED_SINCE_HEADER = "If-Modified-Since";
+    static final String IF_MODIFIED_SINCE_HEADER = "If-Modified-Since";
 
-    public AssetDispatcher(final ResourceStreamer streamer,
-            ClasspathAssetAliasManager aliasManager, ResourceCache resourceCache)
+    public AssetDispatcher(ResourceStreamer streamer, ClasspathAssetAliasManager aliasManager,
+            ResourceCache resourceCache)
     {
         _streamer = streamer;
         _aliasManager = aliasManager;
@@ -70,8 +72,6 @@
         if (resource == null)
             return true;
 
-        // TODO: Check type of request and send correct error code if resource unchanged.
-
         URL url = resource.toURL();
 
         if (url == null)
@@ -95,9 +95,11 @@
 
     /**
      * @param response
+     *            used to send errors back to the client
      * @param resourcePath
-     * @return the true resource (with the digest stripped out of the URL) or null if the digest is
-     *         invalid
+     *            the path to the requested resource, from the request
+     * @return the resource for the path, with the digest stripped out of the URL, or null if the
+     *         digest is invalid (and an error has been sent back to the client)
      * @throws IOException
      */
     private Resource findResourceAndValidateDigest(Response response, String resourcePath)