velocity-user mailing list archives

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

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) {

 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?

Tim Pizey

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message