Q: How to Use WikiToXhtmlMigrator to Convert using Confluence SDK I am trying to convert WikiMarkup data to Confluence's XHTML based format. I saw there are 2 different ways to do the same.
1) Use the rest/XML Rpc based API convertWikiToStorageFormat(String token, String markup) to do the same.
2) Other way is to use WikiToXhtmlMigrator to do the same Task. Since I am using Confluence SDK, I choose 2nd way to do the same.
public String getXHTMLConvertedTextFromWiki(String markupData){
    String content = null;
    try {

        RenderContext renderContext = new RenderContext();
        DefaultConversionContext defaultConversionContext = new DefaultConversionContext(renderContext);
        ExceptionTolerantMigrator wikiToXhtmlMigrator = (ExceptionTolerantMigrator) ContainerManager.getComponent("wikiToXhtmlMigrator");
        content = wikiToXhtmlMigrator.migrate(markupData, defaultConversionContext).getContent();

    }catch(Exception e){
        e.printStackTrace();
    }
    return content;
}

But Always, I am getting the exception:  
[INFO] [talledLocalContainer] java.lang.NullPointerException
[INFO] [talledLocalContainer]   at com.atlassian.confluence.content.render.xhtml.migration.WikiToXhtmlMigrator.migrate(WikiToXhtmlMigrator.java:57)
[INFO] [talledLocalContainer]   at com.atlassian.confluence.content.render.xhtml.migration.WikiToXhtmlMigrator.migrate(WikiToXhtmlMigrator.java:69)

I tried to push the render mode by setting All in render Context but got the same exception.
renderContext.pushRenderMode(RenderMode.ALL);
Please let me know the what is the problem in this example and show the correct way to do it.

A: Able to convert markup to Xhtml through below code.
public String getXHTMLConvertedTextFromWiki(String wikiText){
    String content = null;
    try {

        List<RuntimeException> exceptions = newArrayList();
        XhtmlContent xhtmlContent = (XhtmlContent)ContainerManager.getComponent("xhtmlContent");
        content = xhtmlContent.convertWikiToStorage(wikiText, new DefaultConversionContext(new PageContext()),exceptions);
         for(RuntimeException e : exceptions){
             log.error(e.getMessage());
         }
    }catch(Exception e){
        e.printStackTrace();
    }
    return content;
}

Please make sure that, your newline characters should not be lost while reading Page Markup Data if reading from external source.
