Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.tapestry.asset
Class AssetExternalizer  view AssetExternalizer download AssetExternalizer.java

java.lang.Object
  extended byorg.apache.tapestry.asset.AssetExternalizer

public class AssetExternalizer
extends java.lang.Object

Responsible for copying assets from the classpath to an external directory that is visible to the web server. The externalizer is stored inside the javax.servlet.ServletContext as a named attribute.

The externalizer uses the name org.apache.tapestry.AssetExternalizer.application name . It configures itself using two additional properties (searching in IEngine.getPropertySource()>IEngine.getPropertySource() 55 .
Parameter Description
org.apache.tapestry.asset.dir The directory to which assets will be copied.
org.apache.tapestry.asset.URL The corresponding URL for the asset directory.

If either of these parameters is null, then no externalization occurs. Private assets will still be available, just less efficiently, as the application will be invoked via its servlet and, ultimately, the AssetService will need to retrieve the asset.

Assets maintain thier directory structure when copied. For example, an asset with a resource path of /com/skunkworx/Banner.gif would be copied to the file system as dir/com/skunkworx/Banner.gif and would have a URL of URL/com/skunkworx/Banner.gif.

The externalizer will create any directories as needed.

The externalizer will not overwrite existing files. When a new version of the application is deployed with changed assets, there are two deployment stategies:

When using the second approach, it is best to use a directory that has a version number in it, for example, D:/inetpub/assets/0 mapped to the URL /assets/0. When a new version of the application is deployed, the trailing version number is incremented from 0 to 1.


Field Summary
static com.cortexeb.tools.clover.d __CLOVER_36_0
           
private  java.io.File _assetDir
           
private  org.apache.hivemind.ClassResolver _resolver
           
private  java.util.Map _resources
          A map from resource path (as a String) to final URL (as a String).
private  java.lang.String _URL
           
private static int BUFFER_SIZE
           
private static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
protected AssetExternalizer(org.apache.tapestry.IRequestCycle cycle)
           
 
Method Summary
protected  void externalize(java.lang.String resourcePath)
           
static AssetExternalizer get(org.apache.tapestry.IRequestCycle cycle)
          Gets the externalizer singleton for the application.
 java.lang.String getURL(java.lang.String resourcePath)
          Gets the URL to a private resource.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

__CLOVER_36_0

public static com.cortexeb.tools.clover.d __CLOVER_36_0

LOG

private static final org.apache.commons.logging.Log LOG

_resolver

private org.apache.hivemind.ClassResolver _resolver

_assetDir

private java.io.File _assetDir

_URL

private java.lang.String _URL

_resources

private java.util.Map _resources
A map from resource path (as a String) to final URL (as a String).


BUFFER_SIZE

private static final int BUFFER_SIZE
See Also:
Constant Field Values
Constructor Detail

AssetExternalizer

protected AssetExternalizer(org.apache.tapestry.IRequestCycle cycle)
Method Detail

externalize

protected void externalize(java.lang.String resourcePath)
                    throws java.io.IOException

get

public static AssetExternalizer get(org.apache.tapestry.IRequestCycle cycle)
Gets the externalizer singleton for the application. If it does not already exist, it is created and stored into the javax.servlet.ServletContext.

Each Tapestry application within a single javax.servlet.ServletContext will have its own externalizer; they are differentiated by the application name.


getURL

public java.lang.String getURL(java.lang.String resourcePath)
Gets the URL to a private resource. If the resource was previously copied out of the classpath, the previously generated URL is returned.

If the asset directory and URL are not configured, then returns null.

Otherwise, the asset is copied out to the asset directory, the URL is constructed (and recorded for later) and the URL is returned.

This method is not explicitly synchronized but should work multi-threaded. It synchronizes on the internal Map used to map resource paths to URLs.