You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "F. Da Costa Gomez" <da...@gmail.com> on 2005/03/04 22:43:45 UTC

Re: How to obtain the .page files (at runtime) in a certain package/ dir (solved)

ron wrote:
> I never did it with tapestry, but concerning servlet containers:
> If the files are in a directory, you can use your servlet context to do 
> the job.
> If its in the class path, then the class loader is the address, but this 
> would not be simple...
Thx Ron for putting me on the right track.
Took some fiddling but i got it resolved. Following the relevant code that gets 
the job done. Could probably be improved but i'll gladly leave that to a better 
programmer ;-)

public void pageBeginRender(PageEvent event) {
...
  // Go through the pages in the package and put them in a list

  // Take the package comment out of the result string
  String pkg = (getClass().getPackage().toString()).split(" ")[1];

  // move the file.separator into a char for the replace method
  char sep = System.getProperty("file.separator").toCharArray()[0];
  String filePkg = pkg.replace('.', sep);

  // Get the url (instead if directory path) through the classloader
  URL url1 = 
getEngine().getResourceResolver().getClassLoader().getResource(filePkg);

  // Get the directory
  File directory = new File(url1.getFile());

  // Get the .page files from the directory using a FileNameFilter
  String[] tapestryPages = directory.list(new TapestryFileNameFilter(".page"));

  _isBreadCrumbMenuInitialized = true;
...
}

I'm still a bit confused about the non-use of the initialize() method but i 
guess one can learn to live with it.

Cheers,

Fermin DCG

> Cheers,
> Ron
> 
> 
> 
> ציטוט F. Da Costa Gomez:
> 
>> Hi,
>>
>> Has anybody ever retrieved the .page files from a directory/package at 
>> runtime? Basically just a String[] with the filenames.
>> If so how, because i'm trying but not succeeding.
>>
>> tia,
>> Fermin DCG
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


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