001/* 002 * 003 * Copyright 2003-2007 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.workgroup.packet; 019 020import java.io.IOException; 021 022import javax.xml.namespace.QName; 023 024import org.jivesoftware.smack.packet.ExtensionElement; 025import org.jivesoftware.smack.packet.XmlEnvironment; 026import org.jivesoftware.smack.provider.ExtensionElementProvider; 027import org.jivesoftware.smack.util.ParserUtils; 028import org.jivesoftware.smack.xml.XmlPullParser; 029import org.jivesoftware.smack.xml.XmlPullParserException; 030 031import org.jxmpp.JxmppContext; 032import org.jxmpp.jid.Jid; 033 034public class UserID implements ExtensionElement { 035 036 /** 037 * Element name of the stanza extension. 038 */ 039 public static final String ELEMENT_NAME = "user"; 040 041 /** 042 * Namespace of the stanza extension. 043 */ 044 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 045 046 public static final QName QNAME = new QName(NAMESPACE, ELEMENT_NAME); 047 048 private final Jid userID; 049 050 public UserID(Jid userID) { 051 this.userID = userID; 052 } 053 054 public Jid getUserID() { 055 return this.userID; 056 } 057 058 @Override 059 public String getElementName() { 060 return ELEMENT_NAME; 061 } 062 063 @Override 064 public String getNamespace() { 065 return NAMESPACE; 066 } 067 068 @Override 069 public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 070 StringBuilder buf = new StringBuilder(); 071 072 buf.append('<').append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" "); 073 buf.append("id=\"").append(this.getUserID()); 074 buf.append("\"/>"); 075 076 return buf.toString(); 077 } 078 079 public static class Provider extends ExtensionElementProvider<UserID> { 080 081 @Override 082 public UserID parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment, JxmppContext jxmppContext) 083 throws XmlPullParserException, IOException { 084 Jid userID = ParserUtils.getJidAttribute(parser, "id", jxmppContext); 085 086 // Advance to end of extension. 087 parser.next(); 088 089 return new UserID(userID); 090 } 091 } 092}