protected void parseAndProcessStanza(XmlPullParser parser) throws Exception { ParserUtils.assertAtStartTag(parser); int parserDepth = parser.getDepth(); Stanza stanza = null; try { stanza = PacketParserUtils.parseStanza(parser); } catch (Exception e) { CharSequence content = PacketParserUtils.parseContentDepth(parser, parserDepth); UnparsablePacket message = new UnparsablePacket(content, e); ParsingExceptionCallback callback = getParsingExceptionCallback(); if (callback != null) { callback.handleUnparsablePacket(message); } } ParserUtils.assertAtEndTag(parser); if (stanza != null) { processPacket(stanza); } }
/** * Install a parsing exception callback, which will be invoked once an exception is encountered while parsing a * stanza * * @param callback the callback to install */ public void setParsingExceptionCallback(ParsingExceptionCallback callback) { parsingExceptionCallback = callback; }
/** * Get the current active parsing exception callback. * * @return the active exception callback or null if there is none */ public ParsingExceptionCallback getParsingExceptionCallback() { return parsingExceptionCallback; }
/** * Set the default parsing exception callback for all newly created connections * * @param callback * @see ParsingExceptionCallback */ public static void setDefaultParsingExceptionCallback(ParsingExceptionCallback callback) { defaultCallback = callback; }
/** * Returns the default parsing exception callback * * @return the default parsing exception callback * @see ParsingExceptionCallback */ public static ParsingExceptionCallback getDefaultParsingExceptionCallback() { return defaultCallback; }
/** * Install a parsing exception callback, which will be invoked once an * exception is encountered while parsing a stanza * * @param callback * the callback to install */ public void setParsingExceptionCallback(ParsingExceptionCallback callback) { parsingExceptionCallback = callback; }
/** * Set the default parsing exception callback for all newly created * connections * * @param callback * @see ParsingExceptionCallback */ public static void setDefaultParsingExceptionCallback( ParsingExceptionCallback callback) { initialize(); defaultCallback = callback; }
/** * Returns the default parsing exception callback * * @return the default parsing exception callback * @see ParsingExceptionCallback */ public static ParsingExceptionCallback getDefaultParsingExceptionCallback() { initialize(); return defaultCallback; }