You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Andrew Mason <an...@assertis.co.uk> on 2005/10/10 18:12:38 UTC

VelocityServlet and Properties file

Ok, I know VelocityServlet is depricated in favour of the VelocityViewServlet 
but i started my web-app before VelocityServlet became deprecated so to keep 
consistency (for now) i'm using it.

Anyway my problem is that my servlet can't seem to find my template. I've 
tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem like it wants 
to pick it up at all. Also i'm not sure that its picking up the 
velocity.properties.fileloader file. 

I got around this problem in the other servlets by overwriting the 
loadConfig() and making a new instance of Property. This was fine until i 
actually wanted to specify some of my own and it would be handy to have them 
all in one place.

thanks in advance

public class EditPage extends VelocityServlet{


	public Template handleRequest(HttpServletRequest request,
		HttpServletResponse response,Context context) {

		// stuff in here
		//Merge the Template now
			try{
                		String templateName="edit.vm";
				template = getTemplate(templateName);
			}
			catch(ResourceNotFoundException rnfe){
		                System.out.println(templateName);
				rnfe.printStackTrace();
			}
			catch(Exception e){
				e.printStackTrace();
			}
		return template;
		
	}
}

and my directory structure works like this (slightly different to normal as it 
allows me to use mod_jk to map www.domain.com to / )

	-/myapp/
			/obb/
			  	WEB-INF/
						classes/  
						lib/  
						- velocity.properties.fileloader 
						- web.xml
	- obb.war
	- edit.vm
	- index.vm


velocity.properties.fileloader
----------------

resource.loader = file
file.resource.loader.description = Velocity File Resource Loader
file.resource.loader.class = 
org.apache.velocity.runtime.resource.loader.FileResourceLoader
file.resource.loader.path = .
file.resource.loader.cache = false
file.resource.loader.modificationCheckInterval = 0

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


Re: VelocityServlet and Properties file

Posted by Andrew Mason <an...@assertis.co.uk>.
Ah....thats why. I haven't been using any of the velocity tools :) 

thanks
On Mon October 17 2005 10:47 am, Claude Brisson wrote:
> On Mon, 2005-10-17 at 09:28 +0100, Andrew Mason wrote:
> > Thanks Wil,
> > Where abouts is the WebappLoader located? I can't seem to see
> > WebappLoader  in the Velocity 1.4 API, the JDK Api or Tomcats Api.
>
> It's in the velocity-tools jar.
>
> --
> Claude
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

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


Re: VelocityServlet and Properties file

Posted by Claude Brisson <cl...@renegat.net>.
On Mon, 2005-10-17 at 09:28 +0100, Andrew Mason wrote:
> Thanks Wil,
> Where abouts is the WebappLoader located? I can't seem to see WebappLoader  in 
> the Velocity 1.4 API, the JDK Api or Tomcats Api.

It's in the velocity-tools jar.

--
Claude



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


Re: VelocityServlet and Properties file

Posted by Andrew Mason <an...@assertis.co.uk>.
Thanks Wil,
Where abouts is the WebappLoader located? I can't seem to see WebappLoader  in 
the Velocity 1.4 API, the JDK Api or Tomcats Api.

regards
Andrew M
On Sun October 16 2005 4:26 pm, Will Glass-Husain wrote:
> You need to import the RuntimeConstants and WebappLoader classes.
>
> WIL
>
> ----- Original Message -----
> From: "Andrew Mason" <an...@assertis.co.uk>
> To: "Velocity Users List" <ve...@jakarta.apache.org>
> Sent: Sunday, October 16, 2005 5:48 AM
> Subject: Re: VelocityServlet and Properties file
>
> > Sorry if i seem a bit dense but i'm still having alot of trouble getting
> > this
> > to work.
> >
> > in my loadConfiguration() i tried
> > {
> >   Properties p = super.loadConfiguration(config);
> >
> > Velocity.setApplicationAttribute("javax.servlet.ServletContext",config.ge
> >tServletContext()); p.setProperty(RuntimeConstants.RESOURCE_LOADER,
> > "webapp");
> > p.setProperty("webapp.resource.loader.class",WebappLoader.class.getName()
> >);
> >
> >
> > }
> > but then i would get the following errors
> >
> >    [javac] Compiling 1 source file
> > to /home/am/OnlineBizBuilder/obb/WEB-INF/classes
> >
> > [javac]
> > /home/am/OnlineBizBuilder/source/com/assertis/obb/LinkManager.java:52:
> > cannot find symbol
> >    [javac] symbol  : variable RuntimeConstants
> >    [javac] location: class com.assertis.obb.LinkManager
> >    [javac]         p.setProperty(RuntimeConstants.RESOURCE_LOADER,
> > "webapp");
> >    [javac]                              ^
> >
> > [javac]
> > /home/am/OnlineBizBuilder/source/com/assertis/obb/LinkManager.java:53:
> > cannot find symbol
> >    [javac] symbol  : class WebappLoader
> >    [javac] location: class com.assertis.obb.LinkManager
> >    [javac]
> > p.setProperty("webapp.resource.loader.class",WebappLoader.class.getName()
> >); [javac]                                                         ^
> > [javac] 2 errors
> >
> >
> >
> > This is my properties file which is located
> > in /obb/WEB-INF/velocity.properties
> >
> > resource.loader = class
> > class.resource.loader.class =
> > org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> > runtime.log = velocity2.log
> > file.resource.loader.cache = false
> > file.resource.manager.logwhenfound = false
> >
> > i would like to be able to set all of the velocity options from this file
> > ,
> > and IF possible, allow my webapp to use it for its properties too, since
> > i am
> > loading it up for velocity anyway (which all of my servlets use).
> >
> > Many thanks
> >
> > Andrew M
> >
> > On Tue October 11 2005 3:37 pm, Nathan Bubna wrote:
> >> On 10/11/05, Andrew Mason <an...@assertis.co.uk> wrote:
> >> > Is this done in  handleRequest() ?
> >>
> >> no, no, no.  this should be handled only once during servlet init via
> >> the overridden loadConfiguration method that Jason suggested.  and
> >> though i didn't include it in my example, the first part of his
> >> suggestion should still be included:
> >>
> >>        //Configuration file to be read is specified as
> >>        //the init param 'org.apache.velocity.properties'
> >>        Properties p = super.loadConfiguration(config);
> >>
> >> > > Velocity.setApplicationAttribute("javax.servlet.ServletContext",
> >> > > config.getServletContext());
> >> > >
> >> > >         // by default, load resources with webapp resource loader
> >> > >         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
> >> > >         p.setProperty("webapp.resource.loader.class",
> >> > > WebappLoader.class.getName());
> >> > >
> >> > >
> >> > > this will make the webapp root the default search path, but you can
> >> > > specify others (relative to the webapp root) using as many
> >> > > "webapp.resource.loader.path" properties as you like.
> >> > >
> >> > > > The only other thing you'll need is that you tell the servlet in
> >> > > > your
> >> > > > web.xml where to find the default properties bundle:
> >> > > >
> >> > > >   <servlet>
> >> > > >     <servlet-name>getter</servlet-name>
> >> > > >
> >> > > > <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
> >> > > > <init-param>
> >> > > >         <param-name>org.apache.velocity.properties</param-name>
> >> > > >         <param-value>/WEB-INF/velocity.properties</param-value>
> >> > > >     </init-param>
> >> > > >     <load-on-startup>2</load-on-startup>
> >> > > >   </servlet>
> >> >
> >> > Do i have to do this on a  / servlet basis ? or can i just use a
> >> > context
> >> > param since its the same for all my servlets ?
> >>
> >> both VelocityServlet and VelocityViewServlet will first search the
> >> servlet config's init-params, then search the servlet context's
> >> init-params.  so the answers to your questions are no and yes,
> >> respectively.
> >>
> >> > > > And the only thing I need in my velocity.properties is:
> >> > > >
> >> > > > runtime.log.logsystem.class=org.foo.bar.VelocityLogger
> >> > > >
> >> > > > Since I have a custom logger.  The rest of the file loader stuff
> >> > > > except for the modfication interval you should just remove since I
> >> > > > think those are the defaults anyway, except for the path, which
> >> > > > we're
> >> > > > setting with our loadConfiguration method.
> >> > > >
> >> > > > You might look at the implementation for the super
> >> > > > loadConfiguration
> >> > > > method-- but it may require that velocity.properties actually end
> >> > > > with a ".properties" extension.  I doubt it, but if you do all
> >> > > > this and it still seems your file is being ignored, try that.
> >> > > >
> >> > > > --jason
> >> > > >
> >> > > > Andrew Mason wrote:
> >> > > > >Ok, I know VelocityServlet is depricated in favour of the
> >> > > > > VelocityViewServlet but i started my web-app before
> >> > > > > VelocityServlet
> >> > > > > became deprecated so to keep consistency (for now) i'm using it.
> >> > > > >
> >> > > > >Anyway my problem is that my servlet can't seem to find my
> >> > > > >template.
> >> > > > > I've tried putting it in / , /obb, /obb/WEB-INF but it doesn't
> >> > > > > seem
> >> > > > > like it wants to pick it up at all. Also i'm not sure that its
> >> > > > > picking up the velocity.properties.fileloader file.
> >> > > > >
> >> > > > >I got around this problem in the other servlets by overwriting
> >> > > > > the loadConfig() and making a new instance of Property. This was
> >> > > > > fine until i actually wanted to specify some of my own and it
> >> > > > > would be handy to have them all in one place.
> >> > > > >
> >> > > > >thanks in advance
> >> > > > >
> >> > > > >public class EditPage extends VelocityServlet{
> >> > > > >
> >> > > > >
> >> > > > >       public Template handleRequest(HttpServletRequest request,
> >> > > > >               HttpServletResponse response,Context context) {
> >> > > > >
> >> > > > >               // stuff in here
> >> > > > >               //Merge the Template now
> >> > > > >                       try{
> >> > > > >                               String templateName="edit.vm";
> >> > > > >                               template =
> >> > > > > getTemplate(templateName);
> >> > > > >                       }
> >> > > > >                       catch(ResourceNotFoundException rnfe){
> >> > > > >                               System.out.println(templateName);
> >> > > > >                               rnfe.printStackTrace();
> >> > > > >                       }
> >> > > > >                       catch(Exception e){
> >> > > > >                               e.printStackTrace();
> >> > > > >                       }
> >> > > > >               return template;
> >> > > > >
> >> > > > >       }
> >> > > > >}
> >> > > > >
> >> > > > >and my directory structure works like this (slightly different to
> >> > > > > normal as it allows me to use mod_jk to map www.domain.com to /
> >> > > > > )
> >> > > > >
> >> > > > >       -/myapp/
> >> > > > >                       /obb/
> >> > > > >                               WEB-INF/
> >> > > > >                                               classes/
> >> > > > >                                               lib/
> >> > > > >                                               -
> >> > > > > velocity.properties.fileloader - web.xml
> >> > > > >       - obb.war
> >> > > > >       - edit.vm
> >> > > > >       - index.vm
> >> > > > >
> >> > > > >
> >> > > > >velocity.properties.fileloader
> >> > > > >----------------
> >> > > > >
> >> > > > >resource.loader = file
> >> > > > >file.resource.loader.description = Velocity File Resource Loader
> >> > > > >file.resource.loader.class =
> >> > > > >org.apache.velocity.runtime.resource.loader.FileResourceLoader
> >> > > > >file.resource.loader.path = .
> >> > > > >file.resource.loader.cache = false
> >> > > > >file.resource.loader.modificationCheckInterval = 0
> >> > > > >
> >> > > > >-----------------------------------------------------------------
> >> > > > >--- - To unsubscribe, e-mail:
> >> > > > > velocity-user-unsubscribe@jakarta.apache.org For additional
> >> > > > > commands, e-mail: velocity-user-help@jakarta.apache.org
> >> > > >
> >> > > > ------------------------------------------------------------------
> >> > > >--- To unsubscribe, e-mail:
> >> > > > velocity-user-unsubscribe@jakarta.apache.org
> >> > > > For additional commands, e-mail:
> >> > > > velocity-user-help@jakarta.apache.org
> >> > >
> >> > > --------------------------------------------------------------------
> >> > >- To unsubscribe, e-mail:
> >> > > velocity-user-unsubscribe@jakarta.apache.org For additional
> >> > > commands, e-mail:
> >> > > velocity-user-help@jakarta.apache.org
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

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


Re: VelocityServlet and Properties file

Posted by Will Glass-Husain <wg...@forio.com>.
You need to import the RuntimeConstants and WebappLoader classes.

WIL

----- Original Message ----- 
From: "Andrew Mason" <an...@assertis.co.uk>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Sunday, October 16, 2005 5:48 AM
Subject: Re: VelocityServlet and Properties file


> Sorry if i seem a bit dense but i'm still having alot of trouble getting 
> this
> to work.
>
> in my loadConfiguration() i tried
> {
>   Properties p = super.loadConfiguration(config);
>
> Velocity.setApplicationAttribute("javax.servlet.ServletContext",config.getServletContext());
> p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
> p.setProperty("webapp.resource.loader.class",WebappLoader.class.getName());
>
>
> }
> but then i would get the following errors
>
>    [javac] Compiling 1 source file
> to /home/am/OnlineBizBuilder/obb/WEB-INF/classes
>
> [javac] 
> /home/am/OnlineBizBuilder/source/com/assertis/obb/LinkManager.java:52:
> cannot find symbol
>    [javac] symbol  : variable RuntimeConstants
>    [javac] location: class com.assertis.obb.LinkManager
>    [javac]         p.setProperty(RuntimeConstants.RESOURCE_LOADER, 
> "webapp");
>    [javac]                              ^
>
> [javac] 
> /home/am/OnlineBizBuilder/source/com/assertis/obb/LinkManager.java:53:
> cannot find symbol
>    [javac] symbol  : class WebappLoader
>    [javac] location: class com.assertis.obb.LinkManager
>    [javac]
> p.setProperty("webapp.resource.loader.class",WebappLoader.class.getName());
>    [javac]                                                         ^
>    [javac] 2 errors
>
>
>
> This is my properties file which is located
> in /obb/WEB-INF/velocity.properties
>
> resource.loader = class
> class.resource.loader.class =
> org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
> runtime.log = velocity2.log
> file.resource.loader.cache = false
> file.resource.manager.logwhenfound = false
>
> i would like to be able to set all of the velocity options from this file 
> ,
> and IF possible, allow my webapp to use it for its properties too, since i 
> am
> loading it up for velocity anyway (which all of my servlets use).
>
> Many thanks
>
> Andrew M
>
>
>
>
>
>
>
> On Tue October 11 2005 3:37 pm, Nathan Bubna wrote:
>> On 10/11/05, Andrew Mason <an...@assertis.co.uk> wrote:
>> > Is this done in  handleRequest() ?
>>
>> no, no, no.  this should be handled only once during servlet init via
>> the overridden loadConfiguration method that Jason suggested.  and
>> though i didn't include it in my example, the first part of his
>> suggestion should still be included:
>>
>>        //Configuration file to be read is specified as
>>        //the init param 'org.apache.velocity.properties'
>>        Properties p = super.loadConfiguration(config);
>>
>> > >
>> > > Velocity.setApplicationAttribute("javax.servlet.ServletContext",
>> > > config.getServletContext());
>> > >
>> > >         // by default, load resources with webapp resource loader
>> > >         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
>> > >         p.setProperty("webapp.resource.loader.class",
>> > > WebappLoader.class.getName());
>> > >
>> > >
>> > > this will make the webapp root the default search path, but you can
>> > > specify others (relative to the webapp root) using as many
>> > > "webapp.resource.loader.path" properties as you like.
>> > >
>> > > > The only other thing you'll need is that you tell the servlet in 
>> > > > your
>> > > > web.xml where to find the default properties bundle:
>> > > >
>> > > >   <servlet>
>> > > >     <servlet-name>getter</servlet-name>
>> > > >
>> > > > <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
>> > > > <init-param>
>> > > >         <param-name>org.apache.velocity.properties</param-name>
>> > > >         <param-value>/WEB-INF/velocity.properties</param-value>
>> > > >     </init-param>
>> > > >     <load-on-startup>2</load-on-startup>
>> > > >   </servlet>
>> >
>> > Do i have to do this on a  / servlet basis ? or can i just use a 
>> > context
>> > param since its the same for all my servlets ?
>>
>> both VelocityServlet and VelocityViewServlet will first search the
>> servlet config's init-params, then search the servlet context's
>> init-params.  so the answers to your questions are no and yes,
>> respectively.
>>
>> > > > And the only thing I need in my velocity.properties is:
>> > > >
>> > > > runtime.log.logsystem.class=org.foo.bar.VelocityLogger
>> > > >
>> > > > Since I have a custom logger.  The rest of the file loader stuff
>> > > > except for the modfication interval you should just remove since I
>> > > > think those are the defaults anyway, except for the path, which 
>> > > > we're
>> > > > setting with our loadConfiguration method.
>> > > >
>> > > > You might look at the implementation for the super 
>> > > > loadConfiguration
>> > > > method-- but it may require that velocity.properties actually end
>> > > > with a ".properties" extension.  I doubt it, but if you do all this
>> > > > and it still seems your file is being ignored, try that.
>> > > >
>> > > > --jason
>> > > >
>> > > > Andrew Mason wrote:
>> > > > >Ok, I know VelocityServlet is depricated in favour of the
>> > > > > VelocityViewServlet but i started my web-app before 
>> > > > > VelocityServlet
>> > > > > became deprecated so to keep consistency (for now) i'm using it.
>> > > > >
>> > > > >Anyway my problem is that my servlet can't seem to find my 
>> > > > >template.
>> > > > > I've tried putting it in / , /obb, /obb/WEB-INF but it doesn't 
>> > > > > seem
>> > > > > like it wants to pick it up at all. Also i'm not sure that its
>> > > > > picking up the velocity.properties.fileloader file.
>> > > > >
>> > > > >I got around this problem in the other servlets by overwriting the
>> > > > >loadConfig() and making a new instance of Property. This was fine
>> > > > > until i actually wanted to specify some of my own and it would be
>> > > > > handy to have them all in one place.
>> > > > >
>> > > > >thanks in advance
>> > > > >
>> > > > >public class EditPage extends VelocityServlet{
>> > > > >
>> > > > >
>> > > > >       public Template handleRequest(HttpServletRequest request,
>> > > > >               HttpServletResponse response,Context context) {
>> > > > >
>> > > > >               // stuff in here
>> > > > >               //Merge the Template now
>> > > > >                       try{
>> > > > >                               String templateName="edit.vm";
>> > > > >                               template = 
>> > > > > getTemplate(templateName);
>> > > > >                       }
>> > > > >                       catch(ResourceNotFoundException rnfe){
>> > > > >                               System.out.println(templateName);
>> > > > >                               rnfe.printStackTrace();
>> > > > >                       }
>> > > > >                       catch(Exception e){
>> > > > >                               e.printStackTrace();
>> > > > >                       }
>> > > > >               return template;
>> > > > >
>> > > > >       }
>> > > > >}
>> > > > >
>> > > > >and my directory structure works like this (slightly different to
>> > > > > normal as it allows me to use mod_jk to map www.domain.com to / )
>> > > > >
>> > > > >       -/myapp/
>> > > > >                       /obb/
>> > > > >                               WEB-INF/
>> > > > >                                               classes/
>> > > > >                                               lib/
>> > > > >                                               -
>> > > > > velocity.properties.fileloader - web.xml
>> > > > >       - obb.war
>> > > > >       - edit.vm
>> > > > >       - index.vm
>> > > > >
>> > > > >
>> > > > >velocity.properties.fileloader
>> > > > >----------------
>> > > > >
>> > > > >resource.loader = file
>> > > > >file.resource.loader.description = Velocity File Resource Loader
>> > > > >file.resource.loader.class =
>> > > > >org.apache.velocity.runtime.resource.loader.FileResourceLoader
>> > > > >file.resource.loader.path = .
>> > > > >file.resource.loader.cache = false
>> > > > >file.resource.loader.modificationCheckInterval = 0
>> > > > >
>> > > > >--------------------------------------------------------------------
>> > > > >- To unsubscribe, e-mail:
>> > > > > velocity-user-unsubscribe@jakarta.apache.org For additional
>> > > > > commands, e-mail: velocity-user-help@jakarta.apache.org
>> > > >
>> > > > ---------------------------------------------------------------------
>> > > > To unsubscribe, e-mail: 
>> > > > velocity-user-unsubscribe@jakarta.apache.org
>> > > > For additional commands, e-mail:
>> > > > velocity-user-help@jakarta.apache.org
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> > > For additional commands, e-mail: 
>> > > velocity-user-help@jakarta.apache.org
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 


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


Re: VelocityServlet and Properties file

Posted by Andrew Mason <an...@assertis.co.uk>.
Sorry if i seem a bit dense but i'm still having alot of trouble getting this 
to work. 

in my loadConfiguration() i tried
{
   Properties p = super.loadConfiguration(config);
 
Velocity.setApplicationAttribute("javax.servlet.ServletContext",config.getServletContext());          
p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");        
p.setProperty("webapp.resource.loader.class",WebappLoader.class.getName());


}
but then i would get the following errors

    [javac] Compiling 1 source file 
to /home/am/OnlineBizBuilder/obb/WEB-INF/classes
    
[javac] /home/am/OnlineBizBuilder/source/com/assertis/obb/LinkManager.java:52: 
cannot find symbol
    [javac] symbol  : variable RuntimeConstants
    [javac] location: class com.assertis.obb.LinkManager
    [javac]         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
    [javac]                              ^
    
[javac] /home/am/OnlineBizBuilder/source/com/assertis/obb/LinkManager.java:53: 
cannot find symbol
    [javac] symbol  : class WebappLoader
    [javac] location: class com.assertis.obb.LinkManager
    [javac]         
p.setProperty("webapp.resource.loader.class",WebappLoader.class.getName());
    [javac]                                                         ^
    [javac] 2 errors



This is my properties file which is located 
in /obb/WEB-INF/velocity.properties

resource.loader = class
class.resource.loader.class = 
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
runtime.log = velocity2.log
file.resource.loader.cache = false
file.resource.manager.logwhenfound = false

i would like to be able to set all of the velocity options from this file , 
and IF possible, allow my webapp to use it for its properties too, since i am 
loading it up for velocity anyway (which all of my servlets use).

Many thanks

Andrew M







On Tue October 11 2005 3:37 pm, Nathan Bubna wrote:
> On 10/11/05, Andrew Mason <an...@assertis.co.uk> wrote:
> > Is this done in  handleRequest() ?
>
> no, no, no.  this should be handled only once during servlet init via
> the overridden loadConfiguration method that Jason suggested.  and
> though i didn't include it in my example, the first part of his
> suggestion should still be included:
>
>        //Configuration file to be read is specified as
>        //the init param 'org.apache.velocity.properties'
>        Properties p = super.loadConfiguration(config);
>
> > >        
> > > Velocity.setApplicationAttribute("javax.servlet.ServletContext",
> > > config.getServletContext());
> > >
> > >         // by default, load resources with webapp resource loader
> > >         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
> > >         p.setProperty("webapp.resource.loader.class",
> > > WebappLoader.class.getName());
> > >
> > >
> > > this will make the webapp root the default search path, but you can
> > > specify others (relative to the webapp root) using as many
> > > "webapp.resource.loader.path" properties as you like.
> > >
> > > > The only other thing you'll need is that you tell the servlet in your
> > > > web.xml where to find the default properties bundle:
> > > >
> > > >   <servlet>
> > > >     <servlet-name>getter</servlet-name>
> > > >    
> > > > <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
> > > > <init-param>
> > > >         <param-name>org.apache.velocity.properties</param-name>
> > > >         <param-value>/WEB-INF/velocity.properties</param-value>
> > > >     </init-param>
> > > >     <load-on-startup>2</load-on-startup>
> > > >   </servlet>
> >
> > Do i have to do this on a  / servlet basis ? or can i just use a context
> > param since its the same for all my servlets ?
>
> both VelocityServlet and VelocityViewServlet will first search the
> servlet config's init-params, then search the servlet context's
> init-params.  so the answers to your questions are no and yes,
> respectively.
>
> > > > And the only thing I need in my velocity.properties is:
> > > >
> > > > runtime.log.logsystem.class=org.foo.bar.VelocityLogger
> > > >
> > > > Since I have a custom logger.  The rest of the file loader stuff
> > > > except for the modfication interval you should just remove since I
> > > > think those are the defaults anyway, except for the path, which we're
> > > > setting with our loadConfiguration method.
> > > >
> > > > You might look at the implementation for the super loadConfiguration
> > > > method-- but it may require that velocity.properties actually end
> > > > with a ".properties" extension.  I doubt it, but if you do all this
> > > > and it still seems your file is being ignored, try that.
> > > >
> > > > --jason
> > > >
> > > > Andrew Mason wrote:
> > > > >Ok, I know VelocityServlet is depricated in favour of the
> > > > > VelocityViewServlet but i started my web-app before VelocityServlet
> > > > > became deprecated so to keep consistency (for now) i'm using it.
> > > > >
> > > > >Anyway my problem is that my servlet can't seem to find my template.
> > > > > I've tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem
> > > > > like it wants to pick it up at all. Also i'm not sure that its
> > > > > picking up the velocity.properties.fileloader file.
> > > > >
> > > > >I got around this problem in the other servlets by overwriting the
> > > > >loadConfig() and making a new instance of Property. This was fine
> > > > > until i actually wanted to specify some of my own and it would be
> > > > > handy to have them all in one place.
> > > > >
> > > > >thanks in advance
> > > > >
> > > > >public class EditPage extends VelocityServlet{
> > > > >
> > > > >
> > > > >       public Template handleRequest(HttpServletRequest request,
> > > > >               HttpServletResponse response,Context context) {
> > > > >
> > > > >               // stuff in here
> > > > >               //Merge the Template now
> > > > >                       try{
> > > > >                               String templateName="edit.vm";
> > > > >                               template = getTemplate(templateName);
> > > > >                       }
> > > > >                       catch(ResourceNotFoundException rnfe){
> > > > >                               System.out.println(templateName);
> > > > >                               rnfe.printStackTrace();
> > > > >                       }
> > > > >                       catch(Exception e){
> > > > >                               e.printStackTrace();
> > > > >                       }
> > > > >               return template;
> > > > >
> > > > >       }
> > > > >}
> > > > >
> > > > >and my directory structure works like this (slightly different to
> > > > > normal as it allows me to use mod_jk to map www.domain.com to / )
> > > > >
> > > > >       -/myapp/
> > > > >                       /obb/
> > > > >                               WEB-INF/
> > > > >                                               classes/
> > > > >                                               lib/
> > > > >                                               -
> > > > > velocity.properties.fileloader - web.xml
> > > > >       - obb.war
> > > > >       - edit.vm
> > > > >       - index.vm
> > > > >
> > > > >
> > > > >velocity.properties.fileloader
> > > > >----------------
> > > > >
> > > > >resource.loader = file
> > > > >file.resource.loader.description = Velocity File Resource Loader
> > > > >file.resource.loader.class =
> > > > >org.apache.velocity.runtime.resource.loader.FileResourceLoader
> > > > >file.resource.loader.path = .
> > > > >file.resource.loader.cache = false
> > > > >file.resource.loader.modificationCheckInterval = 0
> > > > >
> > > > >--------------------------------------------------------------------
> > > > >- To unsubscribe, e-mail:
> > > > > velocity-user-unsubscribe@jakarta.apache.org For additional
> > > > > commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > > > velocity-user-help@jakarta.apache.org
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

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


Re: VelocityServlet and Properties file

Posted by Andrew Mason <an...@assertis.co.uk>.
ah ok. Thanks. 
On Tue October 11 2005 3:37 pm, Nathan Bubna wrote:
> On 10/11/05, Andrew Mason <an...@assertis.co.uk> wrote:
> > Is this done in  handleRequest() ?
>
> no, no, no.  this should be handled only once during servlet init via
> the overridden loadConfiguration method that Jason suggested.  and
> though i didn't include it in my example, the first part of his
> suggestion should still be included:
>
>        //Configuration file to be read is specified as
>        //the init param 'org.apache.velocity.properties'
>        Properties p = super.loadConfiguration(config);
>
> > >        
> > > Velocity.setApplicationAttribute("javax.servlet.ServletContext",
> > > config.getServletContext());
> > >
> > >         // by default, load resources with webapp resource loader
> > >         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
> > >         p.setProperty("webapp.resource.loader.class",
> > > WebappLoader.class.getName());
> > >
> > >
> > > this will make the webapp root the default search path, but you can
> > > specify others (relative to the webapp root) using as many
> > > "webapp.resource.loader.path" properties as you like.
> > >
> > > > The only other thing you'll need is that you tell the servlet in your
> > > > web.xml where to find the default properties bundle:
> > > >
> > > >   <servlet>
> > > >     <servlet-name>getter</servlet-name>
> > > >    
> > > > <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
> > > > <init-param>
> > > >         <param-name>org.apache.velocity.properties</param-name>
> > > >         <param-value>/WEB-INF/velocity.properties</param-value>
> > > >     </init-param>
> > > >     <load-on-startup>2</load-on-startup>
> > > >   </servlet>
> >
> > Do i have to do this on a  / servlet basis ? or can i just use a context
> > param since its the same for all my servlets ?
>
> both VelocityServlet and VelocityViewServlet will first search the
> servlet config's init-params, then search the servlet context's
> init-params.  so the answers to your questions are no and yes,
> respectively.
>
> > > > And the only thing I need in my velocity.properties is:
> > > >
> > > > runtime.log.logsystem.class=org.foo.bar.VelocityLogger
> > > >
> > > > Since I have a custom logger.  The rest of the file loader stuff
> > > > except for the modfication interval you should just remove since I
> > > > think those are the defaults anyway, except for the path, which we're
> > > > setting with our loadConfiguration method.
> > > >
> > > > You might look at the implementation for the super loadConfiguration
> > > > method-- but it may require that velocity.properties actually end
> > > > with a ".properties" extension.  I doubt it, but if you do all this
> > > > and it still seems your file is being ignored, try that.
> > > >
> > > > --jason
> > > >
> > > > Andrew Mason wrote:
> > > > >Ok, I know VelocityServlet is depricated in favour of the
> > > > > VelocityViewServlet but i started my web-app before VelocityServlet
> > > > > became deprecated so to keep consistency (for now) i'm using it.
> > > > >
> > > > >Anyway my problem is that my servlet can't seem to find my template.
> > > > > I've tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem
> > > > > like it wants to pick it up at all. Also i'm not sure that its
> > > > > picking up the velocity.properties.fileloader file.
> > > > >
> > > > >I got around this problem in the other servlets by overwriting the
> > > > >loadConfig() and making a new instance of Property. This was fine
> > > > > until i actually wanted to specify some of my own and it would be
> > > > > handy to have them all in one place.
> > > > >
> > > > >thanks in advance
> > > > >
> > > > >public class EditPage extends VelocityServlet{
> > > > >
> > > > >
> > > > >       public Template handleRequest(HttpServletRequest request,
> > > > >               HttpServletResponse response,Context context) {
> > > > >
> > > > >               // stuff in here
> > > > >               //Merge the Template now
> > > > >                       try{
> > > > >                               String templateName="edit.vm";
> > > > >                               template = getTemplate(templateName);
> > > > >                       }
> > > > >                       catch(ResourceNotFoundException rnfe){
> > > > >                               System.out.println(templateName);
> > > > >                               rnfe.printStackTrace();
> > > > >                       }
> > > > >                       catch(Exception e){
> > > > >                               e.printStackTrace();
> > > > >                       }
> > > > >               return template;
> > > > >
> > > > >       }
> > > > >}
> > > > >
> > > > >and my directory structure works like this (slightly different to
> > > > > normal as it allows me to use mod_jk to map www.domain.com to / )
> > > > >
> > > > >       -/myapp/
> > > > >                       /obb/
> > > > >                               WEB-INF/
> > > > >                                               classes/
> > > > >                                               lib/
> > > > >                                               -
> > > > > velocity.properties.fileloader - web.xml
> > > > >       - obb.war
> > > > >       - edit.vm
> > > > >       - index.vm
> > > > >
> > > > >
> > > > >velocity.properties.fileloader
> > > > >----------------
> > > > >
> > > > >resource.loader = file
> > > > >file.resource.loader.description = Velocity File Resource Loader
> > > > >file.resource.loader.class =
> > > > >org.apache.velocity.runtime.resource.loader.FileResourceLoader
> > > > >file.resource.loader.path = .
> > > > >file.resource.loader.cache = false
> > > > >file.resource.loader.modificationCheckInterval = 0
> > > > >
> > > > >--------------------------------------------------------------------
> > > > >- To unsubscribe, e-mail:
> > > > > velocity-user-unsubscribe@jakarta.apache.org For additional
> > > > > commands, e-mail: velocity-user-help@jakarta.apache.org
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > > For additional commands, e-mail:
> > > > velocity-user-help@jakarta.apache.org
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

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


Re: VelocityServlet and Properties file

Posted by Nathan Bubna <nb...@gmail.com>.
On 10/11/05, Andrew Mason <an...@assertis.co.uk> wrote:
> Is this done in  handleRequest() ?

no, no, no.  this should be handled only once during servlet init via
the overridden loadConfiguration method that Jason suggested.  and
though i didn't include it in my example, the first part of his
suggestion should still be included:

       //Configuration file to be read is specified as
       //the init param 'org.apache.velocity.properties'
       Properties p = super.loadConfiguration(config);
> >
> >         Velocity.setApplicationAttribute("javax.servlet.ServletContext",
> > config.getServletContext());
> >
> >         // by default, load resources with webapp resource loader
> >         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
> >         p.setProperty("webapp.resource.loader.class",
> > WebappLoader.class.getName());
> >
> >
> > this will make the webapp root the default search path, but you can
> > specify others (relative to the webapp root) using as many
> > "webapp.resource.loader.path" properties as you like.
> >
> > > The only other thing you'll need is that you tell the servlet in your
> > > web.xml where to find the default properties bundle:
> > >
> > >   <servlet>
> > >     <servlet-name>getter</servlet-name>
> > >     <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
> > >     <init-param>
> > >         <param-name>org.apache.velocity.properties</param-name>
> > >         <param-value>/WEB-INF/velocity.properties</param-value>
> > >     </init-param>
> > >     <load-on-startup>2</load-on-startup>
> > >   </servlet>
> > >
> Do i have to do this on a  / servlet basis ? or can i just use a context param
> since its the same for all my servlets ?

both VelocityServlet and VelocityViewServlet will first search the
servlet config's init-params, then search the servlet context's
init-params.  so the answers to your questions are no and yes,
respectively.


> > > And the only thing I need in my velocity.properties is:
> > >
> > > runtime.log.logsystem.class=org.foo.bar.VelocityLogger
> > >
> > > Since I have a custom logger.  The rest of the file loader stuff except
> > > for the modfication interval you should just remove since I think those
> > > are the defaults anyway, except for the path, which we're setting with
> > > our loadConfiguration method.
> > >
> > > You might look at the implementation for the super loadConfiguration
> > > method-- but it may require that velocity.properties actually end with a
> > > ".properties" extension.  I doubt it, but if you do all this and it
> > > still seems your file is being ignored, try that.
> > >
> > > --jason
> > >
> > > Andrew Mason wrote:
> > > >Ok, I know VelocityServlet is depricated in favour of the
> > > > VelocityViewServlet but i started my web-app before VelocityServlet
> > > > became deprecated so to keep consistency (for now) i'm using it.
> > > >
> > > >Anyway my problem is that my servlet can't seem to find my template.
> > > > I've tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem
> > > > like it wants to pick it up at all. Also i'm not sure that its picking
> > > > up the velocity.properties.fileloader file.
> > > >
> > > >I got around this problem in the other servlets by overwriting the
> > > >loadConfig() and making a new instance of Property. This was fine until
> > > > i actually wanted to specify some of my own and it would be handy to
> > > > have them all in one place.
> > > >
> > > >thanks in advance
> > > >
> > > >public class EditPage extends VelocityServlet{
> > > >
> > > >
> > > >       public Template handleRequest(HttpServletRequest request,
> > > >               HttpServletResponse response,Context context) {
> > > >
> > > >               // stuff in here
> > > >               //Merge the Template now
> > > >                       try{
> > > >                               String templateName="edit.vm";
> > > >                               template = getTemplate(templateName);
> > > >                       }
> > > >                       catch(ResourceNotFoundException rnfe){
> > > >                               System.out.println(templateName);
> > > >                               rnfe.printStackTrace();
> > > >                       }
> > > >                       catch(Exception e){
> > > >                               e.printStackTrace();
> > > >                       }
> > > >               return template;
> > > >
> > > >       }
> > > >}
> > > >
> > > >and my directory structure works like this (slightly different to normal
> > > > as it allows me to use mod_jk to map www.domain.com to / )
> > > >
> > > >       -/myapp/
> > > >                       /obb/
> > > >                               WEB-INF/
> > > >                                               classes/
> > > >                                               lib/
> > > >                                               -
> > > > velocity.properties.fileloader - web.xml
> > > >       - obb.war
> > > >       - edit.vm
> > > >       - index.vm
> > > >
> > > >
> > > >velocity.properties.fileloader
> > > >----------------
> > > >
> > > >resource.loader = file
> > > >file.resource.loader.description = Velocity File Resource Loader
> > > >file.resource.loader.class =
> > > >org.apache.velocity.runtime.resource.loader.FileResourceLoader
> > > >file.resource.loader.path = .
> > > >file.resource.loader.cache = false
> > > >file.resource.loader.modificationCheckInterval = 0
> > > >
> > > >---------------------------------------------------------------------
> > > >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


Re: VelocityServlet and Properties file

Posted by Andrew Mason <an...@assertis.co.uk>.
Is this done in  handleRequest() ? 


>
>         Velocity.setApplicationAttribute("javax.servlet.ServletContext",
> config.getServletContext());
>
>         // by default, load resources with webapp resource loader
>         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
>         p.setProperty("webapp.resource.loader.class",
> WebappLoader.class.getName());
>
>
> this will make the webapp root the default search path, but you can
> specify others (relative to the webapp root) using as many
> "webapp.resource.loader.path" properties as you like.
>
> > The only other thing you'll need is that you tell the servlet in your
> > web.xml where to find the default properties bundle:
> >
> >   <servlet>
> >     <servlet-name>getter</servlet-name>
> >     <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
> >     <init-param>
> >         <param-name>org.apache.velocity.properties</param-name>
> >         <param-value>/WEB-INF/velocity.properties</param-value>
> >     </init-param>
> >     <load-on-startup>2</load-on-startup>
> >   </servlet>
> >
Do i have to do this on a  / servlet basis ? or can i just use a context param 
since its the same for all my servlets ?

> > And the only thing I need in my velocity.properties is:
> >
> > runtime.log.logsystem.class=org.foo.bar.VelocityLogger
> >
> > Since I have a custom logger.  The rest of the file loader stuff except
> > for the modfication interval you should just remove since I think those
> > are the defaults anyway, except for the path, which we're setting with
> > our loadConfiguration method.
> >
> > You might look at the implementation for the super loadConfiguration
> > method-- but it may require that velocity.properties actually end with a
> > ".properties" extension.  I doubt it, but if you do all this and it
> > still seems your file is being ignored, try that.
> >
> > --jason
> >
> > Andrew Mason wrote:
> > >Ok, I know VelocityServlet is depricated in favour of the
> > > VelocityViewServlet but i started my web-app before VelocityServlet
> > > became deprecated so to keep consistency (for now) i'm using it.
> > >
> > >Anyway my problem is that my servlet can't seem to find my template.
> > > I've tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem
> > > like it wants to pick it up at all. Also i'm not sure that its picking
> > > up the velocity.properties.fileloader file.
> > >
> > >I got around this problem in the other servlets by overwriting the
> > >loadConfig() and making a new instance of Property. This was fine until
> > > i actually wanted to specify some of my own and it would be handy to
> > > have them all in one place.
> > >
> > >thanks in advance
> > >
> > >public class EditPage extends VelocityServlet{
> > >
> > >
> > >       public Template handleRequest(HttpServletRequest request,
> > >               HttpServletResponse response,Context context) {
> > >
> > >               // stuff in here
> > >               //Merge the Template now
> > >                       try{
> > >                               String templateName="edit.vm";
> > >                               template = getTemplate(templateName);
> > >                       }
> > >                       catch(ResourceNotFoundException rnfe){
> > >                               System.out.println(templateName);
> > >                               rnfe.printStackTrace();
> > >                       }
> > >                       catch(Exception e){
> > >                               e.printStackTrace();
> > >                       }
> > >               return template;
> > >
> > >       }
> > >}
> > >
> > >and my directory structure works like this (slightly different to normal
> > > as it allows me to use mod_jk to map www.domain.com to / )
> > >
> > >       -/myapp/
> > >                       /obb/
> > >                               WEB-INF/
> > >                                               classes/
> > >                                               lib/
> > >                                               -
> > > velocity.properties.fileloader - web.xml
> > >       - obb.war
> > >       - edit.vm
> > >       - index.vm
> > >
> > >
> > >velocity.properties.fileloader
> > >----------------
> > >
> > >resource.loader = file
> > >file.resource.loader.description = Velocity File Resource Loader
> > >file.resource.loader.class =
> > >org.apache.velocity.runtime.resource.loader.FileResourceLoader
> > >file.resource.loader.path = .
> > >file.resource.loader.cache = false
> > >file.resource.loader.modificationCheckInterval = 0
> > >
> > >---------------------------------------------------------------------
> > >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org

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


Re: VelocityServlet and Properties file

Posted by Andrew Mason <an...@assertis.net>.
Thanks Nathan,
This is what i was trying to get it to (after checking out the source), 
but i couldn't work out how to do it. I will try this as soon as I get 
to work. I'm trying to make this as fool proof as possible for any 
developers that may come after me.
On 10/10/2005, at 8:53 PM, Nathan Bubna wrote:

> On 10/10/05, Jason Pettiss <ja...@thecatalis.com> wrote:
>> I have the same situation... this is what I do in my loadConfiguration
>> method:
>>
>>         //Configuration file to be read is specified as
>>         //the init param 'org.apache.velocity.properties'
>>         Properties p = super.loadConfiguration(config);
>>
>>         //For ease of use, our templates are found in our webapp,
>>         //just as if they were JSPs
>>         String path = 
>> makeServletContextPath(config.getServletContext());
>>
>>         //Tell Velocity where we expect our templates to be
>>         log.debug(Velocity.FILE_RESOURCE_LOADER_PATH+"="+path);
>>         p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
>>
>>         return p;
>>
>> Then I just put my templates in the same place as my JSP pages and if 
>> a
>> request comes in for /dir/foo.vtl I just serve that right up.
>
> this is what the WebappLoader used by the VelocityViewServlet does
> automatically.  you can use it without using the VelocityViewServlet,
> just specify it in your properties and put the servlet context into
> Velocity's application attributes.  it would be something along these
> lines for your example above:
>
>         
> Velocity.setApplicationAttribute("javax.servlet.ServletContext",
> config.getServletContext());
>
>         // by default, load resources with webapp resource loader
>         p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
>         p.setProperty("webapp.resource.loader.class",
> WebappLoader.class.getName());
>
>
> this will make the webapp root the default search path, but you can
> specify others (relative to the webapp root) using as many
> "webapp.resource.loader.path" properties as you like.
>
>> The only other thing you'll need is that you tell the servlet in your
>> web.xml where to find the default properties bundle:
>>
>>   <servlet>
>>     <servlet-name>getter</servlet-name>
>>     <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
>>     <init-param>
>>         <param-name>org.apache.velocity.properties</param-name>
>>         <param-value>/WEB-INF/velocity.properties</param-value>
>>     </init-param>
>>     <load-on-startup>2</load-on-startup>
>>   </servlet>
>>
>> And the only thing I need in my velocity.properties is:
>>
>> runtime.log.logsystem.class=org.foo.bar.VelocityLogger
>>
>> Since I have a custom logger.  The rest of the file loader stuff 
>> except
>> for the modfication interval you should just remove since I think 
>> those
>> are the defaults anyway, except for the path, which we're setting with
>> our loadConfiguration method.
>>
>> You might look at the implementation for the super loadConfiguration
>> method-- but it may require that velocity.properties actually end 
>> with a
>> ".properties" extension.  I doubt it, but if you do all this and it
>> still seems your file is being ignored, try that.
>>
>> --jason
>>
>> Andrew Mason wrote:
>>
>>> Ok, I know VelocityServlet is depricated in favour of the 
>>> VelocityViewServlet
>>> but i started my web-app before VelocityServlet became deprecated so 
>>> to keep
>>> consistency (for now) i'm using it.
>>>
>>> Anyway my problem is that my servlet can't seem to find my template. 
>>> I've
>>> tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem like 
>>> it wants
>>> to pick it up at all. Also i'm not sure that its picking up the
>>> velocity.properties.fileloader file.
>>>
>>> I got around this problem in the other servlets by overwriting the
>>> loadConfig() and making a new instance of Property. This was fine 
>>> until i
>>> actually wanted to specify some of my own and it would be handy to 
>>> have them
>>> all in one place.
>>>
>>> thanks in advance
>>>
>>> public class EditPage extends VelocityServlet{
>>>
>>>
>>>       public Template handleRequest(HttpServletRequest request,
>>>               HttpServletResponse response,Context context) {
>>>
>>>               // stuff in here
>>>               //Merge the Template now
>>>                       try{
>>>                               String templateName="edit.vm";
>>>                               template = getTemplate(templateName);
>>>                       }
>>>                       catch(ResourceNotFoundException rnfe){
>>>                               System.out.println(templateName);
>>>                               rnfe.printStackTrace();
>>>                       }
>>>                       catch(Exception e){
>>>                               e.printStackTrace();
>>>                       }
>>>               return template;
>>>
>>>       }
>>> }
>>>
>>> and my directory structure works like this (slightly different to 
>>> normal as it
>>> allows me to use mod_jk to map www.domain.com to / )
>>>
>>>       -/myapp/
>>>                       /obb/
>>>                               WEB-INF/
>>>                                               classes/
>>>                                               lib/
>>>                                               - 
>>> velocity.properties.fileloader
>>>                                               - web.xml
>>>       - obb.war
>>>       - edit.vm
>>>       - index.vm
>>>
>>>
>>> velocity.properties.fileloader
>>> ----------------
>>>
>>> resource.loader = file
>>> file.resource.loader.description = Velocity File Resource Loader
>>> file.resource.loader.class =
>>> org.apache.velocity.runtime.resource.loader.FileResourceLoader
>>> file.resource.loader.path = .
>>> file.resource.loader.cache = false
>>> file.resource.loader.modificationCheckInterval = 0
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: 
>>> velocity-user-help@jakarta.apache.org
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>

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


Re: VelocityServlet and Properties file

Posted by Nathan Bubna <nb...@gmail.com>.
On 10/10/05, Jason Pettiss <ja...@thecatalis.com> wrote:
> I have the same situation... this is what I do in my loadConfiguration
> method:
>
>         //Configuration file to be read is specified as
>         //the init param 'org.apache.velocity.properties'
>         Properties p = super.loadConfiguration(config);
>
>         //For ease of use, our templates are found in our webapp,
>         //just as if they were JSPs
>         String path = makeServletContextPath(config.getServletContext());
>
>         //Tell Velocity where we expect our templates to be
>         log.debug(Velocity.FILE_RESOURCE_LOADER_PATH+"="+path);
>         p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
>
>         return p;
>
> Then I just put my templates in the same place as my JSP pages and if a
> request comes in for /dir/foo.vtl I just serve that right up.

this is what the WebappLoader used by the VelocityViewServlet does
automatically.  you can use it without using the VelocityViewServlet,
just specify it in your properties and put the servlet context into
Velocity's application attributes.  it would be something along these
lines for your example above:

        Velocity.setApplicationAttribute("javax.servlet.ServletContext",
config.getServletContext());

        // by default, load resources with webapp resource loader
        p.setProperty(RuntimeConstants.RESOURCE_LOADER, "webapp");
        p.setProperty("webapp.resource.loader.class",
WebappLoader.class.getName());


this will make the webapp root the default search path, but you can
specify others (relative to the webapp root) using as many
"webapp.resource.loader.path" properties as you like.

> The only other thing you'll need is that you tell the servlet in your
> web.xml where to find the default properties bundle:
>
>   <servlet>
>     <servlet-name>getter</servlet-name>
>     <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
>     <init-param>
>         <param-name>org.apache.velocity.properties</param-name>
>         <param-value>/WEB-INF/velocity.properties</param-value>
>     </init-param>
>     <load-on-startup>2</load-on-startup>
>   </servlet>
>
> And the only thing I need in my velocity.properties is:
>
> runtime.log.logsystem.class=org.foo.bar.VelocityLogger
>
> Since I have a custom logger.  The rest of the file loader stuff except
> for the modfication interval you should just remove since I think those
> are the defaults anyway, except for the path, which we're setting with
> our loadConfiguration method.
>
> You might look at the implementation for the super loadConfiguration
> method-- but it may require that velocity.properties actually end with a
> ".properties" extension.  I doubt it, but if you do all this and it
> still seems your file is being ignored, try that.
>
> --jason
>
> Andrew Mason wrote:
>
> >Ok, I know VelocityServlet is depricated in favour of the VelocityViewServlet
> >but i started my web-app before VelocityServlet became deprecated so to keep
> >consistency (for now) i'm using it.
> >
> >Anyway my problem is that my servlet can't seem to find my template. I've
> >tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem like it wants
> >to pick it up at all. Also i'm not sure that its picking up the
> >velocity.properties.fileloader file.
> >
> >I got around this problem in the other servlets by overwriting the
> >loadConfig() and making a new instance of Property. This was fine until i
> >actually wanted to specify some of my own and it would be handy to have them
> >all in one place.
> >
> >thanks in advance
> >
> >public class EditPage extends VelocityServlet{
> >
> >
> >       public Template handleRequest(HttpServletRequest request,
> >               HttpServletResponse response,Context context) {
> >
> >               // stuff in here
> >               //Merge the Template now
> >                       try{
> >                               String templateName="edit.vm";
> >                               template = getTemplate(templateName);
> >                       }
> >                       catch(ResourceNotFoundException rnfe){
> >                               System.out.println(templateName);
> >                               rnfe.printStackTrace();
> >                       }
> >                       catch(Exception e){
> >                               e.printStackTrace();
> >                       }
> >               return template;
> >
> >       }
> >}
> >
> >and my directory structure works like this (slightly different to normal as it
> >allows me to use mod_jk to map www.domain.com to / )
> >
> >       -/myapp/
> >                       /obb/
> >                               WEB-INF/
> >                                               classes/
> >                                               lib/
> >                                               - velocity.properties.fileloader
> >                                               - web.xml
> >       - obb.war
> >       - edit.vm
> >       - index.vm
> >
> >
> >velocity.properties.fileloader
> >----------------
> >
> >resource.loader = file
> >file.resource.loader.description = Velocity File Resource Loader
> >file.resource.loader.class =
> >org.apache.velocity.runtime.resource.loader.FileResourceLoader
> >file.resource.loader.path = .
> >file.resource.loader.cache = false
> >file.resource.loader.modificationCheckInterval = 0
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

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


Re: VelocityServlet and Properties file

Posted by Jason Pettiss <ja...@TheCatalis.com>.
I have the same situation... this is what I do in my loadConfiguration 
method:

        //Configuration file to be read is specified as
        //the init param 'org.apache.velocity.properties'
        Properties p = super.loadConfiguration(config);

        //For ease of use, our templates are found in our webapp,
        //just as if they were JSPs
        String path = makeServletContextPath(config.getServletContext());

        //Tell Velocity where we expect our templates to be
        log.debug(Velocity.FILE_RESOURCE_LOADER_PATH+"="+path);
        p.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
       
        return p;

Then I just put my templates in the same place as my JSP pages and if a 
request comes in for /dir/foo.vtl I just serve that right up.

The only other thing you'll need is that you tell the servlet in your 
web.xml where to find the default properties bundle:

  <servlet>
    <servlet-name>getter</servlet-name>
    <servlet-class>org.foo.bar.MyCustomVelocityServlet</servlet-class>
    <init-param>
        <param-name>org.apache.velocity.properties</param-name>
        <param-value>/WEB-INF/velocity.properties</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>

And the only thing I need in my velocity.properties is:

runtime.log.logsystem.class=org.foo.bar.VelocityLogger

Since I have a custom logger.  The rest of the file loader stuff except 
for the modfication interval you should just remove since I think those 
are the defaults anyway, except for the path, which we're setting with 
our loadConfiguration method.

You might look at the implementation for the super loadConfiguration 
method-- but it may require that velocity.properties actually end with a 
".properties" extension.  I doubt it, but if you do all this and it 
still seems your file is being ignored, try that.

--jason

Andrew Mason wrote:

>Ok, I know VelocityServlet is depricated in favour of the VelocityViewServlet 
>but i started my web-app before VelocityServlet became deprecated so to keep 
>consistency (for now) i'm using it.
>
>Anyway my problem is that my servlet can't seem to find my template. I've 
>tried putting it in / , /obb, /obb/WEB-INF but it doesn't seem like it wants 
>to pick it up at all. Also i'm not sure that its picking up the 
>velocity.properties.fileloader file. 
>
>I got around this problem in the other servlets by overwriting the 
>loadConfig() and making a new instance of Property. This was fine until i 
>actually wanted to specify some of my own and it would be handy to have them 
>all in one place.
>
>thanks in advance
>
>public class EditPage extends VelocityServlet{
>
>
>	public Template handleRequest(HttpServletRequest request,
>		HttpServletResponse response,Context context) {
>
>		// stuff in here
>		//Merge the Template now
>			try{
>                		String templateName="edit.vm";
>				template = getTemplate(templateName);
>			}
>			catch(ResourceNotFoundException rnfe){
>		                System.out.println(templateName);
>				rnfe.printStackTrace();
>			}
>			catch(Exception e){
>				e.printStackTrace();
>			}
>		return template;
>		
>	}
>}
>
>and my directory structure works like this (slightly different to normal as it 
>allows me to use mod_jk to map www.domain.com to / )
>
>	-/myapp/
>			/obb/
>			  	WEB-INF/
>						classes/  
>						lib/  
>						- velocity.properties.fileloader 
>						- web.xml
>	- obb.war
>	- edit.vm
>	- index.vm
>
>
>velocity.properties.fileloader
>----------------
>
>resource.loader = file
>file.resource.loader.description = Velocity File Resource Loader
>file.resource.loader.class = 
>org.apache.velocity.runtime.resource.loader.FileResourceLoader
>file.resource.loader.path = .
>file.resource.loader.cache = false
>file.resource.loader.modificationCheckInterval = 0
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>  
>


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