Allow for multiple pre-loaded config files.
Showing
2 changed files
with
12 additions
and
12 deletions
... | @@ -89,13 +89,17 @@ public class OfbizRhinoContainer extends RhinoContainer<OfbizRhinoContainer> { | ... | @@ -89,13 +89,17 @@ public class OfbizRhinoContainer extends RhinoContainer<OfbizRhinoContainer> { |
89 | 89 | ||
90 | private static final UtilCache<String, Require> cache = UtilCache.getOrCreateUtilCache("OfbizRhinoContainer.Require", 0, 5, 10000, false, false); | 90 | private static final UtilCache<String, Require> cache = UtilCache.getOrCreateUtilCache("OfbizRhinoContainer.Require", 0, 5, 10000, false, false); |
91 | 91 | ||
92 | public static Require getOrCreateRequire(String appLocation, String configPath, String... deps) throws Exception { | 92 | public static Require getOrCreateRequire(String appLocation, List<String> configPaths, List<String> deps) throws Exception { |
93 | return getOrCreateRequire(appLocation, configPaths.toArray(new String[configPaths.size()]), deps.toArray(new String[deps.size()])); | ||
94 | } | ||
95 | |||
96 | public static Require getOrCreateRequire(String appLocation, String[] configPaths, String[] deps) throws Exception { | ||
93 | Require require = cache.get(appLocation); | 97 | Require require = cache.get(appLocation); |
94 | if (require == null) { | 98 | if (require == null) { |
95 | File base = new File(FlexibleLocation.resolveLocation(appLocation).getPath()); | 99 | File base = new File(FlexibleLocation.resolveLocation(appLocation).getPath()); |
96 | OfbizRhinoContainer container = new OfbizRhinoContainer(base); | 100 | OfbizRhinoContainer container = new OfbizRhinoContainer(base); |
97 | File rLocation = new File(FlexibleLocation.resolveLocation("component://ofbiz-rhino/lib/r.js").getPath()); | 101 | File rLocation = new File(FlexibleLocation.resolveLocation("component://ofbiz-rhino/lib/r.js").getPath()); |
98 | require = new Require(container, rLocation, configPath); | 102 | require = new Require(container, rLocation, configPaths); |
99 | for (String dep: deps) { | 103 | for (String dep: deps) { |
100 | require.require(dep); | 104 | require.require(dep); |
101 | } | 105 | } | ... | ... |
... | @@ -19,9 +19,9 @@ public class Require { | ... | @@ -19,9 +19,9 @@ public class Require { |
19 | private final Loader loader; | 19 | private final Loader loader; |
20 | private final Function require; | 20 | private final Function require; |
21 | 21 | ||
22 | public Require(RhinoContainer<?> container, File rLocation, String configPath) throws Exception { | 22 | public Require(RhinoContainer<?> container, File rLocation, String... configPaths) throws Exception { |
23 | this.container = container; | 23 | this.container = container; |
24 | this.loader = new Loader(container, rLocation, configPath); | 24 | this.loader = new Loader(container, rLocation, configPaths); |
25 | this.require = container.run(loader); | 25 | this.require = container.run(loader); |
26 | } | 26 | } |
27 | 27 | ||
... | @@ -74,12 +74,12 @@ public class Require { | ... | @@ -74,12 +74,12 @@ public class Require { |
74 | public static class Loader extends InContext<Function> { | 74 | public static class Loader extends InContext<Function> { |
75 | private final RhinoContainer<?> container; | 75 | private final RhinoContainer<?> container; |
76 | private final File rLocation; | 76 | private final File rLocation; |
77 | private final String configPath; | 77 | private final String[] configPaths; |
78 | 78 | ||
79 | public Loader(RhinoContainer<?> container, File rLocation, String configPath) { | 79 | public Loader(RhinoContainer<?> container, File rLocation, String... configPaths) { |
80 | this.container = container; | 80 | this.container = container; |
81 | this.rLocation = rLocation; | 81 | this.rLocation = rLocation; |
82 | this.configPath = configPath; | 82 | this.configPaths = configPaths; |
83 | } | 83 | } |
84 | 84 | ||
85 | @Override | 85 | @Override |
... | @@ -94,7 +94,7 @@ public class Require { | ... | @@ -94,7 +94,7 @@ public class Require { |
94 | Scriptable argsObj = cx.newArray(this, new Object[] {}); | 94 | Scriptable argsObj = cx.newArray(this, new Object[] {}); |
95 | defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); | 95 | defineProperty("arguments", argsObj, ScriptableObject.DONTENUM); |
96 | 96 | ||
97 | if (configPath != null && configPath.length() > 0) { | 97 | for (String configPath: configPaths) { |
98 | container.processSource(cx, this, configPath); | 98 | container.processSource(cx, this, configPath); |
99 | } | 99 | } |
100 | int optLevel = cx.getOptimizationLevel(); | 100 | int optLevel = cx.getOptimizationLevel(); |
... | @@ -114,10 +114,6 @@ public class Require { | ... | @@ -114,10 +114,6 @@ public class Require { |
114 | public void load(Context cx, Object[] args, Function funObj) throws FileNotFoundException, IOException { | 114 | public void load(Context cx, Object[] args, Function funObj) throws FileNotFoundException, IOException { |
115 | for (int i = 0; i < args.length; i++) { | 115 | for (int i = 0; i < args.length; i++) { |
116 | String path = Context.toString(args[i]); | 116 | String path = Context.toString(args[i]); |
117 | if (path.endsWith("/jquery.js")) { | ||
118 | container.print(cx, this, new Object[] {"Skipping file " + path}, funObj); | ||
119 | continue; | ||
120 | } | ||
121 | container.print(cx, this, new Object[] {"Loading file " + path}, funObj); | 117 | container.print(cx, this, new Object[] {"Loading file " + path}, funObj); |
122 | container.processSource(cx, this, path); | 118 | container.processSource(cx, this, path); |
123 | } | 119 | } | ... | ... |
-
Please register or sign in to post a comment