Uploaded image for project: 'Magnolia'
  1. Magnolia
  2. MAGNOLIA-1018

JavascriptIncludePage doesn't respect classpath when loading javascript class definitions.

    XMLWordPrintable

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

      Checklists

        Acceptance criteria

        Attachments

          Activity

            People

              pbaerfuss Philipp Bärfuss
              chris_miner Chris Miner
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Checklists

                  Bug DoR
                  Task DoD

                  Time Tracking

                    Estimated:
                    Original Estimate - 0.25h
                    0.25h
                    Remaining:
                    Remaining Estimate - 0.25h
                    0.25h
                    Logged:
                    Time Spent - Not Specified
                    Not Specified