You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/06/24 12:00:54 UTC

svn commit: r671109 - in /myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util: AddResource.java MyFacesResourceHandler.java MyFacesResourceLoader.java

Author: skitching
Date: Tue Jun 24 03:00:54 2008
New Revision: 671109

URL: http://svn.apache.org/viewvc?rev=671109&view=rev
Log:
TOMAHAWK-1266. Report an exception if an absolute path is passed to the AddResource methods that are intended to serve tomahawk resources relative to a tomahawk class file. Also add better documentation on what is going on here.

Modified:
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceHandler.java
    myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceLoader.java

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java?rev=671109&r1=671108&r2=671109&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/AddResource.java Tue Jun 24 03:00:54 2008
@@ -213,16 +213,23 @@
             String inlineScript);
 
     /**
-     * Return a URI that can be embedded into an HTML page.
+     * Return a URI that can be embedded into an HTML page to reference a resource
+     * from a Tomahawk jarfile.
      * <p>
-     * When the browser GETs that url, the serveResource method of this class will
-     * be invoked that is expected to write the contents of the specified resource
-     * to the respose stream.
+     * This method is intended for internal use by the Tomahawk project only,
+     * and will not serve resources for other projects (unless a custom
+     * AddResource implementation has been configured). Non-tomahawk code should
+     * use the variants that take an explicit ResourceHandler class.
      * <p>
-     * Parameter myfacesCustomComponent must be an instance of ResourceProvider,
-     * and have a default constructor. When the URL is fetched, an instance of
-     * this class is created and its methods invoked to retrieve info about the
-     * specified resource (including its content).
+     * Parameter myfacesCustomComponent is a tomahawk class that the resource
+     * is associated with. The resource is then expected to be in the classpath
+     * in the same package as the specified class (or a subpackage).
+     * <p>
+     * Parameter resource is a path relative to the .class file of the specified
+     * myfacesCustomComponent class.
+     * 
+     * Param withContextPath controls whether the webapp name is prefixed to
+     * the generated url.
      */
     public String getResourceUri(FacesContext context, Class myfacesCustomComponent,
             String resource, boolean withContextPath);

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceHandler.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceHandler.java?rev=671109&r1=671108&r2=671109&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceHandler.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceHandler.java Tue Jun 24 03:00:54 2008
@@ -21,8 +21,14 @@
 import javax.faces.context.FacesContext;
 
 /**
- * Class whose instances represent a resource inside the tomahawk jarfile
- * which a custom component needs to tell a browser to fetch.
+ * A ResourceHandler which always generates URLs that trigger the
+ * MyfacesResourceLoader to load resources from the classpath
+ * relative to some Tomahawk class.
+ * <p>
+ * This is intended to support loading of Tomahawk resources only;
+ * applications which wish to use the Tomahawk AddResources framework
+ * for loading resources from elsewhere should implement their own
+ * ResourceHandler class.
  * 
  * @author Mathias Broekelmann
  */
@@ -42,7 +48,8 @@
      *   
      * @param resourceName is the name of a file that can be found in dir
      *  "resource/{resourceName} relative to the location of the specified
-     *  component class in the classpath.
+     *  component class in the classpath. Because the resource is always
+     *  relative to a class file, it must never begin with a slash. 
      */
     public MyFacesResourceHandler(Class myfacesCustomComponent, String resourceName)
     {
@@ -103,6 +110,12 @@
         sb.append("/");
         if (_resource != null)
         {
+            if (_resource.startsWith("/"))
+            {
+                throw new IllegalArgumentException(
+                    "Tomahawk resources are always relative to the associated class." +
+                    " Absolute resource paths are not allowed: " + _resource);
+            }
             sb.append(_resource);
         }
         return sb.toString();

Modified: myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceLoader.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceLoader.java?rev=671109&r1=671108&r2=671109&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceLoader.java (original)
+++ myfaces/tomahawk/trunk/core/src/main/java/org/apache/myfaces/renderkit/html/util/MyFacesResourceLoader.java Tue Jun 24 03:00:54 2008
@@ -38,6 +38,10 @@
 /**
  * A ResourceLoader capable of fetching resources from the classpath,
  * but only for classes under package org.apache.myfaces.custom.
+ * <p>
+ * The URI is expected to contain two pieces of information: the
+ * tomahawk class the resource is associated with, and a relative path
+ * from that class to the resource.
  *
  * @author Mathias Broekelmann (latest modification by $Author$)
  * @version $Revision$ $Date$