How get HTML of confluence page through JAVA API?

Vital Yeutukhovich April 26, 2015

Hello,

I need to get raw html of confluence page in my plugin. 

This code:

pagemanager.getPage(pageID).getBodyAsString();

often gives me macro's tags and I can't to normally parse it.

 

Thanks

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
Panos
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 26, 2015

I am using something like

String rendered = renderer.render(page.getEntity(),conversionContext);
view = HTMLUtils.stripTags(rendered);

where the renderer is a DeviceTypeAwareRenderer:

renderer = (DeviceTypeAwareRenderer)ContainerManager.getComponent("viewRenderer");

and conversionContext

final ConversionContext conversionContext = new DefaultConversionContext(page.toPageContext());

 

Hope it helps smile

munish kumar September 18, 2015

Thanks Can you please give full code. I am having problem in identifying type of objects like renderer and view.

Nick November 25, 2015

DeviceTypeAwareRenderer renderer = (DeviceTypeAwareRenderer) ContainerManager.getComponent("viewRenderer"); final ConversionContext conversionContext = new DefaultConversionContext(page.toPageContext()); String rendered = renderer.render(page.getEntity(), conversionContext); String result = HTMLUtils.stripTags(rendered); return result;

1 vote
jayaramkasangottu October 19, 2015

You could use Jsoup to parse the body to a HTML doc.

Below are the required imports and code you can use to get Elements.

 

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
Document htmlDoc = Jsoup.parse(htmlBody);
Elements elements = htmlDoc.getAllElements();

 

Make sure you add the required dependencies in your pom file.

TAGS
AUG Leaders

Atlassian Community Events