You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2011/01/07 18:23:18 UTC

[tools] Using LinkTool for mailto: links

All,

I'm trying (for the first time!) to create a mailto: link in my webapp
and I decided to see what would happen if I used the LinkTool (really
StrutsLinkTool) to generate it. Something like this (newlines added for
readability):

<a href="$link.setURI("mailto:foo@bar.com")
     .addQueryData('subject', 'Some Subject')
     .addQueryData('body', 'Say something smart, here')">mail</a>

This resulted in the following URL:

mailto:foo@bar.com?subject=Some+Subject&body=Say+something+smart%2C+here

Normally, this would be a perfectly correct URL. Unfortunately, someone
at some point declared that spaces in mailto: link parameters should be
encoded as "%20" and not "+" [1]. :(

Ignoring the fact that mailto: links are apparently unreliable when
subjects and bodies are added, does anyone have any brilliant ideas of
how to do it?

A simple string.replaceAll(' ', '%20') won't do it, as I'd like to
convert all other characters appropriately and protect against '?' and
'&' characters being included, etc.

I suppose I could do $link.setURI(...).toString().replaceAll('+', '%20')
but that seems completely stupid.

Any ideas?

Thanks,
-chris

[1] http://www.faqs.org/faqs/www/authoring-faq/index.html S(6.10)


Re: [tools] Using LinkTool for mailto: links

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Nathan,

On 1/7/2011 12:52 PM, Nathan Bubna wrote:
> looks like 1.4 code.  have you checked on how Tools 2 encodes links?

Forgot to mention that I'm on velocity-1.4 and velocity-tools-1.4 (plus
a few of my own old patches).

I should try to upgrade to velocity-tools-2.0 since it does not
(necessarily) require an upgrade of Velocity engine (which badly needs
an upgrade, too, but will require a bunch of work on my part).

Thanks,
-chris


Re: [tools] Using LinkTool for mailto: links

Posted by Nathan Bubna <nb...@gmail.com>.
looks like 1.4 code.  have you checked on how Tools 2 encodes links?

On Fri, Jan 7, 2011 at 9:23 AM, Christopher Schultz
<ch...@christopherschultz.net> wrote:
> All,
>
> I'm trying (for the first time!) to create a mailto: link in my webapp
> and I decided to see what would happen if I used the LinkTool (really
> StrutsLinkTool) to generate it. Something like this (newlines added for
> readability):
>
> <a href="$link.setURI("mailto:foo@bar.com")
>     .addQueryData('subject', 'Some Subject')
>     .addQueryData('body', 'Say something smart, here')">mail</a>
>
> This resulted in the following URL:
>
> mailto:foo@bar.com?subject=Some+Subject&body=Say+something+smart%2C+here
>
> Normally, this would be a perfectly correct URL. Unfortunately, someone
> at some point declared that spaces in mailto: link parameters should be
> encoded as "%20" and not "+" [1]. :(
>
> Ignoring the fact that mailto: links are apparently unreliable when
> subjects and bodies are added, does anyone have any brilliant ideas of
> how to do it?
>
> A simple string.replaceAll(' ', '%20') won't do it, as I'd like to
> convert all other characters appropriately and protect against '?' and
> '&' characters being included, etc.
>
> I suppose I could do $link.setURI(...).toString().replaceAll('+', '%20')
> but that seems completely stupid.
>
> Any ideas?
>
> Thanks,
> -chris
>
> [1] http://www.faqs.org/faqs/www/authoring-faq/index.html S(6.10)
>
>

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