Package org.apache.vysper.xml.sax

Examples of org.apache.vysper.xml.sax.NonBlockingXMLReader


            elements.add(element);
        }
    }

    public void test() throws Exception {
        NonBlockingXMLReader reader = new DefaultNonBlockingXMLReader();
        XMPPContentHandler handler = new XMPPContentHandler();
        TestListener listener = new TestListener();
        handler.setListener(listener);

        reader.setContentHandler(handler);

        parse(reader, "<stanza:stanza xmlns:stanza='http://etherx.jabber.org/streams'>");
        parse(reader, "<message></message>");
        parse(reader, "<iq>");
        parse(reader, "</iq>");
View Full Code Here


*/
public class DefaultAsyncXMLReaderTestCase extends AbstractAsyncXMLReaderTestCase {

    public void testParseAfterFatalError() throws Exception {
        TestHandler handler = new TestHandler();
        NonBlockingXMLReader reader = new DefaultNonBlockingXMLReader();
        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);

        // causes a fatal error
        reader.parse(IoBuffer.wrap("<root></error>".getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);

        try {
            // not allowed to parse after an error
            reader.parse(IoBuffer.wrap("<root>".getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);
            fail("Must throw SAXException");
        } catch (SAXException e) {
            // OK
        }
    }
View Full Code Here

        }
    }

    public void testParseAfterEndDocument() throws Exception {
        TestHandler handler = new TestHandler();
        NonBlockingXMLReader reader = new DefaultNonBlockingXMLReader();
        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);

        // causes a fatal error
        reader.parse(IoBuffer.wrap("<root></root>".getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);

        try {
            // not allowed to parse after end of document
            reader.parse(IoBuffer.wrap("<root>".getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);
            fail("Must throw SAXException");
        } catch (SAXException e) {
            // OK
        }
    }
View Full Code Here

    }

    protected List<TestEvent> parse(String xml, Map<String, Boolean> features, Map<String, Object> properties)
            throws Exception {
        TestHandler handler = new TestHandler();
        NonBlockingXMLReader reader = new DefaultNonBlockingXMLReader();
        if (features != null) {
            for (Entry<String, Boolean> feature : features.entrySet()) {
                reader.setFeature(feature.getKey(), feature.getValue());
            }
        }
        if (properties != null) {
            for (Entry<String, Object> property : properties.entrySet()) {
                reader.setProperty(property.getKey(), property.getValue());
            }
        }

        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);

        reader.parse(IoBuffer.wrap(xml.getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);

        return handler.getEvents();
    }
View Full Code Here

        assertNoMoreevents(events);
    }
   
    public void testSplitBuffers() throws Exception {
        TestHandler handler = new TestHandler();
        NonBlockingXMLReader reader = new DefaultNonBlockingXMLReader();

        reader.setContentHandler(handler);
        reader.setErrorHandler(handler);

        String xml1 = "<root></r";
        String xml2 = "oot>";
       
        reader.parse(IoBuffer.wrap(xml1.getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);
        reader.parse(IoBuffer.wrap(xml2.getBytes("UTF-8")), CharsetUtil.UTF8_DECODER);

        Iterator<TestEvent> events = handler.getEvents().iterator();
        assertStartDocument(events.next());
        assertStartElement("", "root", "root", events.next());
View Full Code Here

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
        NonBlockingXMLReader reader = (NonBlockingXMLReader) session.getAttribute(SESSION_ATTRIBUTE_NAME);

        if (reader == null) {
            reader = new DefaultNonBlockingXMLReader();

            // we need to check the jabber:client/jabber:server NS declarations
            reader.setFeature(DefaultNonBlockingXMLReader.FEATURE_NAMESPACE_PREFIXES, true);

            // allow parser to restart XML stream
            reader.setFeature(DefaultNonBlockingXMLReader.FEATURE_RESTART_ALLOWED, true);
            reader.setProperty(DefaultNonBlockingXMLReader.PROPERTY_RESTART_QNAME, "stream:stream");

            reader.setContentHandler(new XMPPContentHandler(builderFactory));

            session.setAttribute(SESSION_ATTRIBUTE_NAME, reader);
        }

        XMPPContentHandler contentHandler = (XMPPContentHandler) reader.getContentHandler();
        contentHandler.setListener(new MinaStanzaListener(out));

        reader.parse(in, CharsetUtil.UTF8_DECODER);

        // we have parsed what we got, invoke again when more data is available
        return false;
    }
View Full Code Here

TOP

Related Classes of org.apache.vysper.xml.sax.NonBlockingXMLReader

Copyright © 2018 www.massapicom. 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.