I managed to override the class but later I realize that I did not want to
have this behaviour for all the T5 standard components :(  

So using a decorator fits better because  I can reuse the original approach
in the case I don´t find the template in the fileSystem.

This is a first version of the code in case is useful for someone. Please
nothe that this uses a very basic approach to build the name of the file. A
file resource is built using URIResource (thanks to the chillenkit project)
which admits several constructors and one of them is File

public PageTemplateLocator decoratePageTemplateLocator(
                        final PageTemplateLocator original) {

                return new PageTemplateLocator() {
                        public Resource findPageTemplateResource(
                                        ComponentModel componentModel, Locale 
locale) {

                                String pageName = 
getLogicalName(componentModel);
                                boolean useClassPath = pageName == null;
                                Resource resource = null;

                                if (useClassPath) {
                                        System.out.println("Searching in 
classpath");
                                        resource = 
original.findPageTemplateResource(
                                                        componentModel, locale);

                                } else {

                                        String path = format("%s.%s", pageName,
                                                        
InternalConstants.TEMPLATE_EXTENSION);
                                        System.out.println("Reading file: " + 
"C:\\temp\\" + path);

                                        if (path != null) {
                                                File file = new 
File("C:\\temp\\" + path);
                                                try {
                                                        resource = new 
URIResource(file);
                                                } catch (MalformedURLException 
e) {
                                                        // TODO Auto-generated 
catch block
                                                        
System.out.println("Error file not found!!!!");
                                                        resource = 
original.findPageTemplateResource(
                                                                        
componentModel, locale);
                                                }

                                        }

                                }

                                return resource;
                        }
                };
        }


I,m able to load external pages and having some issues with component
templates. But I´ll find out how to fix it.

Thanks everybody fot your support. I think now I´ve become a new T5 user and
I like what I see ;)
-- 
View this message in context: 
http://tapestry-users.832.n2.nabble.com/How-to-load-tml-files-from-the-filesystem-instead-of-classpath-tp5009386p5011570.html
Sent from the Tapestry Users mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to