Andrzej Jarmoniuk created FREEMARKER-193:
--------------------------------------------

             Summary: FileTemplateLoader always appends the root base path to 
the file path
                 Key: FREEMARKER-193
                 URL: https://issues.apache.org/jira/browse/FREEMARKER-193
             Project: Apache Freemarker
          Issue Type: Bug
          Components: engine
    Affects Versions: 2.3.31
         Environment: Windows
            Reporter: Andrzej Jarmoniuk


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 "C:\" 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.

{code:java}
@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;
                    }
{code}

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.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to