Convert String to URL in vm file.

hemanth acharya July 14, 2014

Hi All,

I want to convert a plain String to a URL(clickable link) in a vm file. I have tried using $link.encode(String) but it takes as a literal. That is , it just prints "$link.encode(String)", doesnt encode. I am not sure what do I have to enable and where in jira. Please suggest. We are using jira 6.0.8 currently which will be upgraded shortly to the latest version.

Thanks,

Hemanth

1 answer

0 votes
Elisa [Atlassian]
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 15, 2014

Hi! :)

Have you tried this one:

ib.name

Escapes the characters in a String to be suitable to use as an HTTP parameter value.

String url(Object string)
<dl><dt>Parameters</dt><dd><dl><dt>string</dt><dd>the string to escape values, may be null.</dd></dl></dd></dl><dl><dt>Returns</dt><dd>a new escaped String, null if null string input</dd></dl>

Delegates the process to java.net.URLEncoder#encodeURL(String,"UTF-8").

If $url had the following value:

Hello here & there

then the following Velocity script:

$esc.url($url)

produces this output:

hello+here+%26+there

Source: http://velocity.apache.org/tools/devel/generic/EscapeTool.html#url()

The other option would be ( https://velocity.apache.org/tools/devel/velocity-tools-generic/apidocs/org/apache/velocity/tools/ConversionUtils.html#toURL(java.lang.String) ):

toURL

public static URL toURL(String value)
<dl><dd>Converts a string to a URL. It will first try to treat the string as a File name, then a classpath resource, then finally as a literal URL. If none of these work, then this will return null.

</dd><dd><dl><dt>Parameters:</dt><dd>value - - the string to parse</dd><dt>Returns:</dt><dd>the URL form of the string or null</dd><dt>See Also:</dt><dd>File, ClassUtils.getResource(String,Object), URL</dd><dd></dd><dd></dd></dl></dd></dl>
Ross Bender May 24, 2017

I'm trying the following in a macro:

$esc.url($url)

However, I just see the same output: $esc.url($url)

Any assistance would be appreciated

Suggest an answer

Log in or Sign up to answer