Search in sources :

Example 1 with StringWriterOutputTarget

use of org.xwiki.filter.output.StringWriterOutputTarget in project xwiki-platform by xwiki.

the class AbstractInstanceInputFilterStreamTest method assertXML.

protected void assertXML(String resource, InstanceInputProperties instanceProperties) throws FilterException, IOException {
    if (instanceProperties == null) {
        instanceProperties = new InstanceInputProperties();
        instanceProperties.setVerbose(false);
    }
    URL url = getClass().getResource("/filter/" + resource + ".xml");
    String expected = IOUtils.toString(url, "UTF-8");
    expected = StringUtils.removeStart(expected, "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n\n");
    InputFilterStream inputFilterStream = this.inputFilterStreamFactory.createInputFilterStream(instanceProperties);
    StringWriterOutputTarget writer = new StringWriterOutputTarget();
    FilterXMLOutputProperties properties = new FilterXMLOutputProperties();
    properties.setTarget(writer);
    OutputFilterStream outputFilterStream = this.xmlOutputFilterStreamFactory.createOutputFilterStream(properties);
    inputFilterStream.read(outputFilterStream.getFilter());
    inputFilterStream.close();
    outputFilterStream.close();
    Assert.assertEquals(expected, writer.getBuffer().toString());
}
Also used : FilterXMLOutputProperties(org.xwiki.filter.filterxml.output.FilterXMLOutputProperties) OutputFilterStream(org.xwiki.filter.output.OutputFilterStream) InstanceInputProperties(org.xwiki.filter.instance.input.InstanceInputProperties) StringWriterOutputTarget(org.xwiki.filter.output.StringWriterOutputTarget) InputFilterStream(org.xwiki.filter.input.InputFilterStream) URL(java.net.URL)

Example 2 with StringWriterOutputTarget

use of org.xwiki.filter.output.StringWriterOutputTarget in project xwiki-platform by xwiki.

the class XARInputFilterStreamTest method assertXML.

private void assertXML(String resource, XARInputProperties xarProperties) throws FilterException, IOException, ComponentLookupException {
    URL url = getClass().getResource("/xar/" + resource + ".output.xml");
    String expected = IOUtils.toString(url, "UTF-8");
    expected = StringUtils.removeStart(expected, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n");
    BeanInputFilterStreamFactory<XARInputProperties> inputFilterStreamFactory = this.mocker.getInstance(InputFilterStreamFactory.class, FilterStreamType.XWIKI_XAR_CURRENT.serialize());
    InputFilterStream inputFilterStream = inputFilterStreamFactory.createInputFilterStream(xarProperties);
    StringWriterOutputTarget writer = new StringWriterOutputTarget();
    FilterXMLOutputProperties properties = new FilterXMLOutputProperties();
    properties.setTarget(writer);
    BeanOutputFilterStreamFactory<FilterXMLOutputProperties> xmlOutputFilterStreamFactory = this.mocker.getInstance(OutputFilterStreamFactory.class, FilterStreamType.FILTER_XML.serialize());
    OutputFilterStream outputFilterStream = xmlOutputFilterStreamFactory.createOutputFilterStream(properties);
    inputFilterStream.read(outputFilterStream.getFilter());
    inputFilterStream.close();
    outputFilterStream.close();
    Assert.assertEquals(expected, writer.getBuffer().toString());
}
Also used : XARInputProperties(org.xwiki.filter.xar.input.XARInputProperties) FilterXMLOutputProperties(org.xwiki.filter.filterxml.output.FilterXMLOutputProperties) OutputFilterStream(org.xwiki.filter.output.OutputFilterStream) StringWriterOutputTarget(org.xwiki.filter.output.StringWriterOutputTarget) InputFilterStream(org.xwiki.filter.input.InputFilterStream) URL(java.net.URL)

Example 3 with StringWriterOutputTarget

use of org.xwiki.filter.output.StringWriterOutputTarget in project xwiki-platform by xwiki.

the class XWikiDocumentFilterUtils method exportEntity.

/**
 * @param entity the entity to read
 * @param xarProperties the configuration of the output filter
 * @param documentProperties the configuration of the input filter
 * @return the XML as a String
 * @throws ComponentLookupException failed to find an event generator for passed entity
 * @throws FilterException when failing to generate export the passed entity
 * @throws IOException when failing to close the stream
 */
public String exportEntity(Object entity, XAROutputProperties xarProperties, DocumentInstanceInputProperties documentProperties) throws ComponentLookupException, FilterException, IOException {
    WriterOutputTarget target = new StringWriterOutputTarget();
    exportEntity(entity, target, xarProperties, documentProperties);
    return target.toString();
}
Also used : WriterOutputTarget(org.xwiki.filter.output.WriterOutputTarget) StringWriterOutputTarget(org.xwiki.filter.output.StringWriterOutputTarget) StringWriterOutputTarget(org.xwiki.filter.output.StringWriterOutputTarget)

Aggregations

StringWriterOutputTarget (org.xwiki.filter.output.StringWriterOutputTarget)3 URL (java.net.URL)2 FilterXMLOutputProperties (org.xwiki.filter.filterxml.output.FilterXMLOutputProperties)2 InputFilterStream (org.xwiki.filter.input.InputFilterStream)2 OutputFilterStream (org.xwiki.filter.output.OutputFilterStream)2 InstanceInputProperties (org.xwiki.filter.instance.input.InstanceInputProperties)1 WriterOutputTarget (org.xwiki.filter.output.WriterOutputTarget)1 XARInputProperties (org.xwiki.filter.xar.input.XARInputProperties)1