Confluence中的WikiToXhtmlMigrator

问题描述 投票:1回答:1

我一直在尝试使用来自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渲染器?

任何帮助将不胜感激。

java xhtml confluence wiki-markup
1个回答
1
投票

掌握Confluence源代码 - 如果你没有购买10个用户/ 10美元的许可证;已经拥有它。然后,您将能够搜索到最好的文档 - 源代码

wikiToXhtmlMigratormigrationRenderer都被定义为ContextMigrationRenderer.xml中的豆类

Atlassian正在访问使用它来访问他们的WikiToXhtmlMigrator

ExceptionTolerantMigrator wikiToXhtmlMigrator = (ExceptionTolerantMigrator) ContainerManager.getComponent("wikiToXhtmlMigrator");

您应该能够使用以下方式访问ErrorReportingV2Renderer

ExceptionTolerantMigrator wikiToXhtmlMigrator = (ExceptionTolerantMigrator) ContainerManager.getComponent("migrationRenderer");
© www.soinside.com 2019 - 2024. All rights reserved.