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 javax.xml.namespace.QName;

  20. import org.jivesoftware.smack.packet.ExtensionElement;
  21. import org.jivesoftware.smack.packet.XmlEnvironment;
  22. import org.jivesoftware.smack.provider.ExtensionElementProvider;
  23. import org.jivesoftware.smack.util.ParserUtils;
  24. import org.jivesoftware.smack.xml.XmlPullParser;
  25. import org.jivesoftware.smack.xml.XmlPullParserException;

  26. import org.jxmpp.jid.EntityBareJid;

  27. /**
  28.  * A stanza extension that contains information about the user and agent in a
  29.  * workgroup chat. The stanza extension is attached to group chat invitations.
  30.  */
  31. public class WorkgroupInformation implements ExtensionElement {

  32.     /**
  33.      * Element name of the stanza extension.
  34.      */
  35.     public static final String ELEMENT_NAME = "workgroup";

  36.     /**
  37.      * Namespace of the stanza extension.
  38.      */
  39.     public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";

  40.     public static final QName QNAME = new QName(NAMESPACE, ELEMENT_NAME);

  41.     private final EntityBareJid workgroupJID;

  42.     public WorkgroupInformation(EntityBareJid workgroupJID) {
  43.         this.workgroupJID = workgroupJID;
  44.     }

  45.     public EntityBareJid getWorkgroupJID() {
  46.         return workgroupJID;
  47.     }

  48.     @Override
  49.     public String getElementName() {
  50.         return ELEMENT_NAME;
  51.     }

  52.     @Override
  53.     public String getNamespace() {
  54.         return NAMESPACE;
  55.     }

  56.     @Override
  57.     public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  58.         StringBuilder buf = new StringBuilder();

  59.         buf.append('<').append(ELEMENT_NAME);
  60.         buf.append(" jid=\"").append(getWorkgroupJID()).append('"');
  61.         buf.append(" xmlns=\"").append(NAMESPACE).append("\" />");

  62.         return buf.toString();
  63.     }

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

  65.         /**
  66.          * PacketExtensionProvider implementation.
  67.          * @throws IOException if an I/O error occurred.
  68.          * @throws XmlPullParserException if an error in the XML parser occurred.
  69.          */
  70.         @Override
  71.         public WorkgroupInformation parse(XmlPullParser parser,
  72.                         int initialDepth, XmlEnvironment xmlEnvironment) throws XmlPullParserException,
  73.                         IOException {
  74.             EntityBareJid workgroupJID = ParserUtils.getBareJidAttribute(parser);

  75.             // since this is a start and end tag, and we arrive on the start, this should guarantee
  76.             //      we leave on the end
  77.             parser.next();

  78.             return new WorkgroupInformation(workgroupJID);
  79.         }
  80.     }
  81. }