@Levi
Thanks for that idea.

@Morten
Thanks for that code snippet. I used it for reading a properties file for
one of my filters.

On Tue, Nov 18, 2008 at 2:11 PM, Morten Matras <[EMAIL PROTECTED]>wrote:

> I don't think Stripes has that out of the box. Therefore I created a
> property reader servlet, that can be set up in web.xml that reads in
> properties files from /WEB-INF/conf to a properties object in application
> scope, so that it can be used from Stripes and other Java components
> afterwards:
>
> Getting started:
> 1) create the PropertyReader class
> 2) add xml to web.xml, that loads the PropertyReader servlet and runs the
> init method of that.
>
> ----
> The code is simplified to ensure easy setup. (No logging mechanism)
> The code has not been doublechecked, so please give feedback on whether it
> works or not.
> There is place for improvements, but basically it makes it very easy to use
> properties in your app. Just put them into WEB-INF/conf and the properties
> can be used. You can use one property file per logical unit all you have to
> ensure is that properties from one properties file doesn't overwrite
> properties from another. This will happen if the properties have the same
> name.
>
>
>      <servlet>
>         <servlet-name>ConfigurationReader</servlet-name>
>         <servlet-class>com.blob.PropertyReader</servlet-class>
>
>         <init-param>
>             <param-name>path</param-name>
>             <param-value>WEB-INF/conf</param-value>
>         </init-param>
>         <load-on-startup>1</load-on-startup>
>     </servlet>
>
> package com.blob;
>
> //import statements left out.
>
> public class PropertyReader extends HttpServlet{
>     public void init() throws ServletException {
>         //Setting the rootPath property for freemarker template setup.
>
> Configuration.getInstance().getProps().put("rootPath",this.getServletContext().getRealPath(""));
>         String path = this.getInitParameter("path");
>         String realPath = this.getServletContext().getRealPath(path);
>         File dir = new File(realPath);
>         for (File file : dir.listFiles()) {
>             if (file.getName().endsWith(".properties")) {
>                 try {
>                     Properties props = new Properties();
>                     props.load(new FileInputStream(file));
>                     Enumeration enumeration = props.keys();
>                     while (enumeration.hasMoreElements()){
>                         String key = (String) enumeration.nextElement();
>                         System.out.println("Adding parameter "+key);
>
> Configuration.getInstance().getProps().put(key,props.getProperty(key).trim());
>                         System.out.println("Added parameter "+key);
>                     }
>                 } catch (IOException ex) {
>                     ex.printStackTrace();
>                 }
>             }
>         }
>     }
>
> 2008/11/18 Abhi <[EMAIL PROTECTED]>
>
>> I don't know as to whether I am wishing for too much here but for sure
>> would like to know :).
>>
>> Does Stripes provide some way to read properties file and make the key
>> value pairs available in the action beans? I know I can use the
>> StripesResources.properties file. But I don't want to put my non stripes
>> configuration stuff in there.
>>
>> --
>> Cheers,
>> Abhi
>>
>> -------------------------------------------------------------------------
>> This SF.Net email is sponsored by the Moblin Your Move Developer's
>> challenge
>> Build the coolest Linux based applications with Moblin SDK & win great
>> prizes
>> Grand prize is a trip for two to an Open Source event anywhere in the
>> world
>> http://moblin-contest.org/redirect.php?banner_id=100&url=/
>> _______________________________________________
>> Stripes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>>
>
>
> --
>  Morten Matras
>  Consultant
>  Blob Communication ApS
>  Svendsagervej 42
>  DK-5240 Odense NĂ˜
>  P: (+45) 76 6-5-4-3-2-1
>  W: www.blobcom.com
>  E: [EMAIL PROTECTED]
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win great
> prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>


-- 
Cheers,
Abhi
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to