Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Confluence存储格式XML转换为HTML?_Xml_Xslt_Xml Serialization_Confluence - Fatal编程技术网

如何将Confluence存储格式XML转换为HTML?

如何将Confluence存储格式XML转换为HTML?,xml,xslt,xml-serialization,confluence,Xml,Xslt,Xml Serialization,Confluence,我使用RESTAPI从confluence中提取内容 API返回带有内容属性的汇流页面。内容是XHTML和专有XML标记的混合。XML是合流存储格式: 自定义XML标记用于图像、相对链接和附件等。如果我直接呈现内容,自定义XML将不会呈现 我找到了一个应该转换格式的端点: 我认为它不再受到支持 我还发现了这个项目: 它将confluence XML转换为confluence wiki标记。该项目附带了两张.xsl工作表,一张是confluence2wiki.xsl,用于处理标记转换,另一

我使用RESTAPI从confluence中提取内容

API返回带有内容属性的汇流页面。内容是XHTML和专有XML标记的混合。XML是合流存储格式:

自定义XML标记用于图像、相对链接和附件等。如果我直接呈现内容,自定义XML将不会呈现

我找到了一个应该转换格式的端点:

我认为它不再受到支持

我还发现了这个项目:

它将confluence XML转换为confluence wiki标记。该项目附带了两张
.xsl
工作表,一张是
confluence2wiki.xsl
,用于处理标记转换,另一张是
confluence2xhtml.xsl
,听起来似乎可以完成这项工作,但不幸的是,它的实现很差。它从字面上将汇流XML转换为类似XML的XHTML。因此,来自汇流XML的图像标记不幸变成:


ac:图像 ac:alt =" 例1.png "

ri:url ri:价值 =" https://example.com/attachments/token/2ujwb0dm4jsorgk/?name=Omniata_Docs_Projects_Example1.png "


如果需要使用REST API进行转换,目前最好的方法是编写一个插件并实现自己的REST API来完成转换

通过将存储格式转换为HTML,您可以开始这样做:

public String convertStorageToView(int pageId)
{
    Page page = pageManager.getById(pageId);        
    String storage = page.getBodyAsString();

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

        return xhtmlContent.convertStorageToView(storage, conversionContext);
    }
    catch (XhtmlException e)
    {
        e.printStackTrace();
    }
    catch (XMLStreamException e)
    {
        e.printStackTrace();
    }

    return null;
}

您还必须编写。

通过远程API调用该方法。如果您的内容是旧格式的,还有一个ConvertWikitoStorage方法。

类似于其他答案中已经显示的内容,但我不清楚您是否必须使用XHTML内容。您可以通过构造函数很容易地获得它的实例

public class MyServlet extends HttpServlet {

    private Logger LOGGER = Logger.getLogger(getClass());

    private final PageManager pageManager;
    private final XhtmlContent xhtmlContent;


    public static final String PARAM_PAGE_ID = "pageId";


    public MyServlet( PageManager pageManager, XhtmlContent xhtmlContent) {
    this.pageManager = pageManager;
        this.xhtmlContent = xhtmlContent;
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        //fetch page or blogpost
        ContentEntityObject page = pageManager.getPage(Long.parseLong(request.getParameter(PARAM_PAGE_ID)));
        if (page == null) {
            page = pageManager.getBlogPost(Long.parseLong(request.getParameter(PARAM_PAGE_ID)));
        }
        if (page != null) {
            String htmlContent = "";
            final ConversionContext conversionContext = new DefaultConversionContext(page.toPageContext());
            try {
                htmlContent = xhtmlContent.convertStorageToView(page.getBodyAsString(), conversionContext);
            } catch (XMLStreamException e) {
                htmlContent = "ERROR ON EXPORT";
                LOGGER.error(e);
            } catch (XhtmlException e) {
                htmlContent = "ERROR ON EXPORT";
                LOGGER.error(e);
            }

        } else {
        //do some errorhandling here
    }
    //.. do something with the content .. render it in a velocity file for example
    }

例如,您可以在velocity文件中渲染数据,也可以直接在响应中写入数据。

我找到了您想要完成的任务。在“将存储格式转换为视图格式”一节中,您有一个关于如何执行RESTful请求以将存储格式转换为视图格式的示例。