/**
* {@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;
}