Uploaded image for project: 'Apache Freemarker'
  1. Apache Freemarker
  2. FREEMARKER-193

FileTemplateLoader always prepends the root base path to the file path

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Not A Bug
    • 2.3.31
    • None
    • engine
    • None
    • Windows

    Description

      I was trying to use the FileTemplateLoader. While it seemed to work fine on Linux, it did not work on Windows. The thing was that I was trying to feed it with absolute file paths, and the base directory of the FileTemplateLoader was the root directory. 

      It was thus "X:\" for Windows and "/" for Linux. FileTemplateLoader was unable to retrieve the files with the absolute path on Windows, because it was trying to prepend the base path to the file names. So, it was prepending the "X:\" to the absolute file paths, already containing that "X:\" directory.

      @Override
          public Object findTemplateSource(final String name) throws IOException {
              try {
                  return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() {
                      @Override
                      public File run() throws IOException {
                          File source = new File(baseDir, SEP_IS_SLASH ? name : 
                              name.replace('/', File.separatorChar));
                          if (!source.isFile()) {
                              return null;
                          }
      

      I'm not sure whether this is by design and if files must always be relative to the base path of one of the FileTemplateLoader objects.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ajarmoniuk Andrzej J.
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: