You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christoph Reck <Ch...@dlr.de> on 2001/12/13 14:20:15 UTC

Re: globalMacros - encodeToHTML

Hi,

I copying this to the Velocity user list since it might interest
others...

KL Tse wrote:
> 
> Dear Christoph,
> I found your globalMacros.vm in the mail achive and very interested to use
> it in our Turbine application. However both Turbine and Volicity are new to
> me. I copy the following section of your globalMacros.vm to the one supplied
> with Turbine, the output only produce a $l_line. This is done after I have
> restart the whole system. Other Macros of the vm file are working fine.
> Please let me know if there are something needed to be done to make the
> macros working or I have missed something.
> Thanks in advance for your help.
> Best regards
> KL Tse
> 
> ## ------------------------------------------------------------------------
> ## Encodes a text string into HTML
> ## ------------------------------------------------------------------------
> #macro( encodeToHTML $text )
> #set( $l_line = $Regexp.substitute('s/&/&amp;/g', $text) )
> #set( $l_line = $Regexp.substitute('s/</&lt;/g', $l_line) )
> #set( $l_line = $Regexp.substitute('s/  /&nbsp;&nbsp;/g', $l_line) )
> #set( $l_line = $Regexp.substitute('s/%0A/<br>/g', $l_line) )
> $l_line##
> #end

The above encodeToHTML macro serves as a *very* useful way of
getting plain text nicely formatted and wrapped within HTML.
Using a <pre> tag will not wrap lines. Putting an above formatted
string within a <code>-tagpair will do things nicer. This trick
sould find its way into the jakarta-site2 transformation to allow
pretty printing w/o requiring an extra set of printer-friendly docs...

You need an instance of the org.apache.oro.text.perl.Perl5Util in the
context. This is from the oro.jar package from the jakarta site (was
part of Velocity jar in version 1.1 and earlyer).

I create an instance per request since I read somewhere that the 
regexp is not multithreaded.

I remember that I read somewhere that in the Turbine Pull-Model 
configuration you can specify which instances you want in your 
context.

I used this in a TemplateSerlvet - see source at:
  http://www.eoweb.de:8888/eoweb/templates/TemplateSerlvet.java
with a initial setup template
  http://www.eoweb.de:8888/eoweb/templates/init.vm
with a per-request initialization template
  http://www.eoweb.de:8888/eoweb/templates/request.vm

For simple XML escaping, Turbine has tools available. In the
jakarta org.apache.commons.util package you will also find 
many goodies like the XMLUtil that could help you here if your 
requirement is just XML-escaping.

:) Christoph

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: globalMacros - encodeToHTML

Posted by KL Tse <kl...@yahoo.com>.
Dear Christoph,
I cannot access the links. I have been looking around for an example but in
vain. It will be extremely helpful if you can cut the relevant sections of
your code and show a brief example of how to use it.
Best regards,
KL Tsee
----- Original Message -----
From: "Christoph Reck" <Ch...@dlr.de>
To: "KL Tse" <kl...@yahoo.com>; <ve...@jakarta.apache.org>
Sent: Thursday, December 13, 2001 9:20 PM
Subject: Re: globalMacros - encodeToHTML


> Hi,
>
> I copying this to the Velocity user list since it might interest
> others...
>
> KL Tse wrote:
> >
> > Dear Christoph,
> > I found your globalMacros.vm in the mail achive and very interested to
use
> > it in our Turbine application. However both Turbine and Volicity are new
to
> > me. I copy the following section of your globalMacros.vm to the one
supplied
> > with Turbine, the output only produce a $l_line. This is done after I
have
> > restart the whole system. Other Macros of the vm file are working fine.
> > Please let me know if there are something needed to be done to make the
> > macros working or I have missed something.
> > Thanks in advance for your help.
> > Best regards
> > KL Tse
> >
> >
## ------------------------------------------------------------------------
> > ## Encodes a text string into HTML
> >
## ------------------------------------------------------------------------
> > #macro( encodeToHTML $text )
> > #set( $l_line = $Regexp.substitute('s/&/&amp;/g', $text) )
> > #set( $l_line = $Regexp.substitute('s/</&lt;/g', $l_line) )
> > #set( $l_line = $Regexp.substitute('s/  /&nbsp;&nbsp;/g', $l_line) )
> > #set( $l_line = $Regexp.substitute('s/%0A/<br>/g', $l_line) )
> > $l_line##
> > #end
>
> The above encodeToHTML macro serves as a *very* useful way of
> getting plain text nicely formatted and wrapped within HTML.
> Using a <pre> tag will not wrap lines. Putting an above formatted
> string within a <code>-tagpair will do things nicer. This trick
> sould find its way into the jakarta-site2 transformation to allow
> pretty printing w/o requiring an extra set of printer-friendly docs...
>
> You need an instance of the org.apache.oro.text.perl.Perl5Util in the
> context. This is from the oro.jar package from the jakarta site (was
> part of Velocity jar in version 1.1 and earlyer).
>
> I create an instance per request since I read somewhere that the
> regexp is not multithreaded.
>
> I remember that I read somewhere that in the Turbine Pull-Model
> configuration you can specify which instances you want in your
> context.
>
> I used this in a TemplateSerlvet - see source at:
>   http://www.eoweb.de:8888/eoweb/templates/TemplateSerlvet.java
> with a initial setup template
>   http://www.eoweb.de:8888/eoweb/templates/init.vm
> with a per-request initialization template
>   http://www.eoweb.de:8888/eoweb/templates/request.vm
>
> For simple XML escaping, Turbine has tools available. In the
> jakarta org.apache.commons.util package you will also find
> many goodies like the XMLUtil that could help you here if your
> requirement is just XML-escaping.
>
> :) Christoph


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: globalMacros - encodeToHTML

Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 12/20/01 7:31 AM, "Christoph Reck" <Ch...@dlr.de> wrote:

> psaunder wrote:
>> 
>> Hi Christopher,
>> In the same theme as your work on globalMacros.vm, do you know if there
>> is a convenience package of velocity macros, or do people tend to
>> roll their own.
>> The reason I ask is that I have been hacking a bit of PHP (at work, no
>> choice but PHP)
>> and it has a whole heap of inbuilt functions for generating html.
>> 
>> This is really a question to all others on list too.
>> 
>> Thanks,
> 
> Currently everyone is rolling their own...
> 
> Geir just mentioned in another thread that soon there will be
> a place for tool contributions:
> 


Yes -  sorry - client stuff came up - will sketch out what we can bring
together so far later today for comment before we get started...


> "Geir Magnusson Jr." wrote in thread "VelocityVaue Patch":
>>> What about having a repository for Velocity tools?
>>> Does that make sense?
>>> 
>>> 
>> 
>> That's coming :)
>> 
>> Real soon!
>> 
>> Getting the code checked into the dvsl repository first.
>> 
>> :)
> 
> 
> :) Christoph
> 
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 

-- 
Geir Magnusson Jr.     geirm@optonline.net
System and Software Consulting
"Whoever would overthrow the liberty of a nation must begin by subduing the
freeness of speech." - Benjamin Franklin



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: globalMacros - encodeToHTML

Posted by Christoph Reck <Ch...@dlr.de>.
psaunder wrote:
> 
> Hi Christopher,
> In the same theme as your work on globalMacros.vm, do you know if there
> is a convenience package of velocity macros, or do people tend to
> roll their own.
> The reason I ask is that I have been hacking a bit of PHP (at work, no
> choice but PHP)
> and it has a whole heap of inbuilt functions for generating html.
> 
> This is really a question to all others on list too.
> 
> Thanks,

Currently everyone is rolling their own...

Geir just mentioned in another thread that soon there will be
a place for tool contributions:

"Geir Magnusson Jr." wrote in thread "VelocityVaue Patch":
> > What about having a repository for Velocity tools?
> > Does that make sense?
> >
> >
> 
> That's coming :)
> 
> Real soon!
> 
> Getting the code checked into the dvsl repository first.
> 
> :)


:) Christoph

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: globalMacros - encodeToHTML

Posted by psaunder <ps...@comcen.com.au>.
Hi Christopher,
In the same theme as your work on globalMacros.vm, do you know if there
is a convenience package of velocity macros, or do people tend to
roll their own.
The reason I ask is that I have been hacking a bit of PHP (at work, no
choice but PHP)
and it has a whole heap of inbuilt functions for generating html.

This is really a question to all others on list too.

Thanks,

Pat.
----- Original Message -----
From: Christoph Reck <Ch...@dlr.de>
To: KL Tse <kl...@yahoo.com>; <ve...@jakarta.apache.org>
Sent: Friday, December 14, 2001 12:20 AM
Subject: Re: globalMacros - encodeToHTML


> Hi,
>
> I copying this to the Velocity user list since it might interest
> others...
>
> KL Tse wrote:
> >
> > Dear Christoph,
> > I found your globalMacros.vm in the mail achive and very interested to
use
> > it in our Turbine application. However both Turbine and Volicity are new
to
> > me. I copy the following section of your globalMacros.vm to the one
supplied
> > with Turbine, the output only produce a $l_line. This is done after I
have
> > restart the whole system. Other Macros of the vm file are working fine.
> > Please let me know if there are something needed to be done to make the
> > macros working or I have missed something.
> > Thanks in advance for your help.
> > Best regards
> > KL Tse
> >
> >
## ------------------------------------------------------------------------
> > ## Encodes a text string into HTML
> >
## ------------------------------------------------------------------------
> > #macro( encodeToHTML $text )
> > #set( $l_line = $Regexp.substitute('s/&/&amp;/g', $text) )
> > #set( $l_line = $Regexp.substitute('s/</&lt;/g', $l_line) )
> > #set( $l_line = $Regexp.substitute('s/  /&nbsp;&nbsp;/g', $l_line) )
> > #set( $l_line = $Regexp.substitute('s/%0A/<br>/g', $l_line) )
> > $l_line##
> > #end
>
> The above encodeToHTML macro serves as a *very* useful way of
> getting plain text nicely formatted and wrapped within HTML.
> Using a <pre> tag will not wrap lines. Putting an above formatted
> string within a <code>-tagpair will do things nicer. This trick
> sould find its way into the jakarta-site2 transformation to allow
> pretty printing w/o requiring an extra set of printer-friendly docs...
>
> You need an instance of the org.apache.oro.text.perl.Perl5Util in the
> context. This is from the oro.jar package from the jakarta site (was
> part of Velocity jar in version 1.1 and earlyer).
>
> I create an instance per request since I read somewhere that the
> regexp is not multithreaded.
>
> I remember that I read somewhere that in the Turbine Pull-Model
> configuration you can specify which instances you want in your
> context.
>
> I used this in a TemplateSerlvet - see source at:
>   http://www.eoweb.de:8888/eoweb/templates/TemplateSerlvet.java
> with a initial setup template
>   http://www.eoweb.de:8888/eoweb/templates/init.vm
> with a per-request initialization template
>   http://www.eoweb.de:8888/eoweb/templates/request.vm
>
> For simple XML escaping, Turbine has tools available. In the
> jakarta org.apache.commons.util package you will also find
> many goodies like the XMLUtil that could help you here if your
> requirement is just XML-escaping.
>
> :) Christoph
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>