use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class AnnotationXHTMLRendererTest method getAnnotatedHTMLWithoutAnnotations.
/**
* Test rendering with the annotations renderer but without annotations doesn't alter the content.
*
* @throws Exception in case something goes wrong looking up components and rendering
*/
@Test
public void getAnnotatedHTMLWithoutAnnotations() throws Exception {
Parser parser = getComponentManager().getInstance(Parser.class, docFactory.getDocument(docName).getSyntax());
XDOM xdom = parser.parse(new StringReader(docFactory.getDocument(docName).getSource()));
// run transformations
TransformationManager transformationManager = getComponentManager().getInstance(TransformationManager.class);
TransformationContext context = new TransformationContext(xdom, Syntax.valueOf(docFactory.getDocument(docName).getSyntax()));
context.setTargetSyntax(Syntax.ANNOTATED_XHTML_1_0);
transformationManager.performTransformations(xdom, context);
AnnotationPrintRenderer renderer = getComponentManager().getInstance(AnnotationPrintRenderer.class, ANNOTATIONS_RENDERER_HINT);
WikiPrinter printer = new DefaultWikiPrinter();
renderer.setPrinter(printer);
xdom.traverse(renderer);
assertEquals("[" + docName + "] test failed", docFactory.getDocument(docName).getRenderedContent(), printer.toString());
}
use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class XDOMOfficeDocumentTest method createOfficeDocument.
/**
* Creates an {@link XDOMOfficeDocument} by parsing the given content.
*
* @param content the content to be parsed
* @param syntax the syntax of the given content
* @return the created {@link XDOMOfficeDocument}
* @throws Exception if it fails to parse the given content
*/
private XDOMOfficeDocument createOfficeDocument(String content, String syntax) throws Exception {
Parser parser = getComponentManager().getInstance(Parser.class, syntax);
XDOM xdom = parser.parse(new StringReader(content));
return new XDOMOfficeDocument(xdom, new HashMap<String, byte[]>(), getComponentManager());
}
use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class RenderingScriptServiceTest method parseAndRenderWhenErrorInParse.
@Test
public void parseAndRenderWhenErrorInParse() throws Exception {
Parser parser = this.mocker.registerMockComponent(Parser.class, "plain/1.0");
when(parser.parse(new StringReader("some [[TODO]] stuff"))).thenThrow(new ParseException(("error")));
Assert.assertNull(this.mocker.getComponentUnderTest().parse("some [[TODO]] stuff", "plain/1.0"));
}
use of org.xwiki.rendering.parser.Parser in project xwiki-platform by xwiki.
the class DefaultContentParserTest method configure.
@Before
public void configure() throws Exception {
Parser parser = mocker.registerMockComponent(Parser.class, Syntax.PLAIN_1_0.toIdString());
when(parser.parse(argThat(any(Reader.class)))).thenReturn(new XDOM(Collections.<Block>emptyList()));
EntityReferenceSerializer<String> serializer = mocker.getInstance(EntityReferenceSerializer.TYPE_STRING);
when(serializer.serialize(DOCUMENT_REFERENCE)).thenReturn(SOURCE);
}
Aggregations