use of org.xmlpull.v1.XmlPullParser in project Openfire by igniterealtime.
the class BlockingReadingMode method tlsNegotiated.
@Override
protected void tlsNegotiated() throws XmlPullParserException, IOException {
XmlPullParser xpp = socketReader.reader.getXPPParser();
// Reset the parser to use the new reader
xpp.setInput(new InputStreamReader(socketReader.connection.getTLSStreamHandler().getInputStream(), CHARSET));
// Skip new stream element
for (int eventType = xpp.getEventType(); eventType != XmlPullParser.START_TAG; ) {
eventType = xpp.next();
}
super.tlsNegotiated();
}
use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.
the class JivePropertiesExtensionProvider method parse.
/**
* Parse a properties sub-packet. If any errors occur while de-serializing Java object
* properties, an exception will be printed and not thrown since a thrown exception will shut
* down the entire connection. ClassCastExceptions will occur when both the sender and receiver
* of the stanza(/packet) don't have identical versions of the same class.
* <p>
* Note that you have to explicitly enabled Java object deserialization with @{link
* {@link JivePropertiesManager#setJavaObjectEnabled(boolean)}
*
* @param parser the XML parser, positioned at the start of a properties sub-packet.
* @return a map of the properties.
* @throws IOException
* @throws XmlPullParserException
*/
@Override
public JivePropertiesExtension parse(XmlPullParser parser, int initialDepth) throws XmlPullParserException, IOException {
Map<String, Object> properties = new HashMap<String, Object>();
while (true) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG && parser.getName().equals("property")) {
// Parse a property
boolean done = false;
String name = null;
String type = null;
String valueText = null;
Object value = null;
while (!done) {
eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
String elementName = parser.getName();
if (elementName.equals("name")) {
name = parser.nextText();
} else if (elementName.equals("value")) {
type = parser.getAttributeValue("", "type");
valueText = parser.nextText();
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals("property")) {
if ("integer".equals(type)) {
value = Integer.valueOf(valueText);
} else if ("long".equals(type)) {
value = Long.valueOf(valueText);
} else if ("float".equals(type)) {
value = Float.valueOf(valueText);
} else if ("double".equals(type)) {
value = Double.valueOf(valueText);
} else if ("boolean".equals(type)) {
value = Boolean.valueOf(valueText);
} else if ("string".equals(type)) {
value = valueText;
} else if ("java-object".equals(type)) {
if (JivePropertiesManager.isJavaObjectEnabled()) {
try {
byte[] bytes = Base64.decode(valueText);
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
value = in.readObject();
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error parsing java object", e);
}
} else {
LOGGER.severe("JavaObject is not enabled. Enable with JivePropertiesManager.setJavaObjectEnabled(true)");
}
}
if (name != null && value != null) {
properties.put(name, value);
}
done = true;
}
}
}
} else if (eventType == XmlPullParser.END_TAG) {
if (parser.getName().equals(JivePropertiesExtension.ELEMENT)) {
break;
}
}
}
return new JivePropertiesExtension(properties);
}
use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.
the class PacketParserUtils method getParserFor.
public static XmlPullParser getParserFor(Reader reader) throws XmlPullParserException, IOException {
XmlPullParser parser = newXmppParser(reader);
// Wind the parser forward to the first start tag
int event = parser.getEventType();
while (event != XmlPullParser.START_TAG) {
if (event == XmlPullParser.END_DOCUMENT) {
throw new IllegalArgumentException("Document contains no start tag");
}
event = parser.next();
}
return parser;
}
use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.
the class PacketParserUtils method newXmppParser.
/**
* Creates a new XmlPullParser suitable for parsing XMPP. This means in particular that
* FEATURE_PROCESS_NAMESPACES is enabled.
* <p>
* Note that not all XmlPullParser implementations will return a String on
* <code>getText()</code> if the parser is on START_TAG or END_TAG. So you must not rely on this
* behavior when using the parser.
* </p>
*
* @param reader
* @return A suitable XmlPullParser for XMPP parsing
* @throws XmlPullParserException
*/
public static XmlPullParser newXmppParser(Reader reader) throws XmlPullParserException {
XmlPullParser parser = newXmppParser();
parser.setInput(reader);
return parser;
}
use of org.xmlpull.v1.XmlPullParser in project Smack by igniterealtime.
the class PacketParserUtils method getParserFor.
public static XmlPullParser getParserFor(String stanza, String startTag) throws XmlPullParserException, IOException {
XmlPullParser parser = getParserFor(stanza);
while (true) {
int event = parser.getEventType();
String name = parser.getName();
if (event == XmlPullParser.START_TAG && name.equals(startTag)) {
break;
} else if (event == XmlPullParser.END_DOCUMENT) {
throw new IllegalArgumentException("Could not find start tag '" + startTag + "' in stanza: " + stanza);
}
parser.next();
}
return parser;
}
Aggregations