Details
-
Bug
-
Resolution: Won't Do
-
Major
-
None
-
None
-
None
-
None
-
irrelevant
Description
If you include two defnintions of a javascript class in your classpath then the JavascriptIncludePage will prefer the last definition in the path. This is not expected since it isn't the way it works with java classes. The first definition found should be preferred. Here's a patch to the renderHtml method:
Index: /home/chris/Documents/magnolia-all/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/pages/JavascriptIncludePage.java
===================================================================
— /home/chris/Documents/magnolia-all/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/pages/JavascriptIncludePage.java (revision 6053)
+++ /home/chris/Documents/magnolia-all/magnolia-module-admininterface/src/main/java/info/magnolia/module/admininterface/pages/JavascriptIncludePage.java (working copy)
@@ -125,21 +125,28 @@
// request.getRequestDispatcher("/.resources/js-libs/*.js").include(request, response);
for (int j = 0; j < files.length; j++) {
- String name = files[j];
- Definition def = new Definition();
- def.name = StringUtils.replace(name, "
", "/"); - def.name = StringUtils.substringAfterLast(def.name, "/js-classes/");
- def.name = StringUtils.removeEnd(def.name, ".js");
- def.name = StringUtils.replace(def.name, "/", ".");
- InputStream stream = ClasspathResourcesUtil.getStream(name);
- def.content = IOUtils.toString(stream);
- stream.close();
- Matcher matcher = importPattern.matcher(def.content);
- while (matcher.find()) {
- String importName = matcher.group(1);
- def.imports.add(importName);
+ String streamName = files[j];
+
+ // extract a class name based on file path
+ String className = StringUtils.replace(streamName, "
", "/");
+ className = StringUtils.substringAfterLast(className, "/js-classes/");
+ className = StringUtils.removeEnd(className, ".js");
+ className = StringUtils.replace(className, "/", ".");
+
+ // only load up the first definition of a class
+ if (classDefinitions.get(className) == null)Unknown macro: {+ Definition def = new Definition();+ def.name = className;+ InputStream stream = ClasspathResourcesUtil.getStream(streamName);+ def.content = IOUtils.toString(stream);+ stream.close(); + Matcher matcher = importPattern.matcher(def.content);+ while (matcher.find()) { + String importName = matcher.group(1); + def.imports.add(importName); + }+ classDefinitions.put(def.name, def); } - classDefinitions.put(def.name, def);
}
// write first the runtime