Search in sources :

Example 1 with DefaultURLInputSource

use of org.xwiki.filter.input.DefaultURLInputSource in project xwiki-platform by xwiki.

the class AbstractInstanceFilterStreamTest method importFromXML.

protected void importFromXML(String resource, InstanceOutputProperties instanceProperties) throws FilterException {
    if (instanceProperties == null) {
        instanceProperties = new InstanceOutputProperties();
        instanceProperties.setVerbose(false);
    }
    OutputFilterStream outputFilterStream = this.outputFilterStreamFactory.createOutputFilterStream(instanceProperties);
    URL url = getClass().getResource("/filter/" + resource + ".xml");
    FilterXMLInputProperties properties = new FilterXMLInputProperties();
    properties.setSource(new DefaultURLInputSource(url));
    InputFilterStream inputFilterStream = this.xmlInputFilterStreamFactory.createInputFilterStream(properties);
    inputFilterStream.read(outputFilterStream.getFilter());
    try {
        inputFilterStream.close();
    } catch (IOException e) {
        throw new FilterException("Failed to close input wiki stream", e);
    }
    try {
        outputFilterStream.close();
    } catch (IOException e) {
        throw new FilterException("Failed to close output wiki stream", e);
    }
}
Also used : InstanceOutputProperties(org.xwiki.filter.instance.output.InstanceOutputProperties) OutputFilterStream(org.xwiki.filter.output.OutputFilterStream) DefaultURLInputSource(org.xwiki.filter.input.DefaultURLInputSource) FilterException(org.xwiki.filter.FilterException) FilterXMLInputProperties(org.xwiki.filter.filterxml.input.FilterXMLInputProperties) IOException(java.io.IOException) InputFilterStream(org.xwiki.filter.input.InputFilterStream) URL(java.net.URL)

Example 2 with DefaultURLInputSource

use of org.xwiki.filter.input.DefaultURLInputSource in project xwiki-platform by xwiki.

the class XWikiDocumentFilterUtilsTest method assertXML.

private void assertXML(Object entity, String resource) throws FilterException, IOException, ComponentLookupException {
    URL url = getClass().getResource("/filter/xar/" + resource + ".xml");
    assertNotNull(url);
    String expected = IOUtils.toString(url, "UTF-8");
    expected = StringUtils.removeStart(expected, "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n\n");
    // Import
    Object importedEntity = this.mocker.getComponentUnderTest().importEntity(entity, new DefaultURLInputSource(url));
    // Export
    String actual = this.mocker.getComponentUnderTest().exportEntity(importedEntity);
    // Validate
    assertEquals(expected, actual);
}
Also used : BaseObject(com.xpn.xwiki.objects.BaseObject) DefaultURLInputSource(org.xwiki.filter.input.DefaultURLInputSource) URL(java.net.URL)

Example 3 with DefaultURLInputSource

use of org.xwiki.filter.input.DefaultURLInputSource in project xwiki-platform by xwiki.

the class ExtensionInstanceOutputFilterStreamTest method importFromXML.

protected void importFromXML(String resource, InstanceOutputProperties instanceProperties) throws FilterException {
    if (instanceProperties == null) {
        instanceProperties = new InstanceOutputProperties();
        instanceProperties.setVerbose(false);
    }
    OutputFilterStream outputFilterStream = this.outputFilterStreamFactory.createOutputFilterStream(instanceProperties);
    URL url = getClass().getResource("/" + resource + ".xml");
    FilterXMLInputProperties properties = new FilterXMLInputProperties();
    properties.setSource(new DefaultURLInputSource(url));
    InputFilterStream inputFilterStream = this.xmlInputFilterStreamFactory.createInputFilterStream(properties);
    inputFilterStream.read(outputFilterStream.getFilter());
    try {
        inputFilterStream.close();
    } catch (IOException e) {
        throw new FilterException("Failed to close input wiki stream", e);
    }
    try {
        outputFilterStream.close();
    } catch (IOException e) {
        throw new FilterException("Failed to close output wiki stream", e);
    }
}
Also used : ExtensionInstanceOutputProperties(org.xwiki.filter.instance.output.ExtensionInstanceOutputProperties) InstanceOutputProperties(org.xwiki.filter.instance.output.InstanceOutputProperties) OutputFilterStream(org.xwiki.filter.output.OutputFilterStream) DefaultURLInputSource(org.xwiki.filter.input.DefaultURLInputSource) FilterException(org.xwiki.filter.FilterException) FilterXMLInputProperties(org.xwiki.filter.filterxml.input.FilterXMLInputProperties) IOException(java.io.IOException) InputFilterStream(org.xwiki.filter.input.InputFilterStream) URL(java.net.URL)

Aggregations

URL (java.net.URL)3 DefaultURLInputSource (org.xwiki.filter.input.DefaultURLInputSource)3 IOException (java.io.IOException)2 FilterException (org.xwiki.filter.FilterException)2 FilterXMLInputProperties (org.xwiki.filter.filterxml.input.FilterXMLInputProperties)2 InputFilterStream (org.xwiki.filter.input.InputFilterStream)2 InstanceOutputProperties (org.xwiki.filter.instance.output.InstanceOutputProperties)2 OutputFilterStream (org.xwiki.filter.output.OutputFilterStream)2 BaseObject (com.xpn.xwiki.objects.BaseObject)1 ExtensionInstanceOutputProperties (org.xwiki.filter.instance.output.ExtensionInstanceOutputProperties)1