WorkgroupInformation.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.packet;

  18. import java.io.IOException;

  19. import org.jivesoftware.smack.packet.ExtensionElement;
  20. import org.jivesoftware.smack.provider.ExtensionElementProvider;
  21. import org.xmlpull.v1.XmlPullParser;
  22. import org.xmlpull.v1.XmlPullParserException;

  23. /**
  24.  * A packet extension that contains information about the user and agent in a
  25.  * workgroup chat. The packet extension is attached to group chat invitations.
  26.  */
  27. public class WorkgroupInformation implements ExtensionElement {

  28.     /**
  29.      * Element name of the packet extension.
  30.      */
  31.     public static final String ELEMENT_NAME = "workgroup";

  32.     /**
  33.      * Namespace of the packet extension.
  34.      */
  35.     public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";

  36.     private String workgroupJID;

  37.     public WorkgroupInformation(String workgroupJID){
  38.         this.workgroupJID = workgroupJID;
  39.     }

  40.     public String getWorkgroupJID() {
  41.         return workgroupJID;
  42.     }

  43.     public String getElementName() {
  44.         return ELEMENT_NAME;
  45.     }

  46.     public String getNamespace() {
  47.         return NAMESPACE;
  48.     }

  49.     public String toXML() {
  50.         StringBuilder buf = new StringBuilder();

  51.         buf.append('<').append(ELEMENT_NAME);
  52.         buf.append(" jid=\"").append(getWorkgroupJID()).append("\"");
  53.         buf.append(" xmlns=\"").append(NAMESPACE).append("\" />");

  54.         return buf.toString();
  55.     }

  56.     public static class Provider extends ExtensionElementProvider<WorkgroupInformation> {

  57.         /**
  58.          * PacketExtensionProvider implementation
  59.          * @throws IOException
  60.          * @throws XmlPullParserException
  61.          */
  62.         @Override
  63.         public WorkgroupInformation parse(XmlPullParser parser,
  64.                         int initialDepth) throws XmlPullParserException,
  65.                         IOException {
  66.             String workgroupJID = parser.getAttributeValue("", "jid");

  67.             // since this is a start and end tag, and we arrive on the start, this should guarantee
  68.             //      we leave on the end
  69.             parser.next();

  70.             return new WorkgroupInformation(workgroupJID);
  71.         }
  72.     }
  73. }