You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Johannes Fiala <ve...@fwd.at> on 2003/06/14 11:59:32 UTC

[OT] Re: Using velocity decoupled from main sourcecode

Hi Jonathan,

Although this is getting a bit off topic here:

Could you briefly line out what's the main difference between JPublish and 
Niggle? 
Does JPublish/Niggle have a caching mechanism more advanced than 
Velocity's Hashtable mechanism?

thx alot
Johannes




Jonathan Revusky <jo...@revusky.com> 
Sent by: news <ne...@main.gmane.org>
09.06.2003 14:52
Please respond to
"Velocity Users List" <ve...@jakarta.apache.org>


To
velocity-user@jakarta.apache.org
cc

Subject
Re: Using velocity decoupled from main sourcecode






Johannes Fiala wrote:
> Hi there,
> 
> I'd like to use the Velocity framework, but I want to prevent my own app 

> from glueing with the Velocity packages.

There are various web frameworks that allow programmers to use different 
template engines using the same programmatic interface.

Specifically, you might look at JPublish, at http://www.jpublish.org/ 
which supports Velocity, FreeMarker, and Webmacro with a common View API.

You could look at Niggle (disclosure, I'm the author) that supports the 
same 3 template engines using a common API.

> 
> I plan to set up an TemplateInterface which will decouple my own 
> sourcecode from the real use of Velocity itself.

Basically, it's pretty straightforward. You create an abstract wrapper 
around the template and context objects, that protects you from knowing 
what the underlying template engine API is, and then instantiate and 
process them via some kind of abstract factory pattern.


> Has anybody else already done that or is there an implementation 
> suggestion (which methods should be part of such an interface) somehwere 

> in the Velocity source?

I think you could eyeball the JPublish or Niggle sources.

Regards,

Jonathan Revusky
--
lead developer, FreeMarker project, http://freemarker.org/
FreeMarker-Velocity comparison page: http://freemarker.org/fmVsVel.html

FreeMarker 2.3pre2 is out!

> 
> thx alot
> Johannes



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



Re: VelocityLayoutServlet mime type setting

Posted by Nathan Bubna <na...@esha.com>.
Tim Colson said:
> > I can't believe there's any way to generate a xls with velocity.
> > I'd bet they are returning csv and want excel to import?
>
> If the server sends the correct mime type, Excel will happily injest
> simple HTML with tables and stick it into a worksheet.

ah.  interesting.

...
> > > 3) extend VelocityLayoutServlet or VelocityViewServlet to create
> > > MyCustomVelocityServlet (or whatever) and just override the
> > > setContentType(req, res) to behave differently according to
> > a request
> > > parameter (or other request info).  that's why we pass that method
> > > both the request and the response..
> Ok, essentially that's the same as my #2 but with added flexibility. :-)
>
> Any reason I shouldn't just submit a patch for VelocityViewServlet to
> add that feature?

hmm.  i'm not sure how you are planning to implement this, but AFAICS, if this
were to be done in a way that would be generally useful, that would probably
make it so that users could arbitrarily set the content-type for any and every
request.  i don't think that's a Good Idea (tm).  the application should
decide what the content-type is for each request, not the user (IMHO).

Nathan Bubna
nathan@esha.com


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


RE: VelocityLayoutServlet mime type setting

Posted by Emilio Suarez <em...@cisco.com>.
Hi all,

Well this line did the trick...
#set ($foo = $response.setContentType("application/vnd.ms-excel"))

So no need to subclass the servlet or anything... it looks like it works as
it is supposed to.

Thanks,

-emilio

> -----Original Message-----
> From: Tim Colson [mailto:tcolson@cisco.com]
> Sent: Wednesday, June 18, 2003 9:01 PM
> To: 'Velocity Developers List'
> Subject: RE: VelocityLayoutServlet mime type setting
>
>
> > I can't believe there's any way to generate a xls with velocity.
> > I'd bet they are returning csv and want excel to import?
>
> If the server sends the correct mime type, Excel will happily injest
> simple HTML with tables and stick it into a worksheet.
>
> > seems to me i remember some problem with the
> > > output stream being opened already
> I was thinking that might be the case. Was hoping folks more familiar
> with the code could confirm/deny. ;-)  We'll try it
> empirically just for
> fun.
>
>
> > > 3) extend VelocityLayoutServlet or VelocityViewServlet to create
> > > MyCustomVelocityServlet (or whatever) and just override the
> > > setContentType(req, res) to behave differently according to
> > a request
> > > parameter (or other request info).  that's why we pass
> that method
> > > both the request and the response..
> Ok, essentially that's the same as my #2 but with added
> flexibility. :-)
>
> Any reason I shouldn't just submit a patch for VelocityViewServlet to
> add that feature?
>
> Timo
>
>

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


RE: VelocityLayoutServlet mime type setting

Posted by Tim Colson <tc...@cisco.com>.
> I can't believe there's any way to generate a xls with velocity.  
> I'd bet they are returning csv and want excel to import?

If the server sends the correct mime type, Excel will happily injest
simple HTML with tables and stick it into a worksheet. 

> seems to me i remember some problem with the
> > output stream being opened already 
I was thinking that might be the case. Was hoping folks more familiar
with the code could confirm/deny. ;-)  We'll try it empirically just for
fun.


> > 3) extend VelocityLayoutServlet or VelocityViewServlet to create 
> > MyCustomVelocityServlet (or whatever) and just override the 
> > setContentType(req, res) to behave differently according to 
> a request 
> > parameter (or other request info).  that's why we pass that method 
> > both the request and the response..
Ok, essentially that's the same as my #2 but with added flexibility. :-)

Any reason I shouldn't just submit a patch for VelocityViewServlet to
add that feature?

Timo


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


Re: VelocityLayoutServlet mime type setting

Posted by "Geir Magnusson Jr." <ge...@adeptra.com>.
On Wednesday, June 18, 2003, at 09:33 PM, Nathan Bubna wrote:

> Tim Colson said:
>> A colleage of mine needs the VelocityLayoutServlet output to spit out 
>> an
>> Excel mime type for some odd reason (damn users! ;-).
>
> interesting. and they're using velocity to generate the file?  seems 
> like
> jakarta-poi might be a better fit.  but, no matter...

I can't believe there's any way to generate a xls with velocity.  As 
part of the project that caused my disappearing act, we built a 
reporting system that returns PDF, XML, CSV, and XLS.  There's no way 
to do XLS with Velocity.

I'd bet they are returning csv and want excel to import?

>
> ...
>> So I'm going to play dumb and ask where/how it might be best to do 
>> what
>> he needs.
>> I do have two ideas:
>>
>> 1) response object is in the context, so perhaps the *.vm can override
>> it directly with a #set ($foo =
>> $response.setContentType("text/excel-something") )
>
> i don't think this will work.  seems to me i remember some problem 
> with the
> output stream being opened already at that point or something like 
> that.  but
> i can't recall offhand.  that's quick to do, so you could just try it. 
> :)

I had the same recollection.

>
>> 2) Create ExcelVelocityViewServlet which extends VelocityViewServlet 
>> and
>> override the setContentType()... then in the server config, map all
>> *.xvm files to that servlet.
>
> sure, if you want.  this should be fine.  but depending on your 
> situation, you
> may just prefer to:
>
> 3) extend VelocityLayoutServlet or VelocityViewServlet to create
> MyCustomVelocityServlet (or whatever) and just override the
> setContentType(req, res) to behave differently according to a request
> parameter (or other request info).  that's why we pass that method 
> both the
> request and the response..

+1

>
> Nathan Bubna
> nathan@esha.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-956-2604(w)
Adeptra, Inc.                                       203-434-2093(m)
geirm@adeptra.com                                   203-247-1713(m)


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


Re: VelocityLayoutServlet mime type setting

Posted by Nathan Bubna <na...@esha.com>.
Tim Colson said:
> A colleage of mine needs the VelocityLayoutServlet output to spit out an
> Excel mime type for some odd reason (damn users! ;-).

interesting. and they're using velocity to generate the file?  seems like
jakarta-poi might be a better fit.  but, no matter...

...
> So I'm going to play dumb and ask where/how it might be best to do what
> he needs.
> I do have two ideas:
>
> 1) response object is in the context, so perhaps the *.vm can override
> it directly with a #set ($foo =
> $response.setContentType("text/excel-something") )

i don't think this will work.  seems to me i remember some problem with the
output stream being opened already at that point or something like that.  but
i can't recall offhand.  that's quick to do, so you could just try it. :)

> 2) Create ExcelVelocityViewServlet which extends VelocityViewServlet and
> override the setContentType()... then in the server config, map all
> *.xvm files to that servlet.

sure, if you want.  this should be fine.  but depending on your situation, you
may just prefer to:

3) extend VelocityLayoutServlet or VelocityViewServlet to create
MyCustomVelocityServlet (or whatever) and just override the
setContentType(req, res) to behave differently according to a request
parameter (or other request info).  that's why we pass that method both the
request and the response..

Nathan Bubna
nathan@esha.com


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


VelocityLayoutServlet mime type setting

Posted by Tim Colson <tc...@cisco.com>.
Nathan et. al. -

A colleage of mine needs the VelocityLayoutServlet output to spit out an
Excel mime type for some odd reason (damn users! ;-).

I had a look through the src and found this in the base
VelocityViewServlet class:
    
    /**
     *  Sets the content type of the response.  This is available to be
overriden
     *  by a derived class.
     *  
     *  <p>The default implementation is :
     *  <pre>
     *
     *     response.setContentType(defaultContentType);
     * 
     *  </pre>
     *  where defaultContentType is set to the value of the
default.contentType
     *  property, or "text/html" if that is not set.</p>
     *
     *  @param request servlet request from client
     *  @param response servlet reponse to client
     */
    protected void setContentType(HttpServletRequest request, 
                                  HttpServletResponse response)
    {
        response.setContentType(defaultContentType);
    }

So I'm going to play dumb and ask where/how it might be best to do what
he needs.
I do have two ideas:

1) response object is in the context, so perhaps the *.vm can override
it directly with a #set ($foo =
$response.setContentType("text/excel-something") )

2) Create ExcelVelocityViewServlet which extends VelocityViewServlet and
override the setContentType()... then in the server config, map all
*.xvm files to that servlet.

Thoughts?
Thanks,
Timo

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


Re: [OT] Re: Using velocity decoupled from main sourcecode

Posted by Anthony Eden <ae...@signaturedomains.com>.
Since Jonathan gave you the info on Niggle I will give you the 
information on JPublish.

Like Niggle, JPublish will use the template engine's caching 
mechanisms.  However JPublish 3.x which is in the JPublish CVS right now 
adds new options for caching including action caching (for script 
actions), design template caching, static resource caching and so on.  
Additionally the caching is completely pluggable meaning that you can 
use a basic hash map for caching, or plug in an LRU cache or even have 
distributed caching.  JPublish also supports different view engines like 
Niggle, such as Velocity, FreeMarker and WebMacro.

JPublish was designed with content in mind and I think this is what 
separates it from the other frameworks out there.  Like its counterparts 
it provides a means for executing actions with a very flexible mapping 
system.  Unlike its peers, it sports Virtual File System (Commons VFS) 
for retrieving content from different sources (file system, network, 
FTP, servlet context, and so on).  The template engine integration is 
also very tight so you can do neat things like:

#parse("repository:content_repository:///includes/foo.html")

And it will pull the content from the named repository, parse it and 
include it inline.

If you would like more information on JPublish take a look at 
http://www.jpublish.org/features.html for the current feature set and 
http://www.jpublish.org/wiki/Wiki.jsp?page=JPublish3.0 for some of the 
upcoming 3.0 features.

Sincerely,
Anthony Eden

Johannes Fiala wrote:

>Hi Jonathan,
>
>Although this is getting a bit off topic here:
>
>Could you briefly line out what's the main difference between JPublish and 
>Niggle? 
>Does JPublish/Niggle have a caching mechanism more advanced than 
>Velocity's Hashtable mechanism?
>
>thx alot
>Johannes
>
>
>
>
>Jonathan Revusky <jo...@revusky.com> 
>Sent by: news <ne...@main.gmane.org>
>09.06.2003 14:52
>Please respond to
>"Velocity Users List" <ve...@jakarta.apache.org>
>
>
>To
>velocity-user@jakarta.apache.org
>cc
>
>Subject
>Re: Using velocity decoupled from main sourcecode
>
>
>
>
>
>
>Johannes Fiala wrote:
>  
>
>>Hi there,
>>
>>I'd like to use the Velocity framework, but I want to prevent my own app 
>>    
>>
>
>  
>
>>from glueing with the Velocity packages.
>>    
>>
>
>There are various web frameworks that allow programmers to use different 
>template engines using the same programmatic interface.
>
>Specifically, you might look at JPublish, at http://www.jpublish.org/ 
>which supports Velocity, FreeMarker, and Webmacro with a common View API.
>
>You could look at Niggle (disclosure, I'm the author) that supports the 
>same 3 template engines using a common API.
>
>  
>
>>I plan to set up an TemplateInterface which will decouple my own 
>>sourcecode from the real use of Velocity itself.
>>    
>>
>
>Basically, it's pretty straightforward. You create an abstract wrapper 
>around the template and context objects, that protects you from knowing 
>what the underlying template engine API is, and then instantiate and 
>process them via some kind of abstract factory pattern.
>
>
>  
>
>>Has anybody else already done that or is there an implementation 
>>suggestion (which methods should be part of such an interface) somehwere 
>>    
>>
>
>  
>
>>in the Velocity source?
>>    
>>
>
>I think you could eyeball the JPublish or Niggle sources.
>
>Regards,
>
>Jonathan Revusky
>--
>lead developer, FreeMarker project, http://freemarker.org/
>FreeMarker-Velocity comparison page: http://freemarker.org/fmVsVel.html
>
>FreeMarker 2.3pre2 is out!
>
>  
>
>>thx alot
>>Johannes
>>    
>>
>
>
>
>---------------------------------------------------------------------
>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: [OT] Re: Using velocity decoupled from main sourcecode

Posted by Jonathan Revusky <jo...@revusky.com>.
Johannes Fiala wrote:
> Hi Jonathan,
> 
> Although this is getting a bit off topic here:
> 
> Could you briefly line out what's the main difference between JPublish and 
> Niggle? 

I don't know enough about JPublish to answer the question really. I 
think they're really quite different and concentrate on different problems.

What Niggle is mostly is an object-relational framework (OREO) with some 
extra glue between that and several well-known template engines -- 
FreeMarker, Velocity, and Webmacro. Also, it provides an API that is a 
higher-level wrapper around the regular java servlet API.

Niggle is quite skeletal compared to most other web app frameworks, but 
I think it does provide a good starting point. It packages the whole 
thing together nicely and offers a lot out-of-the-box. By that, I mean, 
if instead of using Niggle, one were to use the servlet API directly, 
JDBC directly, and one of the template engines, I think most people 
would do much better with Niggle. They'd get going faster and they'd be 
working from a skeletal architecture that is more robust and 
maintianable than what they would have come up with on their own. (In 
most cases anyway.)

> Does JPublish/Niggle have a caching mechanism more advanced than 
> Velocity's Hashtable mechanism?

I assume you refer to the caching of templates, not data. Niggle does 
not cache templates. It simply delegates to whatever template engine is 
being used. It uses FreeMarker by default, and thus, by default, uses 
FreeMarker's template caching.

I hope that's somewhat helpful.

Best Regards,

Jonathan Revusky
--
lead developer, FreeMarker project, http://freemarker.org
Build robust, maintainable web applications with the Niggle Framework, 
http://niggle.org/




> 
> thx alot
> Johannes
> 
> 
> 
> 
> Jonathan Revusky <jo...@revusky.com> 
> Sent by: news <ne...@main.gmane.org>
> 09.06.2003 14:52
> Please respond to
> "Velocity Users List" <ve...@jakarta.apache.org>
> 
> 
> To
> velocity-user@jakarta.apache.org
> cc
> 
> Subject
> Re: Using velocity decoupled from main sourcecode
> 
> 
> 
> 
> 
> 
> Johannes Fiala wrote:
> 
>>Hi there,
>>
>>I'd like to use the Velocity framework, but I want to prevent my own app 
> 
> 
>>from glueing with the Velocity packages.
> 
> 
> There are various web frameworks that allow programmers to use different 
> template engines using the same programmatic interface.
> 
> Specifically, you might look at JPublish, at http://www.jpublish.org/ 
> which supports Velocity, FreeMarker, and Webmacro with a common View API.
> 
> You could look at Niggle (disclosure, I'm the author) that supports the 
> same 3 template engines using a common API.
> 
> 
>>I plan to set up an TemplateInterface which will decouple my own 
>>sourcecode from the real use of Velocity itself.
> 
> 
> Basically, it's pretty straightforward. You create an abstract wrapper 
> around the template and context objects, that protects you from knowing 
> what the underlying template engine API is, and then instantiate and 
> process them via some kind of abstract factory pattern.
> 
> 
> 
>>Has anybody else already done that or is there an implementation 
>>suggestion (which methods should be part of such an interface) somehwere 
> 
> 
>>in the Velocity source?
> 
> 
> I think you could eyeball the JPublish or Niggle sources.
> 
> Regards,
> 
> Jonathan Revusky
> --
> lead developer, FreeMarker project, http://freemarker.org/
> FreeMarker-Velocity comparison page: http://freemarker.org/fmVsVel.html
> 
> FreeMarker 2.3pre2 is out!
> 
> 
>>thx alot
>>Johannes
> 
> 
> 
> 
> ---------------------------------------------------------------------
> 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