Home | History | Annotate | Download | only in packet
      1 /**
      2  * $Revision$
      3  * $Date$
      4  *
      5  * Copyright 2003-2007 Jive Software.
      6  *
      7  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *     http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  */
     19 
     20 package org.jivesoftware.smackx.workgroup.packet;
     21 
     22 import org.jivesoftware.smack.packet.PacketExtension;
     23 import org.jivesoftware.smack.provider.PacketExtensionProvider;
     24 import org.xmlpull.v1.XmlPullParser;
     25 
     26 /**
     27  * A packet extension that contains information about the user and agent in a
     28  * workgroup chat. The packet extension is attached to group chat invitations.
     29  */
     30 public class WorkgroupInformation implements PacketExtension {
     31 
     32     /**
     33      * Element name of the packet extension.
     34      */
     35     public static final String ELEMENT_NAME = "workgroup";
     36 
     37     /**
     38      * Namespace of the packet extension.
     39      */
     40     public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
     41 
     42     private String workgroupJID;
     43 
     44     public WorkgroupInformation(String workgroupJID){
     45         this.workgroupJID = workgroupJID;
     46     }
     47 
     48     public String getWorkgroupJID() {
     49         return workgroupJID;
     50     }
     51 
     52     public String getElementName() {
     53         return ELEMENT_NAME;
     54     }
     55 
     56     public String getNamespace() {
     57         return NAMESPACE;
     58     }
     59 
     60     public String toXML() {
     61         StringBuilder buf = new StringBuilder();
     62 
     63         buf.append('<').append(ELEMENT_NAME);
     64         buf.append(" jid=\"").append(getWorkgroupJID()).append("\"");
     65         buf.append(" xmlns=\"").append(NAMESPACE).append("\" />");
     66 
     67         return buf.toString();
     68     }
     69 
     70     public static class Provider implements PacketExtensionProvider {
     71 
     72         /**
     73          * PacketExtensionProvider implementation
     74          */
     75         public PacketExtension parseExtension (XmlPullParser parser)
     76             throws Exception {
     77             String workgroupJID = parser.getAttributeValue("", "jid");
     78 
     79             // since this is a start and end tag, and we arrive on the start, this should guarantee
     80             //      we leave on the end
     81             parser.next();
     82 
     83             return new WorkgroupInformation(workgroupJID);
     84         }
     85     }
     86 }