Search in sources :

Example 96 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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();
}
Also used : InputStreamReader(java.io.InputStreamReader) XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 97 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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);
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) JivePropertiesExtension(org.jivesoftware.smackx.jiveproperties.packet.JivePropertiesExtension) ObjectInputStream(java.io.ObjectInputStream)

Example 98 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 99 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Example 100 with XmlPullParserException

use of org.xmlpull.v1.XmlPullParserException 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;
}
Also used : XmlPullParser(org.xmlpull.v1.XmlPullParser)

Aggregations

XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1062 IOException (java.io.IOException)630 XmlPullParser (org.xmlpull.v1.XmlPullParser)437 FileNotFoundException (java.io.FileNotFoundException)187 XmlResourceParser (android.content.res.XmlResourceParser)185 FileInputStream (java.io.FileInputStream)182 AttributeSet (android.util.AttributeSet)159 TypedArray (android.content.res.TypedArray)156 Resources (android.content.res.Resources)101 File (java.io.File)101 ArrayList (java.util.ArrayList)97 PackageManager (android.content.pm.PackageManager)62 ComponentName (android.content.ComponentName)57 InputStream (java.io.InputStream)56 HashMap (java.util.HashMap)56 Intent (android.content.Intent)54 XmlSerializer (org.xmlpull.v1.XmlSerializer)52 AtomicFile (android.util.AtomicFile)50 BufferedInputStream (java.io.BufferedInputStream)44 TypedValue (android.util.TypedValue)43