velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Pizey <t...@paneris.org>
Subject Private fields and methods in ResourceLoader
Date Thu, 20 Apr 2006 20:46:54 GMT
Hi, 

I have been trying to write a ResourceLoader, initially a 
FileResourceLoader, but found that I could not extend 
FileResourceLoader as the members and findTemplate method are private. 

This has forced me to a more general solution, where I have a ResouceLoader 
which is a decorator to any other and takes the InputStream returned, 
converts it to a String, does Perl5 substitutions on it and then 
converts the String back to an InputStream. 

My code is at work but from memory I do something like 

public abstract class WebMacroResourceLoader extends ResourceLoader {

 private ResourceLoader loader ;

 public void init( ExtendedProperties configuration) {
  loader.init(configuration);
 }

 public InputStream getResourceStream(String templateName) {
   if (templateName.endsWith(".wm") {
      // mugle about with Perl5
      // return new input stream
   } else 
     return loader.getResourceStream(templateName);
 }

}

public class WebMacroClasspathResourceLoader extends WebMacroResourceLoader {
  public WebMacroClasspathResourceLoader() {
    this.loader = new ClasspathResourceLoader();
  }
}
public class WebMacroFileResourceLoader extends WebMacroResourceLoader {
  public WebMacroClasspathResourceLoader() {
    this.loader = new FileResourceLoader();
  }
}

Mine feels like a not-unusual requirement, is my approach sensible?
PS Any idea why I am getting NPE thrown from the init method?

yours
Tim Pizey

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message