001/** 002 * 003 * Copyright 2019 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jivesoftware.smack.provider; 018 019import java.io.IOException; 020import java.util.Map; 021 022import org.jivesoftware.smack.packet.XmlEnvironment; 023import org.jivesoftware.smack.sasl.packet.SaslNonza.SASLFailure; 024import org.jivesoftware.smack.util.PacketParserUtils; 025import org.jivesoftware.smack.xml.XmlPullParser; 026import org.jivesoftware.smack.xml.XmlPullParserException; 027 028public final class SaslFailureProvider extends NonzaProvider<SASLFailure> { 029 030 public static final SaslFailureProvider INSTANCE = new SaslFailureProvider(); 031 032 private SaslFailureProvider() { 033 } 034 035 @Override 036 public SASLFailure parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, IOException { 037 String condition = null; 038 Map<String, String> descriptiveTexts = null; 039 outerloop: while (true) { 040 XmlPullParser.TagEvent eventType = parser.nextTag(); 041 switch (eventType) { 042 case START_ELEMENT: 043 String name = parser.getName(); 044 if (name.equals("text")) { 045 descriptiveTexts = PacketParserUtils.parseDescriptiveTexts(parser, descriptiveTexts); 046 } 047 else { 048 assert condition == null; 049 condition = parser.getName(); 050 } 051 break; 052 case END_ELEMENT: 053 if (parser.getDepth() == initialDepth) { 054 break outerloop; 055 } 056 break; 057 } 058 } 059 return new SASLFailure(condition, descriptiveTexts); 060 } 061 062}