Convert String to URL in vm file.

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

This widget could not be displayed.

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>

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

112 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you