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

Why is XhtmlContent not converting wiki markup macro as expected?

Nick.Unltd March 27, 2013

I have the following code, where xhtmlContent was injected into the object.

AbstractPage page = pageManager.getAbstractPage(pageId);
try {
    String html = xhtmlContent.convertWikiToView("{blog-posts}", new DefaultConversionContext(page.toPageContext()), null);
} catch (XhtmlException e) {
    e.printStackTrace();
} catch (XMLStreamException e) {
    e.printStackTrace();
}
System.out.println(html);

If I navigate to that particular page in confluence, the macro renders properly and displays a bunch of blogs. However the code above just renders "No blogposts found".

Why does my code end up rendering the macro differently from when I load the actual page? I suspect it is an issue when it is actually searching for blogs, but shouldn't the context take care of that for me?

Edit: If it makes a difference I am calling this code from within a scheduled job module.

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Joe Clark
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2013

I think you're right - if the blog-posts macro is doing some permission checking, it's not going to work within a scheduled job because jobs run in an anonymous user context by default.

You can set a user to be the "current" user with the following code:

com.atlassian.confluence.user.AuthenticatedUserThreadLocal.setUser(theUser);

You need to obtain the user object by calling getUser on com.atlassian.confluence.user.UserAccessor, which you can get injected into your job in the same manner as your xhtmlContent and pageManager components.

0 votes
tousifs
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.
April 3, 2013

Hi Nick.Unltd,

instead of using xhtmlContent in constructor you can try.

com.atlassian.renderer.WikiStyleRenderer.

or

com.atlassian.confluence.content.render.xhtml.Renderer;

regards,

tousif shaikh.

0 votes
Nick.Unltd March 27, 2013

It seems that this is most likely caused by the SiteSearchPermissionsSearchFilter the macro uses when searching for blogs. Since this code is being run in a scheduled job I'm guessing it doesn't have the right permissions when searching. Does anyone know how to set proper permissions so that my scheduled job can run the search, or perhaps a workaround?

TAGS
AUG Leaders

Atlassian Community Events