Examples of EmitElementTransformer


Examples of org.apache.cocoon.stax.stress.src.EmitElementTransformer

     * @exception Exception Is thrown if an error occurs loading the files or in the pipeline
     *                itself.
     */
    @Test
    public void testEmitTransformerBySteps() throws Exception {
        EmitElementTransformer transformer = new EmitElementTransformer("parent", new ArrayList<Attribute>(), "child",
                1);

        transformer.setParent(new StAXProducer() {
            private final XMLEventFactory eventFactory = XMLEventFactory.newInstance();
            private boolean startEmitted = false;

            public boolean hasNext() {
                return true;
            }

            public XMLEvent nextEvent() throws XMLStreamException {
                if (this.startEmitted) {
                    return this.eventFactory.createEndElement("", "", "parent");
                }
               
                this.startEmitted = true;
                return this.eventFactory.createStartElement("", "", "parent");
            }

            public XMLEvent peek() throws XMLStreamException {
                throw new RuntimeException("not impl");
            }

            public void setConsumer(Consumer consumer) {
            }

            public void finish() {
            }

            public void setConfiguration(Map<String, ? extends Object> configuration) {
            }

            public void setup(Map<String, Object> parameters) {
            }
        });

        // "parent" start-tag
        assertTrue(transformer.hasNext());
        XMLEvent event = transformer.nextEvent();
        assertTrue(event.isStartElement());
        assertEquals(event.asStartElement().getName().getLocalPart(), "parent");

        // "child" start-tag
        assertTrue(transformer.hasNext());
        event = transformer.nextEvent();
        assertTrue(event.isStartElement());
        assertEquals(event.asStartElement().getName().getLocalPart(), "child");

        // "child" end-tag
        assertTrue(transformer.hasNext());
        event = transformer.nextEvent();
        assertTrue(event.isEndElement());
        assertEquals(event.asEndElement().getName().getLocalPart(), "child");

        // "element" end-tag
        assertTrue(transformer.hasNext());
        event = transformer.nextEvent();
        assertTrue(event.isEndElement());
        assertEquals(event.asEndElement().getName().getLocalPart(), "parent");
    }
View Full Code Here

Examples of org.apache.cocoon.stax.stress.src.EmitElementTransformer

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = new ByteArrayInputStream("<root/>".getBytes());

        Pipeline<StAXPipelineComponent> pipe = new NonCachingPipeline<StAXPipelineComponent>();
        pipe.addComponent(new XMLGenerator(in));
        pipe.addComponent(new EmitElementTransformer("root", new ArrayList<Attribute>(), "element", 5));
        pipe.addComponent(new XMLSerializer());
        pipe.setup(out);
        pipe.execute();

        String created = new String(out.toByteArray());
View Full Code Here

Examples of org.apache.cocoon.stax.stress.src.EmitElementTransformer

        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tmpOutput));
        InputStream in = new ByteArrayInputStream("<root/>".getBytes());

        Pipeline<StAXPipelineComponent> pipe = new NonCachingPipeline<StAXPipelineComponent>();
        pipe.addComponent(new XMLGenerator(in));
        pipe.addComponent(new EmitElementTransformer("root", new ArrayList<Attribute>(), "element", this.TEST_SIZE));
        pipe.addComponent(new XMLSerializer());
        pipe.setup(out);
        pipe.execute();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.