Skip to content

Instantly share code, notes, and snippets.

@rbackhouse
rbackhouse / FileBasedResourceLoader.java
Created February 28, 2011 20:48
File Based Resource Loader extending CachingResourceLoader
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class FileBasedResourceLoader extends CachingResourceLoader {
private File root = null;
public FileBasedResourceLoader(File root) {
this.root = root;
}
@rbackhouse
rbackhouse / V8JavaBridgeExample.java
Created March 20, 2011 22:29
Example demonstrating using the V8 Java Bridge to run javascript with a callback into java
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import org.dojotoolkit.json.JSONParser;
import org.dojotoolkit.json.JSONSerializer;
import org.dojotoolkit.rt.v8.V8Exception;
import org.dojotoolkit.rt.v8.V8JavaBridge;
@rbackhouse
rbackhouse / FileBasedCompressingResourceLoader.java
Created March 20, 2011 22:32
File Based Resource Loader extending JSCompressorResourceLoader that enables javascript compression
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.dojotoolkit.compressor.JSCompressorFactory;
import org.dojotoolkit.compressor.JSCompressorResourceLoader;
public class FileBasedCompressingResourceLoader extends JSCompressorResourceLoader {
private File root = null;
@rbackhouse
rbackhouse / RunRhinoOptimizerNoCompressor.java
Created March 20, 2011 22:35
Example demonstrating calling the Rhino Based Javascript optimizer
import org.dojotoolkit.optimizer.JSAnalysisData;
import org.dojotoolkit.optimizer.JSOptimizer;
import org.dojotoolkit.optimizer.JSOptimizerFactory;
import org.dojotoolkit.optimizer.Localization;
import org.dojotoolkit.optimizer.rhino.RhinoJSOptimizerFactory;
private void runRhinoOptimizerNoCompressor() {
ResourceLoader resourceLoader = new FileBasedResourceLoader(new File("/pathToResources"));
RhinoClassLoader rhinoClassLoader = new RhinoClassLoader(resourceLoader);
JSOptimizerFactory factory = new RhinoJSOptimizerFactory();
@rbackhouse
rbackhouse / RunRhinoOptimizerRhinoUglifyCompressor.java
Created March 20, 2011 22:40
Example demonstrating calling the Rhino based Javascript optimizer using a Rhino/uglify-js based compressor
import org.dojotoolkit.compressor.JSCompressorFactory;
import org.dojotoolkit.compressor.uglifyjs.rhino.RhinoUglifyJSCompressorFactory;
import org.dojotoolkit.optimizer.JSAnalysisData;
import org.dojotoolkit.optimizer.JSOptimizer;
import org.dojotoolkit.optimizer.JSOptimizerFactory;
import org.dojotoolkit.optimizer.Localization;
import org.dojotoolkit.optimizer.rhino.RhinoJSOptimizerFactory;
import org.dojotoolkit.server.util.resource.ResourceLoader;
import org.dojotoolkit.server.util.rhino.RhinoClassLoader;
@rbackhouse
rbackhouse / RunV8OptimizerNoCompressor.java
Created March 20, 2011 22:46
Example demonstrating calling the V8 based Javascript optimizer
import org.dojotoolkit.optimizer.JSAnalysisData;
import org.dojotoolkit.optimizer.JSOptimizer;
import org.dojotoolkit.optimizer.JSOptimizerFactory;
import org.dojotoolkit.optimizer.Localization;
import org.dojotoolkit.optimizer.v8.V8JSOptimizerFactory;
import org.dojotoolkit.server.util.resource.ResourceLoader;
import org.dojotoolkit.server.util.rhino.RhinoClassLoader;
private void runV8OptimizerNoCompressor() {
ResourceLoader resourceLoader = new FileBasedResourceLoader(new File("pathToResources"));
@rbackhouse
rbackhouse / RunV8OptimizerV8UglifyCompressor.java
Created March 20, 2011 22:49
Example demonstrating calling the V8 based Javascript optimizer using a V8/uglify-js based compressor
import org.dojotoolkit.compressor.JSCompressorFactory;
import org.dojotoolkit.compressor.uglifyjs.v8.V8UglifyJSCompressorFactory;
import org.dojotoolkit.optimizer.JSAnalysisData;
import org.dojotoolkit.optimizer.JSOptimizer;
import org.dojotoolkit.optimizer.JSOptimizerFactory;
import org.dojotoolkit.optimizer.Localization;
import org.dojotoolkit.optimizer.v8.V8JSOptimizerFactory;
import org.dojotoolkit.server.util.resource.ResourceLoader;
import org.dojotoolkit.server.util.rhino.RhinoClassLoader;
@rbackhouse
rbackhouse / V8CommonJSLoader.java
Created March 24, 2011 01:30
Example demonstrating calling the commonjs loader via V8
import java.io.IOException;
import org.dojotoolkit.rt.v8.V8JavaBridge;
import org.dojotoolkit.server.util.resource.ResourceLoader;
public class V8CommonJSLoader extends V8JavaBridge {
private ResourceLoader resourceLoader = null;
public V8CommonJSLoader(ResourceLoader resourceLoader) {
super(true);
this.resourceLoader = resourceLoader;
@rbackhouse
rbackhouse / RhinoCommonJSLoader.java
Created March 24, 2011 01:31
Example demonstrating calling the commonjs loader via Rhino
import java.io.IOException;
import org.dojotoolkit.server.util.resource.ResourceLoader;
import org.dojotoolkit.server.util.rhino.RhinoClassLoader;
import org.dojotoolkit.server.util.rhino.RhinoJSMethods;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.ScriptableObject;
public class RhinoCommonJSLoader {
private RhinoClassLoader rhinoClassLoader = null;
private ResourceLoader resourceLoader = null;
@rbackhouse
rbackhouse / MultiRootResourceLoader.java
Created March 26, 2011 11:09
A Multiple Rooted Resource Loader
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.dojotoolkit.compressor.JSCompressorFactory;
import org.dojotoolkit.compressor.JSCompressorResourceLoader;
public class MultiRootResourceLoader extends JSCompressorResourceLoader {
private File[] roots = null;