This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i get the path from which resource bundle gets its bundle file

 
Meir Yan
Ranch Hand
Posts: 599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all
im using resource bundle to load values from properties files , i like to know
from where the resource bundle load its properties file in the classpath
is there away to do this ?
 
Minh Tran
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is safer and more securer if you use ResourceBundle to load .properties file. You can write it by yourself as simple way. It use classLoader and stream to load file as its locale
 
Meir Yan
Ranch Hand
Posts: 599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i do use RB to load the files , i just need to know from whice path i load them
 
Abdul Kader
Ranch Hand
Posts: 115
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Resource bundle will check the class path and compare with your file name. if it able to match then it will load the file as the property file. here the location is all about the class path.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if you could create a custom ClassLoader that calls a listener any time it succeeds ...

That gives you all you need to map names to URLs.
 
Meir Yan
Ranch Hand
Posts: 599
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont understand how can i implement it so it will give me the path
of the prop file the RB found
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I left a lot out of that suggestion.

First, read up on ClassLoaders. You can write a custom ClassLoader that extends URLClassLoader and override the method I showed before. When it succesfully loads a class, it calls a listener object with name and full classname. You might pass that listener object to your ClassLoader in the ClassLoader constructor.

Then pass your own ClassLoader to ResourceBundle.get().

Now ResourceBundle calls the ClassLoader over and over, once for each candidate name that it might load. When it actually finds a file, the loader will call your listener and you save off the information. When ResourceBundle returns you a bundle, the info you saved should be the latest file loaded.

I can't guarantee this will work out ... give it a try and see!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic