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.jid.EntityBareJid; 032 033/** 034 * A stanza extension that contains information about the user and agent in a 035 * workgroup chat. The stanza extension is attached to group chat invitations. 036 */ 037public class WorkgroupInformation implements ExtensionElement { 038 039 /** 040 * Element name of the stanza extension. 041 */ 042 public static final String ELEMENT_NAME = "workgroup"; 043 044 /** 045 * Namespace of the stanza extension. 046 */ 047 public static final String NAMESPACE = "http://jabber.org/protocol/workgroup"; 048 049 public static final QName QNAME = new QName(NAMESPACE, ELEMENT_NAME); 050 051 private final EntityBareJid workgroupJID; 052 053 public WorkgroupInformation(EntityBareJid workgroupJID) { 054 this.workgroupJID = workgroupJID; 055 } 056 057 public EntityBareJid getWorkgroupJID() { 058 return workgroupJID; 059 } 060 061 @Override 062 public String getElementName() { 063 return ELEMENT_NAME; 064 } 065 066 @Override 067 public String getNamespace() { 068 return NAMESPACE; 069 } 070 071 @Override 072 public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 073 StringBuilder buf = new StringBuilder(); 074 075 buf.append('<').append(ELEMENT_NAME); 076 buf.append(" jid=\"").append(getWorkgroupJID()).append('"'); 077 buf.append(" xmlns=\"").append(NAMESPACE).append("\" />"); 078 079 return buf.toString(); 080 } 081 082 public static class Provider extends ExtensionElementProvider<WorkgroupInformation> { 083 084 /** 085 * PacketExtensionProvider implementation. 086 * @throws IOException if an I/O error occurred. 087 * @throws XmlPullParserException if an error in the XML parser occurred. 088 */ 089 @Override 090 public WorkgroupInformation parse(XmlPullParser parser, 091 int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException, 092 IOException { 093 EntityBareJid workgroupJID = ParserUtils.getBareJidAttribute(parser); 094 095 // since this is a start and end tag, and we arrive on the start, this should guarantee 096 // we leave on the end 097 parser.next(); 098 099 return new WorkgroupInformation(workgroupJID); 100 } 101 } 102}