HTML Export Plugin Edited

I'm currently writing an HTML Export Plugin for Cofluence using the ImportExportManager Class.

public String execute() throws ImportExportException, IOException {
DefaultExportContext defaultExportContext = new MyExportContext(space);

TreeBuilder treeBuilder = new TreeBuilder(AuthenticatedUserThreadLocal.get(), contentPermissionManager, pageManager);
ContentTree contentTree = treeBuilder.createPageTree(space);

ProgressMeter progress = new ProgressMeter();
importExportManager.exportAs(defaultExportContext, progress);

return SUCCESS;


when running the program on my Confluence instance, I only get empty .html files. (Well at least something) But when I run the program in the debug mode, everything works fine. How can that be? And what can I do there? 

1 answer

2 votes

Not sure what went wrong in there, perhaps some data missing from the export context.

I have implemented the same as a rest endpoint, and made sure the export context has what it needs (granted it is not the most intuitive API ... in fact it's not entirely API as far as I am concerned)

Below is a very naive implementation for the happy path without any error handling .

Hope this helps


import com.atlassian.confluence.core.ContentPermissionManager;
import com.atlassian.confluence.importexport.DefaultExportContext;
import com.atlassian.confluence.importexport.ImportExportException;
import com.atlassian.confluence.importexport.ImportExportManager;
import com.atlassian.confluence.importexport.impl.ExportScope;
import com.atlassian.confluence.pages.ContentTree;
import com.atlassian.confluence.pages.PageManager;
import com.atlassian.confluence.pages.TreeBuilder;
import com.atlassian.confluence.spaces.Space;
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal;
import com.atlassian.confluence.user.ConfluenceUser;
import com.atlassian.core.util.ProgressMeter;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;


import static java.util.Collections.singletonMap;

public class ExportResource {

private final ImportExportManager importExportManager;
private final ContentPermissionManager contentPermissionManager;
private final PageManager pageManager;
private final SpaceManager spaceManager;

public ExportResource(
final @ComponentImport ImportExportManager importExportManager,
final @ComponentImport ContentPermissionManager contentPermissionManager,
final @ComponentImport PageManager pageManager,
final @ComponentImport SpaceManager spaceManager) {
this.importExportManager = importExportManager;
this.contentPermissionManager = contentPermissionManager;
this.pageManager = pageManager;
this.spaceManager = spaceManager;

public Response exportSpace(final @PathParam("spaceKey") String spaceKey) throws ImportExportException {
final Space space = spaceManager.getSpace(spaceKey);
final ConfluenceUser currentUser = AuthenticatedUserThreadLocal.get();

final TreeBuilder treeBuilder = new TreeBuilder(currentUser, contentPermissionManager, pageManager);
final ContentTree contentTree = treeBuilder.createPageTree(space);

final DefaultExportContext defaultExportContext = new DefaultExportContext();

final ProgressMeter progress = new ProgressMeter();
final String exportPath = importExportManager.exportAs(defaultExportContext, progress);

return Response.ok(singletonMap("path", exportPath)).build();


Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

915 views 23 12
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