b3c08c71 by Adam Heath

Allow for multiple pre-loaded config files.

1 parent 74582d6e
......@@ -89,13 +89,17 @@ public class OfbizRhinoContainer extends RhinoContainer<OfbizRhinoContainer> {
private static final UtilCache<String, Require> cache = UtilCache.getOrCreateUtilCache("OfbizRhinoContainer.Require", 0, 5, 10000, false, false);
public static Require getOrCreateRequire(String appLocation, String configPath, String... deps) throws Exception {
public static Require getOrCreateRequire(String appLocation, List<String> configPaths, List<String> deps) throws Exception {
return getOrCreateRequire(appLocation, configPaths.toArray(new String[configPaths.size()]), deps.toArray(new String[deps.size()]));
}
public static Require getOrCreateRequire(String appLocation, String[] configPaths, String[] deps) throws Exception {
Require require = cache.get(appLocation);
if (require == null) {
File base = new File(FlexibleLocation.resolveLocation(appLocation).getPath());
OfbizRhinoContainer container = new OfbizRhinoContainer(base);
File rLocation = new File(FlexibleLocation.resolveLocation("component://ofbiz-rhino/lib/r.js").getPath());
require = new Require(container, rLocation, configPath);
require = new Require(container, rLocation, configPaths);
for (String dep: deps) {
require.require(dep);
}
......
......@@ -19,9 +19,9 @@ public class Require {
private final Loader loader;
private final Function require;
public Require(RhinoContainer<?> container, File rLocation, String configPath) throws Exception {
public Require(RhinoContainer<?> container, File rLocation, String... configPaths) throws Exception {
this.container = container;
this.loader = new Loader(container, rLocation, configPath);
this.loader = new Loader(container, rLocation, configPaths);
this.require = container.run(loader);
}
......@@ -74,12 +74,12 @@ public class Require {
public static class Loader extends InContext<Function> {
private final RhinoContainer<?> container;
private final File rLocation;
private final String configPath;
private final String[] configPaths;
public Loader(RhinoContainer<?> container, File rLocation, String configPath) {
public Loader(RhinoContainer<?> container, File rLocation, String... configPaths) {
this.container = container;
this.rLocation = rLocation;
this.configPath = configPath;
this.configPaths = configPaths;
}
@Override
......@@ -94,7 +94,7 @@ public class Require {
Scriptable argsObj = cx.newArray(this, new Object[] {});
defineProperty("arguments", argsObj, ScriptableObject.DONTENUM);
if (configPath != null && configPath.length() > 0) {
for (String configPath: configPaths) {
container.processSource(cx, this, configPath);
}
int optLevel = cx.getOptimizationLevel();
......@@ -114,10 +114,6 @@ public class Require {
public void load(Context cx, Object[] args, Function funObj) throws FileNotFoundException, IOException {
for (int i = 0; i < args.length; i++) {
String path = Context.toString(args[i]);
if (path.endsWith("/jquery.js")) {
container.print(cx, this, new Object[] {"Skipping file " + path}, funObj);
continue;
}
container.print(cx, this, new Object[] {"Loading file " + path}, funObj);
container.processSource(cx, this, path);
}
......