This is a constantly updated FAQ listing questions and answers asked by people developing Confluence plugins and working with the Confluence code base in general. For general questions, check Confluence Main FAQ.
h3 QUESTION: How to access the renderContext of a decorator
In the main.vmd, I have a section that I would like to render as wiki text, in order to do this I need access to a renderContext to pass in to a helper.
Charles has said that it is possible, but heavily discouraged it. With that in mind, I would still like to know how to do it (or an alternative method to achieve what I want). See mail 133426.

Posted by dhardiker@adaptavist.com at Sep 29, 2005 07:56
|
I'm not sure this qualifies as an FAQ. 
You can get the renderContext out of any ContentEntityObject using toRenderContext() (new PageContext(obj) does the same thing). There's no set way in a decorator, however, to say "Get the renderContext of the currently-being-displayed CEO".

Posted by cmiller at Oct 03, 2005 23:22
|
I think a more accurate question is, from any given velocity decorator file (global.vmd, space.vmd, page.vmd ...) - how do I get the currently-being-displayed CEO?
$page gives me the page in side of page.vmd (so I can use $page.toRenderContext() or similar), but of course that doesn't work in space.vmd.
If my question is fundamentally wrong I apologise - what I want to do is 2 fold:
- Get hold of the Velocity Context variables so I can parse a custom string, as if it was injected directly into the vmd itself (equivelant of #parse "string-content-instead-of-filename")
- Get hold of the Render Context so that the result from the Velocity parsing above can be rendered as wiki markup > html output.
I hope that makes more sense!

Posted by dhardiker@adaptavist.com at Oct 04, 2005 09:41
|
As I said in the previous comment, there's no set way to get the currently-being-displayed CEO in a decorator. It would make sense to have such a method on the theme helper object somewhere. For now, you could try a process of elimination: try in order
- $helper.page (which actually returns an AbstractPage which could either be a Page or BlogPost object)
- $helper.action.mail
- $helper.action.personalInformationEntity
- $helper.space.description (This may be not necessarily be what is being viewed, so you might want to skip this as a fallback)
If all these return null, you're looking at a global page with no space or entity to look at.
In main.vmd, however, you're out of luck. By the time SiteMesh hits main.vmd, most of the context has been lost, except for what has been passed up from the other decorators or templates inside <content> blocks.

Posted by cmiller at Oct 09, 2005 09:06
|
is 'myObject' supposed to be the class I want to contain autowire objects, or the object I want to be autowired?
The latter - I've updated the document.
Hmm.. I must be missing something. I've tried both:
- UserAccessor userAccessor = (UserAccessor) ContainerManager.getComponent("userAccessor");
- bucket.container.ContainerManager.autowireComponent(userAccessor);
and I get NullPointerExceptions.
Could you give a more in depth example?
Thanks.

Posted by laura.kolker at Oct 11, 2005 12:22
|
QUESTION: How do I persist a "Request" level object?
I am currently using ServletActionContext.getRequest().setAttribute() (and the appropriate getter), however there are cases where the request will not exist (eg: when the macro is rendered from a decorator (like in the LeftNav theme), or when exporting to PDF).
What should I use? Perhaps the RenderContext (or one of its ancestors) should contain the ability to set/get attributes?
If this is the case then I'll file a JIRA support issue.

Posted by dhardiker@adaptavist.com at Nov 10, 2005 11:56
|
Dan,
perhaps you can tell us what you are trying to achieve and we can think about a solution for you problem. However, we probably shouldn't discuss it in this comment thread, so drop us an email.
Cheers,
Jens

Posted by jens@atlassian.com at Nov 14, 2005 02:37
|
I have a related question. There seems to be an incompatibility between 1.4 and 2.0 in that ServletActionContext.getRequest() returns null in 2.0 in cases that worked in 1.4. For instance if the preview tab is selected, it is null. Interestingly, in a comment where you are allowed to press the preview button, the button works but the preview tab does not (ie. returns null). Why is it incompatible and what recommendations are there for macro writers? Thanks.

Posted by bob.swift@charter.net at Nov 23, 2005 22:34
|
The general rule is: assume that ServletActionContext.getAnything() will return null. There are several situations in which macros will be rendered without the ServletActionContext being populated, whether it be because the request hasn't come in via Webwork, as is the case with AJAX requests that are routed through the DWR servlet, or because the request is being rendered for something like an email which doesn't have a web context to begin with.
The ServletActionContext should always be considered a bonus - if it's populated, you can do something useful with it, but you shouldn't count on its existence.

Posted by cmiller at Nov 24, 2005 00:54
|
Charles, thanks. Seems like ConfluenceMockServletRequest() serves similar purpose for getting things like context path - getContextPath().

Posted by bob.swift@charter.net at Dec 03, 2005 09:58
|
How do you add a new section to the notation guide? If I don't used an existing section (like Advanced) then the macro help doesn't show up anywhere.

Posted by bob.swift@charter.net at Dec 08, 2005 17:22
|
As far as I know, it's currently not possible without source hacking. I've wanted the same thing on several occasions (eg. Scaffolding). Vote here.

Posted by david@randombits.org at Dec 08, 2005 18:06
|
The following comments I posted at http://confluence.atlassian.com/display/CONFEXT/Vote+Macro?focusedCommentId=152965#comment-152965 might be of relevance here:
Ok it looks to me like the behavior of AbstractHtmlGeneratingMacro has changed from what it was in 1.3: basically the body that's provided to the macro (through MacroParameter) seems to be raw HTML instead of raw wiki text as in the past. Not sure if this was intended by the Atlassian crew and/or why it was done.
As a result, it seems the only way out is for this macro to be rewritten for 2.x, by extending BaseMacro and use RenderMode.NO_RENDER (ie. no rendering of wiki into HTML).
Am I right about this? If so, it might be worth documenting on this page. I know it wouldn't matter for new macros but it might be useful to know for legacy macros (to determine whether they might have to be rewritten).

Posted by oalaoui at Jan 15, 2006 22:08
|
Is there an available BNF/EBNF/or any else grammar for Confluence wiki format ?

Posted by ersiner at Jan 30, 2006 16:00
|
No, Confluence wiki format is converted to HTML via regular expressions, not via parsing. This allows any markup to produce sensible HTML without the problems that a parser would have trying to recover from errors.

Posted by tom@atlassian.com at Jan 31, 2006 18:47
|
Is it possible to access classes from one plugin jar in another? I'm trying to write an extension of another plugin by extending a Base class, but when I try to upload my JAR, I'm getting a ClassNotFoundException. Short of combining the two plugins together, is there any way to access classes written for one plugin in another?

Posted by bsensale@pantero.com at Feb 23, 2006 16:28
|
The only way to do this that I'm aware of is for at least one of the plugins to have been installed by putting it into WEB-INF/lib instead of uploading it. So, if plugin-a.jar depends on classes in plugin-b.jar, plugin-b.jar needs to be installed into WEB-INF/lib. If plugin-b.jar also depends on classes in plugin-a.jar, then both plugins will have to be installed into WEB-INF/lib.
This is due to the way the class loader for uploaded plugins works. There are some ideas bouncing around to improve the situation, but the scenario you described is unlikely to be resolved any time soon, unfortunately.

Posted by david@randombits.org at Feb 23, 2006 16:41
|
Thanks...dropping it in web-inf/lib did the trick.

Posted by bsensale@pantero.com at Feb 23, 2006 17:20
|
How do I programatically remove and add attachments to a page in Confluence?
Say I use a page as an informal document (i.e., word, excel, powerpoint, etc.) repository. I also have a proper document repository outside of Confluence. How would I update the page in Confluence programatically, containing these documents as attachments, with a new set of attachments?

Posted by sleight42@gmail.com at Apr 04, 2006 17:33
|
There are a number of options:
WebDAV plugin: CONFEXT:WebDAV Plugin
Perl XML-RPC Client: CONFEXT:Perl XML-RPC client
Multiple Attachments Uploader: CONFEXT:Multiple Attachments Upload Client
Confluence file uploaded: CONFEXT:Confluence File Uploader

Posted by gfraser at Apr 04, 2006 17:38
|
If you want an example, have a look at the WebDAV Plugin code for AttachmentResource (it's in the saveData() method). You will have to get your file input stream from elsewhere, but that should be a fairly straightforward process.

Posted by david@randombits.org at Apr 04, 2006 18:06
|
Or CONFEXT:Confluence SOAP Client in Java

Posted by bob.swift@charter.net at Apr 04, 2006 20:00
|
Got it. Indeed, providing a different input stream would be a simple matter. Polling the document baseline repository ought to be a fairly simple matter as well. Thanks for all of the great and timely remarks, folks!

Posted by sleight42@gmail.com at Apr 05, 2006 10:57
|
How do I programmatically create pages?
I need to automatically create new pages from within a confluence plugin, what would be the best method to create these pages?

Posted by kustere at Oct 05, 2006 02:54
|
I want to open a link in a new window. How can i do that with Confluence ?

Posted by ppb141 at Nov 06, 2006 03:26
|
This macro might do it for you:
http://confluence.atlassian.com/display/CONFEXT/New+window+macro

Posted by nicholas@atlassian.com at Nov 07, 2006 16:16
|
I'm using ASP.NET to talk to the Confluence Web Service API. I can call renderContent OK without passing the final parameter. However then I try and pass this paremeter I get the error message below.
This is the Exception generated by Visual Studio 2005.

Posted by darragh at Nov 13, 2006 09:12
|
It looks like this is a known problem where we use a Java type which isn't compatible with .NET web services.
The relevant issue is CONF-3520. Please vote for that issues to help us prioritise it.

Posted by mryall at Nov 23, 2006 01:19
|