You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Thomas Marsh <ma...@nitesco.com> on 2004/01/02 19:16:47 UTC

How to use DVSL in a Servlet application?

Dear List:

I'm looking for an example of using DVSL in a servlet application
instead of with ant. I'm using tomcat as my servlet tier.

I've looked at the examples in the DVSL CVS directory, and in the
'Mastering Apache Velocity' book. They all seem to be for ant.

Any help is appreciated.

I think I want to have a velocity template that processes an xml
document from the context. Is this possible?

TIA

Tom 


-- 
Tom Marsh

mailto:marsht1@nitesco.com
http://www.nitesco.com

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


Re: How to use DVSL in a Servlet application?

Posted by Claude Brisson <cl...@noos.fr>.
The main purpose of DVSL is to publish XML based on a stylesheet, not to
merge a template according to a context

You should consider a two-step transformation :

XML template --[standard velocity]--> well formed XML --[DVSL]--> final
document

CloD

----- Original Message ----- 
From: "Thomas Marsh" <ma...@nitesco.com>
To: "Velocity Users List" <ve...@jakarta.apache.org>
Sent: Friday, January 02, 2004 7:16 PM
Subject: How to use DVSL in a Servlet application?


> Dear List:
>
> I'm looking for an example of using DVSL in a servlet application
> instead of with ant. I'm using tomcat as my servlet tier.
>
> I've looked at the examples in the DVSL CVS directory, and in the
> 'Mastering Apache Velocity' book. They all seem to be for ant.
>
> Any help is appreciated.
>
> I think I want to have a velocity template that processes an xml
> document from the context. Is this possible?
>
> TIA
>
> Tom
>
>
> -- 
> Tom Marsh
>
> mailto:marsht1@nitesco.com
> http://www.nitesco.com
>
> ---------------------------------------------------------------------
> 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: How to use DVSL in a Servlet application?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 2, 2004, at 4:28 PM, Thomas Marsh wrote:

> Thomas Marsh wrote:
>>
>> Dear List:
>>
>> I'm looking for an example of using DVSL in a servlet application
>> instead of with ant. I'm using tomcat as my servlet tier.
>>
>> I've looked at the examples in the DVSL CVS directory, and in the
>> 'Mastering Apache Velocity' book. They all seem to be for ant.
>>
>> Any help is appreciated.
>>
>> I think I want to have a velocity template that processes an xml
>> document from the context. Is this possible?
>
> After some more reading a browsing some javadocs, it seems maybe Anakia
> might be what I'm looking for. More reading needed....

No! :)

DVSL was what Jon was trying to do w/ Anakia.

DVSL will do what you want Anakia to do, and IMO (and in Jon's opinion) 
does it better.

geir

>
>
>>
>> TIA
>>
>> Tom
>>
>> --
>> Tom Marsh
>>
>> mailto:marsht1@nitesco.com
>> http://www.nitesco.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
> -- 
> Tom Marsh
>
> mailto:marsht1@nitesco.com
> http://www.nitesco.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: How to use DVSL in a Servlet application?

Posted by Thomas Marsh <ma...@nitesco.com>.
Thomas Marsh wrote:
> 
> Dear List:
> 
> I'm looking for an example of using DVSL in a servlet application
> instead of with ant. I'm using tomcat as my servlet tier.
> 
> I've looked at the examples in the DVSL CVS directory, and in the
> 'Mastering Apache Velocity' book. They all seem to be for ant.
> 
> Any help is appreciated.
> 
> I think I want to have a velocity template that processes an xml
> document from the context. Is this possible?

After some more reading a browsing some javadocs, it seems maybe Anakia
might be what I'm looking for. More reading needed....


> 
> TIA
> 
> Tom
> 
> --
> Tom Marsh
> 
> mailto:marsht1@nitesco.com
> http://www.nitesco.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org


-- 
Tom Marsh

mailto:marsht1@nitesco.com
http://www.nitesco.com

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


Re: How to use DVSL in a Servlet application?

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 2, 2004, at 2:33 PM, Nathan Bubna wrote:
> Geir Magnusson Jr said:
>> On Jan 2, 2004, at 1:16 PM, Thomas Marsh wrote:
> ...
>>> I've looked at the examples in the DVSL CVS directory, and in the
>>> 'Mastering Apache Velocity' book. They all seem to be for ant.
>>
>> I had no idea such a book existed.  LOL. I have no idea who the 
>> authors
>> are.  Amazing
>
> news to me too.

Well, I did put it in my references of my recent Velocity article 
<http://today.java.net/pub/a/today/2003/12/16/velocity.html?page=2>  :)

(caveat: I have not read the book either, but I did meet one of the 
co-authors at a symposium a few months ago)

I'm definitely in the camp of wishing authors on open source projects 
would be more involved in the community.  It'd help everyone out, 
methinks.

	Erik


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


Re: How to use DVSL in a Servlet application?

Posted by Nathan Bubna <na...@esha.com>.
Geir Magnusson Jr said:
> On Jan 2, 2004, at 1:16 PM, Thomas Marsh wrote:
...
> > I've looked at the examples in the DVSL CVS directory, and in the
> > 'Mastering Apache Velocity' book. They all seem to be for ant.
>
> I had no idea such a book existed.  LOL. I have no idea who the authors
> are.  Amazing

news to me too.  what's really amzing is that it's apparently about Velocity
2.0 (according to amazon's synopsis)!

http://www.amazon.co.uk/exec/obidos/ASIN/0471457949/026-4217072-0402856#product-details

somebody goofed that one.

Nathan Bubna
nathan@esha.com


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


[dvsl] Re: How to use DVSL in a Servlet application?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 2, 2004, at 6:31 PM, Geir Magnusson Jr wrote:
>
> I'll try to post an example tomorrow.

Ok - today isn't "tomorrow" :)

Here is dumb-simple code to show how to use DVSL in a servlet.  It's 
really basic, ignoring both where stylesheets and xml docs come from.  
However, given that you have sources for documents, it shouldn't be 
hard to extend this to do something useful.

if people think this is useful, I'll commit to the CVS tree as an 
example...

geir


package org.apache.tools.dvsl;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import java.io.StringReader;

/**
  *
  *  Example servlet to show how DVSL can be used in a servlet to
  *  render output
  *
  * @author <a href="mailto:geirm@apache.prg">Geir Magnusson Jr.</a>
  * @version $Id: $
  */
public class DVSLServlet extends HttpServlet
{
     public void service(HttpServletRequest req, HttpServletResponse res)
         throws ServletException, java.io.IOException
     {

         String doc = "<?xml version=\"1.0\"?>"
                     + "<document>"
                     + "<section name=\"foo\">"
                     + "<p> Hello from section foo</p>"
                     + "</section>"
                     + "<section name=\"bar\">"
                     + "<p> Hello from section bar</p>"
                     + "</section>"
                     + "</document>";

         String style = "#match(\"document\")"
                     + 
"<html><body>$context.applyTemplates()</body></html>"
                     + "#end"
                     + "#match(\"section\")"
                     + "<hr><b>Section:</b> $attrib.name 
$context.applyTemplates(\"p\")"
                     + "#end"
                     + "#match(\"p\")"
                     + "<blockquote> $node.copy($node.children()) 
</blockquote>"
                     + "#end";

         DVSL dvsl = new DVSL();

         try
         {
             dvsl.setStylesheet(new StringReader(style));

             dvsl.transform(new StringReader(doc), res.getWriter());
         }
         catch(Exception e)
         {
             log("error",e);
         }
     }
}


-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: How to use DVSL in a Servlet application?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 2, 2004, at 6:05 PM, Geir Magnusson Jr wrote:

>
> On Jan 2, 2004, at 3:25 PM, Thomas Marsh wrote:
>
>>>>> Any help is appreciated.
>>>>>
>>>>> I think I want to have a velocity template that processes an xml
>>>>> document from the context. Is this possible?
>>>>
>>>> What do you want to do?  You have XML and want to produce some  
>>>> output?
>>>
>>> Yes, I have XML returned from a database, and I can put it in my
>>> velocity context in my servlet. I'd like to then process it into  
>>> HTML. I
>>> thought I might be able to use DVSL.
>>
>> Is this something I can use DVSL to do?
>
> Yes, but you don't need to do this from a template.
>
> You can just render the HTML out from the XML w/o having a velocity  
> template.  You'll need a DVSL stylesheet, of course, so I guess you  
> could say it's like having a template, but it's really not the same  
> thing.

I'll try to post an example tomorrow.

>
> geir
>
>>
>>>
>>>>
>>>>>
>>>>> TIA
>>>>>
>>>>> Tom
>>>>>
>>>>>
>>>>> --
>>>>> Tom Marsh
>>>>>
>>>>> mailto:marsht1@nitesco.com
>>>>> http://www.nitesco.com
>>>>>
>>>>> ------------------------------------------------------------------- 
>>>>> --
>>>>> To unsubscribe, e-mail:  
>>>>> velocity-user-unsubscribe@jakarta.apache.org
>>>>> For additional commands, e-mail:  
>>>>> velocity-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>> --
>>>> Geir Magnusson Jr                                   203-247-1713(m)
>>>> geir@4quarters.com
>>>>
>>>> -------------------------------------------------------------------- 
>>>> -
>>>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:  
>>>> velocity-user-help@jakarta.apache.org
>>>
>>> --
>>> Tom Marsh
>>>
>>> mailto:marsht1@nitesco.com
>>> http://www.nitesco.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:  
>>> velocity-user-help@jakarta.apache.org
>>
>>
>> -- 
>> Tom Marsh
>>
>> mailto:marsht1@nitesco.com
>> http://www.nitesco.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>>
>>
> -- 
> Geir Magnusson Jr                                   203-247-1713(m)
> geir@4quarters.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: How to use DVSL in a Servlet application?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 2, 2004, at 3:25 PM, Thomas Marsh wrote:

>>>> Any help is appreciated.
>>>>
>>>> I think I want to have a velocity template that processes an xml
>>>> document from the context. Is this possible?
>>>
>>> What do you want to do?  You have XML and want to produce some  
>>> output?
>>
>> Yes, I have XML returned from a database, and I can put it in my
>> velocity context in my servlet. I'd like to then process it into  
>> HTML. I
>> thought I might be able to use DVSL.
>
> Is this something I can use DVSL to do?

Yes, but you don't need to do this from a template.

You can just render the HTML out from the XML w/o having a velocity  
template.  You'll need a DVSL stylesheet, of course, so I guess you  
could say it's like having a template, but it's really not the same  
thing.

geir

>
>>
>>>
>>>>
>>>> TIA
>>>>
>>>> Tom
>>>>
>>>>
>>>> --
>>>> Tom Marsh
>>>>
>>>> mailto:marsht1@nitesco.com
>>>> http://www.nitesco.com
>>>>
>>>> -------------------------------------------------------------------- 
>>>> -
>>>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:  
>>>> velocity-user-help@jakarta.apache.org
>>>>
>>>>
>>> --
>>> Geir Magnusson Jr                                   203-247-1713(m)
>>> geir@4quarters.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:  
>>> velocity-user-help@jakarta.apache.org
>>
>> --
>> Tom Marsh
>>
>> mailto:marsht1@nitesco.com
>> http://www.nitesco.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
> -- 
> Tom Marsh
>
> mailto:marsht1@nitesco.com
> http://www.nitesco.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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


Re: How to use DVSL in a Servlet application?

Posted by Thomas Marsh <ma...@nitesco.com>.
Thomas Marsh wrote:
> 
> Geir Magnusson Jr wrote:
> >
> > On Jan 2, 2004, at 1:16 PM, Thomas Marsh wrote:
> >
> > > Dear List:
> > >
> > > I'm looking for an example of using DVSL in a servlet application
> > > instead of with ant. I'm using tomcat as my servlet tier.
> > >
> > > I've looked at the examples in the DVSL CVS directory, and in the
> > > 'Mastering Apache Velocity' book. They all seem to be for ant.
> >
> > I had no idea such a book existed.  LOL. I have no idea who the authors
> > are.  Amazing
> 
> Published by Wiley
> ISBN 0-471-45794-9
> Authors Joseph D. Gradecki & Jim Cole
> 
> >
> > >
> > > Any help is appreciated.
> > >
> > > I think I want to have a velocity template that processes an xml
> > > document from the context. Is this possible?
> >
> > What do you want to do?  You have XML and want to produce some output?
> 
> Yes, I have XML returned from a database, and I can put it in my
> velocity context in my servlet. I'd like to then process it into HTML. I
> thought I might be able to use DVSL.

Is this something I can use DVSL to do?

> 
> >
> > >
> > > TIA
> > >
> > > Tom
> > >
> > >
> > > --
> > > Tom Marsh
> > >
> > > mailto:marsht1@nitesco.com
> > > http://www.nitesco.com
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> > >
> > >
> > --
> > Geir Magnusson Jr                                   203-247-1713(m)
> > geir@4quarters.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> --
> Tom Marsh
> 
> mailto:marsht1@nitesco.com
> http://www.nitesco.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org


-- 
Tom Marsh

mailto:marsht1@nitesco.com
http://www.nitesco.com

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


Re: How to use DVSL in a Servlet application?

Posted by Thomas Marsh <ma...@nitesco.com>.
Geir Magnusson Jr wrote:
> 
> On Jan 2, 2004, at 1:16 PM, Thomas Marsh wrote:
> 
> > Dear List:
> >
> > I'm looking for an example of using DVSL in a servlet application
> > instead of with ant. I'm using tomcat as my servlet tier.
> >
> > I've looked at the examples in the DVSL CVS directory, and in the
> > 'Mastering Apache Velocity' book. They all seem to be for ant.
> 
> I had no idea such a book existed.  LOL. I have no idea who the authors
> are.  Amazing

Published by Wiley
ISBN 0-471-45794-9
Authors Joseph D. Gradecki & Jim Cole

> 
> >
> > Any help is appreciated.
> >
> > I think I want to have a velocity template that processes an xml
> > document from the context. Is this possible?
> 
> What do you want to do?  You have XML and want to produce some output?

Yes, I have XML returned from a database, and I can put it in my
velocity context in my servlet. I'd like to then process it into HTML. I
thought I might be able to use DVSL.

> 
> >
> > TIA
> >
> > Tom
> >
> >
> > --
> > Tom Marsh
> >
> > mailto:marsht1@nitesco.com
> > http://www.nitesco.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> >
> >
> --
> Geir Magnusson Jr                                   203-247-1713(m)
> geir@4quarters.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org


-- 
Tom Marsh

mailto:marsht1@nitesco.com
http://www.nitesco.com

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


Re: How to use DVSL in a Servlet application?

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Jan 2, 2004, at 1:16 PM, Thomas Marsh wrote:

> Dear List:
>
> I'm looking for an example of using DVSL in a servlet application
> instead of with ant. I'm using tomcat as my servlet tier.
>
> I've looked at the examples in the DVSL CVS directory, and in the
> 'Mastering Apache Velocity' book. They all seem to be for ant.

I had no idea such a book existed.  LOL. I have no idea who the authors 
are.  Amazing

>
> Any help is appreciated.
>
> I think I want to have a velocity template that processes an xml
> document from the context. Is this possible?

What do you want to do?  You have XML and want to produce some output?

>
> TIA
>
> Tom
>
>
> -- 
> Tom Marsh
>
> mailto:marsht1@nitesco.com
> http://www.nitesco.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


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