Search in sources :

Example 1 with Mood

use of org.jivesoftware.smackx.mood.Mood in project Smack by igniterealtime.

the class MoodProvider method parse.

@Override
public MoodElement parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException, SmackParsingException {
    String text = null;
    Mood mood = null;
    MoodConcretisation concretisation = null;
    outerloop: while (true) {
        XmlPullParser.Event tag = parser.next();
        switch(tag) {
            case START_ELEMENT:
                String name = parser.getName();
                String namespace = parser.getNamespace();
                if (MoodElement.ELEM_TEXT.equals(name)) {
                    text = parser.nextText();
                    continue outerloop;
                }
                if (!MoodElement.NAMESPACE.equals(namespace)) {
                    LOGGER.log(Level.FINE, "Foreign namespace " + namespace + " detected. Try to find suitable MoodConcretisationProvider.");
                    MoodConcretisationProvider<?> provider = (MoodConcretisationProvider<?>) ProviderManager.getExtensionProvider(name, namespace);
                    if (provider != null) {
                        concretisation = provider.parse(parser);
                    } else {
                        LOGGER.log(Level.FINE, "No provider for <" + name + " xmlns:'" + namespace + "'/> found. Ignore.");
                    }
                    continue outerloop;
                }
                try {
                    mood = Mood.valueOf(name);
                    continue outerloop;
                } catch (IllegalArgumentException e) {
                    throw new XmlPullParserException("Unknown mood value: " + name + " encountered.");
                }
            case END_ELEMENT:
                if (MoodElement.ELEMENT.equals(parser.getName())) {
                    MoodElement.MoodSubjectElement subjectElement = (mood == null && concretisation == null) ? null : new MoodElement.MoodSubjectElement(mood, concretisation);
                    return new MoodElement(subjectElement, text);
                }
                break;
            default:
                // Catch all for incomplete switch (MissingCasesInEnumSwitch) statement.
                break;
        }
    }
}
Also used : Mood(org.jivesoftware.smackx.mood.Mood) MoodConcretisation(org.jivesoftware.smackx.mood.element.MoodConcretisation) XmlPullParserException(org.jivesoftware.smack.xml.XmlPullParserException) MoodElement(org.jivesoftware.smackx.mood.element.MoodElement)

Aggregations

XmlPullParserException (org.jivesoftware.smack.xml.XmlPullParserException)1 Mood (org.jivesoftware.smackx.mood.Mood)1 MoodConcretisation (org.jivesoftware.smackx.mood.element.MoodConcretisation)1 MoodElement (org.jivesoftware.smackx.mood.element.MoodElement)1