/** * {@inheritDoc} */ public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { // increase element depth depth++; if (builder == null) { builder = builderFactory.createBuilder(localName, uri, extractPrefix(qName), null, null); } else { builder.startInnerElement(localName, uri); } for (int i = 0; i < atts.getLength(); i++) { builder.addAttribute(atts.getURI(i), atts.getLocalName(i), atts.getValue(i)); } if (depth == 1) { // outer stream:stream element, needs to be dispatched right away emitStanza(); } }
public WebSocketBackedSessionContext(ServerRuntimeContext serverRuntimeContext) { super(serverRuntimeContext, new SessionStateHolder()); XMPPContentHandler contentHandler = new XMPPContentHandler(new StanzaBuilderFactory()); contentHandler.setListener(this); try { // we need to check the jabber:client/jabber:server NS declarations xmlReader.setFeature(DefaultNonBlockingXMLReader.FEATURE_NAMESPACE_PREFIXES, true); // allow parser to restart XML stream xmlReader.setFeature(DefaultNonBlockingXMLReader.FEATURE_RESTART_ALLOWED, true); xmlReader.setProperty(DefaultNonBlockingXMLReader.PROPERTY_RESTART_QNAME, "stream:stream"); } catch (SAXException e) { // should never happen throw new RuntimeException(e); } xmlReader.setContentHandler(contentHandler); }
/** * {@inheritDoc} */ public void endElement(String uri, String localName, String qName) throws SAXException { depth--; if (depth == 1) { // complete stanza, emit emitStanza(); } else if (depth == 0) { // end stream:stream element // TODO handle } else { builder.endInnerElement(); } }
reader.setProperty(DefaultNonBlockingXMLReader.PROPERTY_RESTART_QNAME, "stream:stream"); reader.setContentHandler(new XMPPContentHandler(builderFactory)); contentHandler.setListener(new MinaStanzaListener(out));