/**
 * Copyright (C) 2013-2016 The Rythm Engine project
 * for LICENSE and other details see:
 * https://github.com/rythmengine/rythmengine
 */
package org.rythmengine.resource;

import org.rythmengine.utils.IO;

import java.io.File;

/**
 * Represent a file template resource
 */
public class FileTemplateResource extends TemplateResourceBase implements ITemplateResource {

    private static final long serialVersionUID = -3059476990432671389L;
    private File file;
    private String key;

    @Override
    protected long defCheckInterval() {
        return 1000 * 5;
    }

    public FileTemplateResource(String path, FileResourceLoader loader) {
        super(loader);
        File f = new File(path);
        if (!isValid(f)) {
            File home = loader.getRoot();
            f = new File(home, path);
        }
        file = f;
        key = path.replace('\\', '/');
    }

    FileTemplateResource(File file, FileResourceLoader loader) {
        super(loader);
        this.file = file;
        this.key = file.getPath().replace('\\', '/');
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public long lastModified() {
        return file.lastModified();
    }

    protected boolean isValid(File file) {
        return null != file && !file.isDirectory() && file.canRead();
    }

    @Override
    public boolean isValid() {
        return isValid(file);
    }

    @Override
    protected String reload() {
        return IO.readContentAsString(file);
    }

    @Override
    public String getSuggestedClassName() {
        return path2CN(key);
    }

}

@@ -701,24 +701,104 @@
 File(path);%0A
+        File home = loader.getRoot();%0A        String homePath = home.getPath();%0A
         if (
@@ -828,73 +828,133 @@
     
+f = new 
 File
- 
+(
 home
- = loader.getRoot();%0A            f = new File(home, path
+, path);%0A        %7D else if (path.startsWith(homePath)) %7B%0A            path = path.substring(homePath.length()
 );%0A 
@@ -1152,33 +1152,220 @@
     
-this.key = file.getPath()
+String path = file.getPath();%0A        String homePath = loader.getRoot().getPath();%0A        if (path.startsWith(homePath)) %7B%0A            path = path.substring(homePath.length());%0A        %7D%0A        this.key = path
 .rep

fix #345