Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

access query string parameter in plugin macro

Roger Weinheimer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 3, 2013

Can a plugin macro on a page access a query string parameter included in the request URL for the page?

Example:

http://exampledomain.com/display/spacekey/Home?myquerystringparameter=X

in macro sited on Home page, run the following code.

public class MyMacro implements Macro {

	@Override
    public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException
    {
	// some API to consume query string parameter?
        Object myQueryStringParam = someAPI('myquerystringparameter');
        ...

My question is what API, if any, can I use to consume the query string parameter?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
Eugen Mayer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 5, 2013
import com.opensymphony.webwork.ServletActionContext;
import javax.servlet.http.HttpServletRequest;

// then use this
HttpServletRequest request = ServletActionContext.getRequest();
string param = request.getParameter("myquerystringparamter"));

Thats pretty straighforward.

Roger Weinheimer
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2013

Perfect. Thanks.

Xavier Martin September 5, 2016

In what language is that code written? I mean, what macro do I have to select and then paste that code into its body? Thanks.

Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 6, 2016

They are talking about a formal java macro built in a plugin. You should be able to use the same technique in a Groovy Macro.

Xavier Martin September 6, 2016

Great! At last! You only have to add a groovy macro and then paste this code:

def p=request.getParameter("p")
println(p)

"Save" and then, if you call that page adding this to the URL:

?p=v

...a "v" is shown.

Thanks Bob!

Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 6, 2016

Good. Nice idea to take advantage of the request pre-defined variable to make it easier when used in groovy.

0 votes
Thomas Kalsberger, MSc January 4, 2013

hi!

have a look at the free plugins from randombits. they contain lots of very usefull features and are highly recommended

e.g. from confluence support plugin which you can get from here:

https://marketplace.atlassian.com/plugins/org.randombits.support.support-core

check out this:

https://svn.atlassian.com/svn/public/contrib/confluence/libraries/org.randombits.confluence/confluence-support/tags/1.1/src/java/org/randombits/confluence/support/MacroInfo.java

cheers,

Thomas

TAGS
AUG Leaders

Atlassian Community Events