001/** 002 * 003 * Copyright 2003-2006 Jive Software. 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 */ 017 018package org.jivesoftware.smackx.address.provider; 019 020import java.io.IOException; 021 022import org.jivesoftware.smack.provider.ExtensionElementProvider; 023import org.jivesoftware.smack.util.ParserUtils; 024import org.jivesoftware.smackx.address.packet.MultipleAddresses; 025import org.jivesoftware.smackx.address.packet.MultipleAddresses.Type; 026import org.jxmpp.jid.Jid; 027import org.xmlpull.v1.XmlPullParser; 028import org.xmlpull.v1.XmlPullParserException; 029 030/** 031 * The MultipleAddressesProvider parses {@link MultipleAddresses} packets. 032 * 033 * @author Gaston Dombiak 034 */ 035public class MultipleAddressesProvider extends ExtensionElementProvider<MultipleAddresses> { 036 037 @Override 038 public MultipleAddresses parse(XmlPullParser parser, 039 int initialDepth) throws XmlPullParserException, 040 IOException { 041 MultipleAddresses multipleAddresses = new MultipleAddresses(); 042 outerloop: while (true) { 043 int eventType = parser.next(); 044 switch (eventType) { 045 case XmlPullParser.START_TAG: 046 String name = parser.getName(); 047 switch (name) { 048 case MultipleAddresses.Address.ELEMENT: 049 String typeString = parser.getAttributeValue("", "type"); 050 Type type = Type.valueOf(typeString); 051 Jid jid = ParserUtils.getJidAttribute(parser, "jid"); 052 String node = parser.getAttributeValue("", "node"); 053 String desc = parser.getAttributeValue("", "desc"); 054 boolean delivered = "true".equals(parser.getAttributeValue("", "delivered")); 055 String uri = parser.getAttributeValue("", "uri"); 056 // Add the parsed address 057 multipleAddresses.addAddress(type, jid, node, desc, delivered, uri); 058 break; 059 } 060 break; 061 case XmlPullParser.END_TAG: 062 if (parser.getDepth() == initialDepth) { 063 break outerloop; 064 } 065 break; 066 } 067 } 068 return multipleAddresses; 069 } 070}