Xwiki转换演示样本

时间:2015-07-14 16:24:56

标签: java rendering markdown xwiki

尝试在java独立类中使用xwiki进行此演示,但不起作用。我使用的是xwiki 7.0版本。有人试过这个吗?

http://rendering.xwiki.org/xwiki/bin/view/Main/Demo?inputsyntax=xhtml%2F1.0&outputsyntax=xwiki%2F2.1&input=%3Ch3+id%3D%22Hhelo%22%3E%3Cspan%3Ehelo%3C%2Fspan%3E%3C%2Fh3%3E#HDemo

public class HtmlToXwikiTest
{
    private Converter converter;
private WikiPrinter printer;

@Test
public void testHtmlToMarkdown() throws ComponentLookupException, ConversionException, ParseException, ComponentRepositoryException
{
    WikiPrinter printer = new DefaultWikiPrinter();
    converter.convert(new StringReader("<h3 id=\"HHeader3\"><span>Header 3</span></h3>"), Syntax.XHTML_1_0, Syntax.XWIKI_2_1,  printer);

    System.out.println(printer.toString());
    assertThat(printer.toString(), containsString("==="));
}

@Before
public void setUp() throws ComponentLookupException, ConversionException
{
    EmbeddableComponentManager componentManager = new EmbeddableComponentManager();
    componentManager.initialize(this.getClass().getClassLoader());

    converter = componentManager.getInstance(Converter.class);
    printer = new DefaultWikiPrinter();
}

}

获得, java.lang.NoSuchFieldError:fRecognizedFeatures         在org.apache.xerces.parsers.XML11NonValidatingConfiguration。(未知来源)         在org.apache.xerces.parsers.XML11NonValidatingConfiguration。(未知来源)         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)         at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)         at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)         at java.lang.reflect.Constructor.newInstance(Constructor.java:526)         在java.lang.Class.newInstance(Class.java:379)         在org.xwiki.xml.internal.DefaultXMLReaderFactory.createXMLReader(DefaultXMLReaderFactory.java:74)         在org.xwiki.rendering.internal.parser.xhtml.wikimodel.XWikiXMLReaderFactory.createXMLReader(XWikiXMLReaderFactory.java:73)         在org.xwiki.rendering.internal.parser.xhtml.XHTMLParser.createWikiModelParser(XHTMLParser.java:151)         在org.xwiki.rendering.internal.parser.wikimodel.AbstractWikiModelParser.parse(AbstractWikiModelParser.java:128)

1 个答案:

答案 0 :(得分:0)

您的示例看起来没问题(即使您定义了两次打印机对象,但这不是测试的问题)。

在DefaultXMLReaderFactory.java:74,代码为:

// See http://xerces.apache.org/xerces2-j/faq-grammars.html#faq-1
Object xercesConfiguration = Class.forName("org.apache.xerces.parsers.XML11NonValidatingConfiguration").newInstance();

从堆栈跟踪中可以加载XML11NonValidatingConfiguration类,但它是以某种方式失败的构造函数调用。看到关于fRecognizedFeatures的错误我看不出那是怎么回事......

如果我是你,我会尝试使用不同版本的Xerces,看它是否有帮助。