-
1. Re: Using Velocity or XSLT Templates in Seam
shane.bryzak Jun 1, 2006 5:23 PM (in response to dhinojosa)Create your own response resource loader by extending org.apache.velocity.runtime.resource.loader.ResourceLoader, and override the getResourceStream() method. Then set the Velocity engine "service.resource.loader.class" property to point to your new resource loader class. Then you can use getClass().getResourceAsStream(<resource name goes here>) to load your templates.
-
2. Re: Using Velocity or XSLT Templates in Seam
dhinojosa Jun 6, 2006 1:48 PM (in response to dhinojosa)and what shall I put in getResourceAsStream() ?
-
3. Re: Using Velocity or XSLT Templates in Seam
shane.bryzak Jun 6, 2006 5:14 PM (in response to dhinojosa)The path to the file containing your Velocity template. So for example, if you're storing your templates in the WEB-INF directory and they have a .template extension, your getResourceStream() method would look like this:
public InputStream getResourceStream(String source) throws ResourceNotFoundException { return getClass().getResourceAsStream( String.format("/WEB-INF/%s.template", source)); }
-
4. Re: Using Velocity or XSLT Templates in Seam
dhinojosa Jun 11, 2006 11:11 PM (in response to dhinojosa)Thanks for your help, but I don't think I can or should rely on /WEB-INF/. That way I can reuse those same beans that have non-web-based clients. I think the ultimate best solution could be a JMX setup so that we can get a velocity context injected into a stateless or stateful bean.
IOW, something like this
@Stateful
public class MySessionBean {
@Resource(name="apache/env/VelocityContext")
private VelocityContext velocityContext;
} -
5. Re: Using Velocity or XSLT Templates in Seam
shane.bryzak Jun 12, 2006 11:29 AM (in response to dhinojosa)The template resources could come from anywhere; a directory in your application archive, db table, etc - your resource loader just has to load them from somewhere. Personally I'd use an application-scoped bean to wrap the velocity context, annotate it with @Startup and define a @Create method that initialises the velocity context and possibly loads and caches your templates.
If you want to expose it as an MBean then you'd have to write it as a JBoss service and provide a management interface, but I don't really see any advantage to doing this unless you have special requirements.