You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Chris Hitzke <ch...@adobe.com> on 2004/03/04 22:38:52 UTC

JDOM and Velocity to transform from XML to HTML using Velocity Template

I am using Anakia along with JDOM and Velocity to transform my XML document 
into
HTML file. Below, is the code I wrote to make the transformation happen. 
But, it's not utilizing
the AnakiaTask class. How do I utilize the AnikiaTask class to convert XML 
to HTML using Velocity
template? I see how the it's done in the build.xml file (Anikia example). 
But, how do you do it
programatically? Please, respond. Thanks....


assumption:
==========

xml file
===========
xml tags and info

.vm file
======
contains velocity code and html tags

html file
======
result of transforming xml file to .vm file

code for conversion
===================

Writer writer = null;

try
{
/*
  *  and now call init
  */

Velocity.init();


/*
  * build a Document from our xml
  */

SAXBuilder builder;
Document root = null;

try
{
builder = new SAXBuilder(  "org.apache.xerces.parsers.SAXParser" );
root = builder.build(resultsFileName);
}
catch( Exception ee)
{
System.out.println("Exception building Document : " + ee);
return;
}

/*
  * now, make a Context object and populate it.
  */

VelocityContext context = new VelocityContext();
context.put("root", root);

/*
  *  make a writer, and merge the template 'against' the context
  */

Template template = Velocity.getTemplate(velocityTemplateFileName);

writer = new BufferedWriter(new OutputStreamWriter(System.out));
template.merge( context , writer);
}
catch( Exception e )
{
    System.out.println("Exception : " + e);
}
finally
{
if ( writer != null)
{
try
{
writer.flush();
writer.close();
}
catch( Exception ee )
{
System.out.println("Exception : " + ee );
}
}
}


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


Re: transform from XML - DVSL

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Mar 9, 2004, at 5:01 PM, Colin Chalmers wrote:

> Hi all,
>
> Is anyone actually using DVSL for presentaion layer instead of say 
> XSLT? Any performance issues to be concerned about?

I use it all the time.  That said, it's not for on-line rendering, but 
static rendering.

There is supposedly a memory leak in DVSL - or there was so claimed a 
number of years ago when maven was generating large outputs with it - 
but there never was a fixable example.  DVSL was involved during the 
execution when the OOM happened, but other things were as well.

> We just implemented a solution based on XSLT and I have to say 
> performace sucks!! Wasn't my choice of solution!

I'd be interested to see a timing comparison.

geir

>
> /c
>
> Geir Magnusson Jr wrote:
>
>>
>> On Mar 4, 2004, at 8:28 PM, Tim Colson wrote:
>>
>>> Geir said
>>>
>>>> You would be much better served by using DVSL.
>>>
>>> DVSL is good mojo. I dig it. :-)
>>>
>>> But hey, when is DVSL going to make it out dev-limbo and into the 
>>> core
>>> (or somewhere).
>>
>>
>> I'd like to do a release soon.  No reason not to.  Won't get into vel 
>> core as it's something that uses velocity, not is velocity.
>>
>>>
>>> And what's the big diff between Anakia and DVSL?
>>>
>>> Anakia
>>> ------
>>> WHAT IS IT GOOD FOR: XML transformed to anything?
>>> PRO:Cool name
>>> PRO/CON:Older so maybe more mature, but also cruftier?
>>>
>>
>> Anakia is a fully procedural style rendering system where you have to 
>> know the full document format ahead of time.  It was an early part of 
>> velocity, created originally by Jon Stevens, and is used throughout 
>> the ASF.
>>
>> It my opinion (and Jon's back when I cooked up DVSL), it should be 
>> retired in favor of DVSL.
>>
>>
>>> DVSL
>>> -------
>>> WHAT IS IT GOOD FOR: XML transformed to anything
>>> PRO:Funky acronym name - not as cool
>>> PRO:way cooler than XSL
>>> CON:in "DEV" which means "stay away" for many folks.
>>
>>
>> DVSL is a 'declarative' rendering system like XSL.  It differs from 
>> XSL in that
>>
>> a) you can break out into nice procedural code (the Velocity) at any 
>> time for your output render
>> b) you can stuff the context with objects to access data from other 
>> sources
>>
>> An improvement to DVSL would be to, for pure XML work, generate SAX 
>> events (and ilk) to play better in layered transformation pipelines.  
>> Maybe once we get 1.0 out the door it will get more attention and 
>> someone will scratch that itch.  So far, it hasn't been an itch for 
>> me.
>>
>> geir
>>
>
>
>
> ---------------------------------------------------------------------
> 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-247-1713(m)
geir@4quarters.com


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


Re: transform from XML - DVSL

Posted by Colin Chalmers <Co...@xs4all.nl>.
Why don't you see a quick win?  Don't the want their system to be fast?

LOL, the quick win would of course be better performance but the whole 
thing still has tie in with the legacy framework which only seems to 
support JSP's, and of course the old JSP files themselves. Still that 
shouldn't disourage me from trying to steer it towards Velocity I guess.

For the sake of completeness I'd like to share these figures with you 
which I've extracted from Rod Johnsons book "J2EE Design & Development"
The figures are based on the following and shown as hits per second 
running 100 concurrent clients continually requesting pages

                                  hits per second
1. JSP using jstl   =   54
2. Velocity 1.3    =    112
3. XMLC            =   128
4. XSLT using Xalan   =   7

Rod admits that these figures are only indicative but that the 
differences themselves are astounding!!! The latter ie 7 is what I'm 
experiencing now :-((

/c

>
>>
>> Thx for listening
>>
>> /c
>>
>> Serge Knystautas wrote:
>>
>>> Colin Chalmers wrote:
>>>
>>>> Is anyone actually using DVSL for presentaion layer instead of say 
>>>> XSLT? Any performance issues to be concerned about?
>>>> We just implemented a solution based on XSLT and I have to say 
>>>> performace sucks!! Wasn't my choice of solution!
>>>
>>>
>>>
>>> We use DVSL as part of Ant tasks to convert a bunch of XML reports 
>>> from various tools into consistent HTML.  I was very, very pleased 
>>> with how much easier it was to transform XML than XHTML was, while 
>>> using the same metaphor (?? approach, structure, mindset?) to 
>>> document transformation.
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>>
>>



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


Re: transform from XML - DVSL

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Mar 10, 2004, at 1:46 PM, Colin Chalmers wrote:

> Thx for the feedback guys. Unfortunately I was looking at DVSL helping 
> me with an front-end XSLT problem. I know it's a bit off topic but 
> I'll share the problem with you.
>
> We're migrating a JSP app built against a commercial framework to a 
> colleague of mines' idea of a portal architecture based on same 
> framework, hey he works for them!  I see it as squeezing last drops of 
> blood out a stone. Anyway he claims to have considered templating 
> engines but chose XSLT for his solution. What he's trying to do is 
> send Objects from framework to JSP->render these Objects into XMLin 
> JSP->transform XML/XSL to HTML.

And this was thought to be better than just using the objects in a 
templating system?

> Performance sucks and corresponds with results I saw from Rod Johnson 
> author of Spring Framework ie 8 hits per second!! BTW he showed 
> results of Velocity outperforming JSP and XSLT big style!! 
> Unfortunately I don't see a quick win except trying to convince him 
> that a Velocity solution would/is a better choice :-)

Why don't you see a quick win?  Don't the want their system to be fast?

>
> Thx for listening
>
> /c
>
> Serge Knystautas wrote:
>
>> Colin Chalmers wrote:
>>
>>> Is anyone actually using DVSL for presentaion layer instead of say 
>>> XSLT? Any performance issues to be concerned about?
>>> We just implemented a solution based on XSLT and I have to say 
>>> performace sucks!! Wasn't my choice of solution!
>>
>>
>> We use DVSL as part of Ant tasks to convert a bunch of XML reports 
>> from various tools into consistent HTML.  I was very, very pleased 
>> with how much easier it was to transform XML than XHTML was, while 
>> using the same metaphor (?? approach, structure, mindset?) to 
>> document transformation.
>>
>
>
>
> ---------------------------------------------------------------------
> 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-247-1713(m)
geir@4quarters.com


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


Re: transform from XML - DVSL

Posted by Colin Chalmers <Co...@xs4all.nl>.
Thx for the feedback guys. Unfortunately I was looking at DVSL helping 
me with an front-end XSLT problem. I know it's a bit off topic but I'll 
share the problem with you.

We're migrating a JSP app built against a commercial framework to a 
colleague of mines' idea of a portal architecture based on same 
framework, hey he works for them!  I see it as squeezing last drops of 
blood out a stone. Anyway he claims to have considered templating 
engines but chose XSLT for his solution. What he's trying to do is send 
Objects from framework to JSP->render these Objects into XMLin 
JSP->transform XML/XSL to HTML. Performance sucks and corresponds with 
results I saw from Rod Johnson author of Spring Framework ie 8 hits per 
second!! BTW he showed results of Velocity outperforming JSP and XSLT 
big style!! Unfortunately I don't see a quick win except trying to 
convince him that a Velocity solution would/is a better choice :-)

Thx for listening

/c

Serge Knystautas wrote:

> Colin Chalmers wrote:
>
>> Is anyone actually using DVSL for presentaion layer instead of say 
>> XSLT? Any performance issues to be concerned about?
>> We just implemented a solution based on XSLT and I have to say 
>> performace sucks!! Wasn't my choice of solution!
>
>
> We use DVSL as part of Ant tasks to convert a bunch of XML reports 
> from various tools into consistent HTML.  I was very, very pleased 
> with how much easier it was to transform XML than XHTML was, while 
> using the same metaphor (?? approach, structure, mindset?) to document 
> transformation.
>



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


Re: transform from XML - DVSL

Posted by Serge Knystautas <se...@lokitech.com>.
Colin Chalmers wrote:
> Is anyone actually using DVSL for presentaion layer instead of say XSLT? 
> Any performance issues to be concerned about?
> We just implemented a solution based on XSLT and I have to say 
> performace sucks!! Wasn't my choice of solution!

We use DVSL as part of Ant tasks to convert a bunch of XML reports from 
various tools into consistent HTML.  I was very, very pleased with how 
much easier it was to transform XML than XHTML was, while using the same 
metaphor (?? approach, structure, mindset?) to document transformation.

-- 
Serge Knystautas
President
Lokitech >> software . strategy . design >> http://www.lokitech.com
p. 301.656.5501
e. sergek@lokitech.com

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


Re: transform from XML - DVSL

Posted by Colin Chalmers <Co...@xs4all.nl>.
Hi all,

Is anyone actually using DVSL for presentaion layer instead of say XSLT? 
Any performance issues to be concerned about?
We just implemented a solution based on XSLT and I have to say 
performace sucks!! Wasn't my choice of solution!

/c

Geir Magnusson Jr wrote:

>
> On Mar 4, 2004, at 8:28 PM, Tim Colson wrote:
>
>> Geir said
>>
>>> You would be much better served by using DVSL.
>>
>> DVSL is good mojo. I dig it. :-)
>>
>> But hey, when is DVSL going to make it out dev-limbo and into the core
>> (or somewhere).
>
>
> I'd like to do a release soon.  No reason not to.  Won't get into vel 
> core as it's something that uses velocity, not is velocity.
>
>>
>> And what's the big diff between Anakia and DVSL?
>>
>> Anakia
>> ------
>> WHAT IS IT GOOD FOR: XML transformed to anything?
>> PRO:Cool name
>> PRO/CON:Older so maybe more mature, but also cruftier?
>>
>
> Anakia is a fully procedural style rendering system where you have to 
> know the full document format ahead of time.  It was an early part of 
> velocity, created originally by Jon Stevens, and is used throughout 
> the ASF.
>
> It my opinion (and Jon's back when I cooked up DVSL), it should be 
> retired in favor of DVSL.
>
>
>> DVSL
>> -------
>> WHAT IS IT GOOD FOR: XML transformed to anything
>> PRO:Funky acronym name - not as cool
>> PRO:way cooler than XSL
>> CON:in "DEV" which means "stay away" for many folks.
>
>
> DVSL is a 'declarative' rendering system like XSL.  It differs from 
> XSL in that
>
> a) you can break out into nice procedural code (the Velocity) at any 
> time for your output render
> b) you can stuff the context with objects to access data from other 
> sources
>
> An improvement to DVSL would be to, for pure XML work, generate SAX 
> events (and ilk) to play better in layered transformation pipelines.  
> Maybe once we get 1.0 out the door it will get more attention and 
> someone will scratch that itch.  So far, it hasn't been an itch for me.
>
> geir
>



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


Re: transform from XML - DVSL

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Mar 4, 2004, at 8:28 PM, Tim Colson wrote:

> Geir said
>> You would be much better served by using DVSL.
> DVSL is good mojo. I dig it. :-)
>
> But hey, when is DVSL going to make it out dev-limbo and into the core
> (or somewhere).

I'd like to do a release soon.  No reason not to.  Won't get into vel 
core as it's something that uses velocity, not is velocity.

>
> And what's the big diff between Anakia and DVSL?
>
> Anakia
> ------
> WHAT IS IT GOOD FOR: XML transformed to anything?
> PRO:Cool name
> PRO/CON:Older so maybe more mature, but also cruftier?
>

Anakia is a fully procedural style rendering system where you have to 
know the full document format ahead of time.  It was an early part of 
velocity, created originally by Jon Stevens, and is used throughout the 
ASF.

It my opinion (and Jon's back when I cooked up DVSL), it should be 
retired in favor of DVSL.


> DVSL
> -------
> WHAT IS IT GOOD FOR: XML transformed to anything
> PRO:Funky acronym name - not as cool
> PRO:way cooler than XSL
> CON:in "DEV" which means "stay away" for many folks.

DVSL is a 'declarative' rendering system like XSL.  It differs from XSL 
in that

a) you can break out into nice procedural code (the Velocity) at any 
time for your output render
b) you can stuff the context with objects to access data from other 
sources

An improvement to DVSL would be to, for pure XML work, generate SAX 
events (and ilk) to play better in layered transformation pipelines.  
Maybe once we get 1.0 out the door it will get more attention and 
someone will scratch that itch.  So far, it hasn't been an itch for me.

geir

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


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


RE: transform from XML - DVSL

Posted by Tim Colson <tc...@cisco.com>.
Geir said
> You would be much better served by using DVSL.
DVSL is good mojo. I dig it. :-)

But hey, when is DVSL going to make it out dev-limbo and into the core
(or somewhere).

And what's the big diff between Anakia and DVSL?

Anakia
------
WHAT IS IT GOOD FOR: XML transformed to anything?
PRO:Cool name
PRO/CON:Older so maybe more mature, but also cruftier?

DVSL
-------
WHAT IS IT GOOD FOR: XML transformed to anything
PRO:Funky acronym name - not as cool
PRO:way cooler than XSL
CON:in "DEV" which means "stay away" for many folks.


-Timo



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


Re: JDOM and Velocity to transform from XML to HTML using Velocity Template

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
You would be much better served by using DVSL.

geir

On Mar 4, 2004, at 4:38 PM, Chris Hitzke wrote:

>
> I am using Anakia along with JDOM and Velocity to transform my XML 
> document into
> HTML file. Below, is the code I wrote to make the transformation 
> happen. But, it's not utilizing
> the AnakiaTask class. How do I utilize the AnikiaTask class to convert 
> XML to HTML using Velocity
> template? I see how the it's done in the build.xml file (Anikia 
> example). But, how do you do it
> programatically? Please, respond. Thanks....
>
>
> assumption:
> ==========
>
> xml file
> ===========
> xml tags and info
>
> .vm file
> ======
> contains velocity code and html tags
>
> html file
> ======
> result of transforming xml file to .vm file
>
> code for conversion
> ===================
>
> Writer writer = null;
>
> try
> {
> /*
>  *  and now call init
>  */
>
> Velocity.init();
>
>
> /*
>  * build a Document from our xml
>  */
>
> SAXBuilder builder;
> Document root = null;
>
> try
> {
> builder = new SAXBuilder(  "org.apache.xerces.parsers.SAXParser" );
> root = builder.build(resultsFileName);
> }
> catch( Exception ee)
> {
> System.out.println("Exception building Document : " + ee);
> return;
> }
>
> /*
>  * now, make a Context object and populate it.
>  */
>
> VelocityContext context = new VelocityContext();
> context.put("root", root);
>
> /*
>  *  make a writer, and merge the template 'against' the context
>  */
>
> Template template = Velocity.getTemplate(velocityTemplateFileName);
>
> writer = new BufferedWriter(new OutputStreamWriter(System.out));
> template.merge( context , writer);
> }
> catch( Exception e )
> {
>    System.out.println("Exception : " + e);
> }
> finally
> {
> if ( writer != null)
> {
> try
> {
> writer.flush();
> writer.close();
> }
> catch( Exception ee )
> {
> System.out.println("Exception : " + ee );
> }
> }
> }
>
>
> ---------------------------------------------------------------------
> 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-247-1713(m)
geir@4quarters.com


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