Skip to content

Commit

Permalink
Now supports using Mark Mandel's JavaLoader to load the Java objects.…
Browse files Browse the repository at this point in the history
… Credit for this goes to Dave Shuck, thanks for sharing code!

Updated the ReadMe.txt with JavaLoader info, and provided a simple example in combine.cfm.
  • Loading branch information
zefer committed Apr 27, 2009
1 parent ced11f0 commit 23380eb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
35 changes: 32 additions & 3 deletions Combine.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<cfargument name="outputSeperator" type="string" required="false" default="#chr(13)#" hint="seperates the output of different file content" />
<cfargument name="skipMissingFiles" type="boolean" required="false" default="true" hint="skip files that don't exists? If false, non-existent files will cause an error" />
<cfargument name="getFileModifiedMethod" type="string" required="false" default="java" hint="java or com. Which technique to use to get the last modified times for files." />
<!--- optional - use Mark Mandel's Java Loader to instantiate Java classes. This means you don't need to add the .jar files to the classpath --->
<cfargument name="javaLoader" type="any" required="false" default="" hint="a JavaLoader instance. If provided, this will be used to load the Java objects; if not provided, Java objects are loaded as normal via createObject()" />
<cfargument name="jarPath" type="string" required="false" default="path of the directory where the .jar files are located" />
<!--- experimental - use with care! You may want to tweak these values if your webserver has a caching layer that either causes problems, or adds potential performance gains. Disabling 304s will let the caching layer handle the caching according to its configuration. Setting cache-control to 'private' will bypass the caching layer and put the responsibility in the hands of Combine. --->
<cfargument name="enable304s" type="boolean" required="false" default="true" hint="304 (not-modified) is returned when the request's etag matches the current response, so we return a 304 instead of the content, instructing the browser to use it's cache. A valid reason for disabling this would be if you have an effective caching layer on your web server, which handles 304s more efficiently. However, unlike Combine the caching layer will not check the modified state of each individual css/js file. Note that to enable 304s, you must also enable eTags." />
<cfargument name="cacheControl" type="string" required="false" default="" hint="specify an optional cache-control header, which will be returned in each response. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html. An example use is to specify 'private' which will disable proxy caching, only allowing browser caching." />
Expand Down Expand Up @@ -39,17 +42,43 @@
// return 304s when conditional requests are made with matching Etags?
variables.bEnable304s = arguments.enable304s;

// -----------------------------------------------------------------------

// optional: use JavaLoader for loading external java files
variables.bUseJavaLoader = isObject(arguments.javaLoader) AND len(arguments.jarPath);
if(variables.bUseJavaLoader)
{
variables.jarFileArray = [arguments.jarPath & "\combine.jar",arguments.jarPath & "\yuicompressor-2.4.2.jar"];
arguments.javaLoader.init(variables.jarFileArray);
}

variables.jOutputStream = createObject("java","java.io.ByteArrayOutputStream");
variables.jStringReader = createObject("java","java.io.StringReader");

// If using jsMin, we need to load the required Java objects
if(variables.bJsMin)
{
variables.jJSMin = createObject("java","com.magnoliabox.jsmin.JSMin");
if(variables.bUseJavaLoader)
{
variables.jJSMin = arguments.javaLoader.create("com.magnoliabox.jsmin.JSMin");
}
else
{
variables.jJSMin = createObject("java","com.magnoliabox.jsmin.JSMin");
}

}
// If using the YUI CSS Compressor, we need to load the required Java objects
if(variables.bYuiCss)
{
variables.jStringWriter = createObject("java","java.io.StringWriter");
variables.jYuiCssCompressor = createObject("java","com.yahoo.platform.yui.compressor.CssCompressor");
if (variables.bUseJavaLoader)
{
variables.jYuiCssCompressor = arguments.javaLoader.create("com.yahoo.platform.yui.compressor.CssCompressor");
}
else
{
variables.jYuiCssCompressor = createObject("java","com.yahoo.platform.yui.compressor.CssCompressor");
}
}

// determine which method to use for getting the file last modified dates
Expand Down
11 changes: 9 additions & 2 deletions ReadMe.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ How do I use it?
- [optional] If you want to use the CSS or Javascript compression, you need to add the required Java to your classpath. See "How to add the Java to your classpath" below...


How to add the Java to your classpath [required for css and js compression]
---------------------------------------------------------------------------
Using JavaLoader to load the Java objects
-----------------------------------------
By using Mark Mandel's JavaLoader, you can avoid having to place the .jar files in the class path, which can be fiddly, or even restricted on some shared hosting platforms.
1. Download JavaLoader http://javaloader.riaforge.org/
2. Tweak combine.cfm to pass in an instance of JavaLoader.cfc, and the path to the directory where you have placed the .jar files included with Combine.


How to add the Java to your classpath [required for css and js compression, unless you use JavaLoader]
------------------------------------------------------------------------------------------------------
1. Determine where you will place your Java, it must go in a directory in your Coldfusion class path. This could either be cf_install_dir\lib, or a custom directory path which has been added to the Coldfusion class path (through Coldfusion's admin/config)
2. Add the code to the class_path_dir as determined in step 1. Copy combine.jar and yuicompressor.x.x.x.jar to your class_path_dir.
3. Restart your CFML server
Expand Down
15 changes: 15 additions & 0 deletions combine.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ if(isDefined('application') and structKeyExists(application, variables.sKey) and
else
{
// no cached version, or a forced reinit. Create a new instance.
// not using JavaLoader (the jar files must be in the classpath)
variables.oCombine = createObject("component", "combine").init(
enableCache: true,
cachePath: expandPath('example\cache'),
Expand All @@ -30,6 +32,19 @@ else
enableYuiCSS: true,
skipMissingFiles: false
);
// using JavaLoader
/*variables.oCombine = createObject("component", "combine").init(
enableCache: true,
cachePath: expandPath('example\cache'),
enableETags: true,
enableJSMin: true,
enableYuiCSS: true,
skipMissingFiles: false,
javaLoader: createObject("component", "javaloader.JavaLoader"),
jarPath: 'C:\www\misc\zefer\projects\combine'
);*/
// cache the object in the application scope, if we have an application scope!
if(isDefined('application'))
{
Expand Down

0 comments on commit 23380eb

Please sign in to comment.