Search in sources :

Example 1 with MergeContentFilter

use of aQute.libg.sax.filters.MergeContentFilter in project bnd by bndtools.

the class TestSAXFilters method testMergeInconsistentRoots.

public void testMergeInconsistentRoots() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    MergeContentFilter merger = new MergeContentFilter();
    XMLReader reader = SAXUtil.buildPipeline(new StreamResult(output), merger);
    try {
        reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE1.getBytes())));
        reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE3.getBytes())));
        fail("Should throw exception for inconsistent roots");
    } catch (SAXException e) {
    }
}
Also used : InputSource(org.xml.sax.InputSource) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) MergeContentFilter(aQute.libg.sax.filters.MergeContentFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Example 2 with MergeContentFilter

use of aQute.libg.sax.filters.MergeContentFilter in project bnd by bndtools.

the class TestSAXFilters method testDontRepeatProcessingInstruction.

public void testDontRepeatProcessingInstruction() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    MergeContentFilter merger = new MergeContentFilter();
    XMLReader reader = SAXUtil.buildPipeline(new StreamResult(output), merger);
    reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE5.getBytes())));
    reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE5.getBytes())));
    merger.closeRootAndDocument();
    String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><?xml-stylesheet type='text/xsl' href='http://www2.osgi.org/www/obr2html.xsl'?><root><a/><a/></root>";
    assertEquals(expected, stripLineBreaks(output.toString()));
}
Also used : InputSource(org.xml.sax.InputSource) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) MergeContentFilter(aQute.libg.sax.filters.MergeContentFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLReader(org.xml.sax.XMLReader)

Example 3 with MergeContentFilter

use of aQute.libg.sax.filters.MergeContentFilter in project bnd by bndtools.

the class TestSAXFilters method testMerge.

public void testMerge() throws Exception {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    MergeContentFilter merger = new MergeContentFilter();
    XMLReader reader = SAXUtil.buildPipeline(new StreamResult(output), merger);
    reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE1.getBytes())));
    reader.parse(new InputSource(new ByteArrayInputStream(SAMPLE2.getBytes())));
    merger.closeRootAndDocument();
    assertEquals(MERGED1_2, output.toString());
    assertEquals(2, merger.getRootElements().size());
}
Also used : InputSource(org.xml.sax.InputSource) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) MergeContentFilter(aQute.libg.sax.filters.MergeContentFilter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLReader(org.xml.sax.XMLReader)

Aggregations

MergeContentFilter (aQute.libg.sax.filters.MergeContentFilter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 StreamResult (javax.xml.transform.stream.StreamResult)3 InputSource (org.xml.sax.InputSource)3 XMLReader (org.xml.sax.XMLReader)3 SAXException (org.xml.sax.SAXException)1