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 org.jivesoftware.smack.packet.PacketExtension; 021import org.jivesoftware.smack.provider.PacketExtensionProvider; 022import org.jivesoftware.smackx.address.packet.MultipleAddresses; 023import org.xmlpull.v1.XmlPullParser; 024 025/** 026 * The MultipleAddressesProvider parses {@link MultipleAddresses} packets. 027 * 028 * @author Gaston Dombiak 029 */ 030public class MultipleAddressesProvider implements PacketExtensionProvider { 031 032 /** 033 * Creates a new MultipleAddressesProvider. 034 * ProviderManager requires that every PacketExtensionProvider has a public, no-argument 035 * constructor. 036 */ 037 public MultipleAddressesProvider() { 038 } 039 040 public PacketExtension parseExtension(XmlPullParser parser) throws Exception { 041 boolean done = false; 042 MultipleAddresses multipleAddresses = new MultipleAddresses(); 043 while (!done) { 044 int eventType = parser.next(); 045 if (eventType == XmlPullParser.START_TAG) { 046 if (parser.getName().equals("address")) { 047 String type = parser.getAttributeValue("", "type"); 048 String jid = parser.getAttributeValue("", "jid"); 049 String node = parser.getAttributeValue("", "node"); 050 String desc = parser.getAttributeValue("", "desc"); 051 boolean delivered = "true".equals(parser.getAttributeValue("", "delivered")); 052 String uri = parser.getAttributeValue("", "uri"); 053 // Add the parsed address 054 multipleAddresses.addAddress(type, jid, node, desc, delivered, uri); 055 } 056 } else if (eventType == XmlPullParser.END_TAG) { 057 if (parser.getName().equals(multipleAddresses.getElementName())) { 058 done = true; 059 } 060 } 061 } 062 return multipleAddresses; 063 } 064}