我一直在尝试使用JAVA API(https://docs.atlassian.com/atlassian-confluence/5.3.1/index.html?com/atlassian/confluence/)中的此类,但是由于缺少适当的文档,我一直在苦苦挣扎。我的目标是从Wiki标记格式转换为Confluence使用的xhtml:
到目前为止,这是我的代码:
package org.myorg;
import java.util.List;
import java.util.ArrayList;
import java.io.BufferedReader;
import java.io.FileReader;
import com.atlassian.renderer.RenderContext;
import com.atlassian.confluence.content.render.xhtml.migration.WikiToXhtmlMigrator;
import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.content.render.xhtml.DefaultConversionContext;
import com.atlassian.confluence.content.render.xhtml.storage.pagelayouts.StoragePageLayoutMarshaller;
import com.atlassian.confluence.xhtml.api.MacroDefinition;
import com.atlassian.confluence.content.render.xhtml.storage.macro.*;
import com.atlassian.renderer.RendererConfiguration;
import com.atlassian.renderer.links.LinkRenderer;
import com.atlassian.renderer.v2.V2LinkRenderer;
import com.atlassian.renderer.embedded.EmbeddedResourceRenderer;
import com.atlassian.renderer.embedded.DefaultEmbeddedResourceRenderer;
import com.atlassian.confluence.content.render.xhtml.migration.ErrorReportingV2Renderer;
import com.atlassian.renderer.v2.V2Renderer;
import com.atlassian.confluence.content.render.xhtml.storage.macro.StorageMacroV2Marshaller;
import com.atlassian.renderer.v2.components.RendererComponent;
public class Wiki2xhtml {
public static class Rend implements RendererConfiguration
{
public String getCharacterEncoding()
{
return new String("UTF-8");
//Will return the character encoding for the current application.
}
public String getWebAppContextPath()
{
return "";
//Returns the context path of the running web application.
}
public boolean isAllowCamelCase()
{
return true;
//If this method returns true then camelCase links will be allowed and generated.
}
public boolean isNofollowExternalLinks()
{
return false;
//If this method returns true then external links will be generated with the rel=nofollow attribute.
}
}
public static void main()
{
BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\arenu.CORP\\Desktop\\docs\\Engineering\\markupFile"));
String wikiContent = new String();
String line = null;
while ((line = reader.readLine()) != null)
{
wikiContent = wikiContent + line;
}
/*
public WikiToXhtmlMigrator(com.atlassian.renderer.RendererConfiguration rendererConfiguration,
com.atlassian.renderer.links.LinkRenderer defaultLinkRenderer,
com.atlassian.renderer.embedded.EmbeddedResourceRenderer defaultEmbeddedRenderer,
ErrorReportingV2Renderer renderer)
*/
RenderContext rE = new RenderContext();
DefaultConversionContext dCE = new DefaultConversionContext(rE);
RendererConfiguration rC = new Rend();
LinkRenderer dLC = new V2LinkRenderer();
EmbeddedResourceRenderer dER = new DefaultEmbeddedResourceRenderer();
//ErrorReportingV2Renderer(java.util.List<com.atlassian.renderer.v2.components.RendererComponent> components, Marshaller<MacroDefinition> wikiMarkupMacroMarshaller)
List<RendererComponent> rCList = new ArrayList<RendererComponent> ();
MacroDefinition mD = new MacroDefinition();
ErrorReportingV2Renderer renderer = new ErrorReportingV2Renderer(rCList, whatshouldcomehere) ;
WikiToXhtmlMigrator migr = new WikiToXhtmlMigrator(rC,dLC,dER,vR);
//String migrated = new String();
//migrated = migrate(java.lang.String wiki, com.atlassian.renderer.RenderContext context, java.util.List<java.lang.RuntimeException> exceptions)
//migrated = migrate(java.lang.String wiki, ConversionContext conversionContext)
String migrated = (migr.migrate(wikiContent, dCE)).getContent();
System.out.println(migrated);
}
}
我不确定这是否是正确的方法,并且由于文档中定义所有内容的抽象方式,我不知道每个部分的含义。
有人可以帮我初始化
ErrorReportingV2Renderer
渲染器吗?任何帮助将不胜感激。
最佳答案
掌握Confluence的源代码-如果您没有许可证,请购买10个用户/ 10美元的许可证。然后,您将可以找到最佳的文档-源代码wikiToXhtmlMigrator
和migrationRenderer
都被定义为ContextMigrationRenderer.xml
中的bean
Atlassian正在使用来访问其WikiToXhtmlMigrator
:
ExceptionTolerantMigrator wikiToXhtmlMigrator = (ExceptionTolerantMigrator) ContainerManager.getComponent("wikiToXhtmlMigrator");
您应该能够使用以下命令访问
ErrorReportingV2Renderer
:ExceptionTolerantMigrator wikiToXhtmlMigrator = (ExceptionTolerantMigrator) ContainerManager.getComponent("migrationRenderer");