UserID.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.Jid;

  27. public class UserID implements ExtensionElement {

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

  32.     /**
  33.      * Namespace of the stanza extension.
  34.      */
  35.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

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

  37.     private final Jid userID;

  38.     public UserID(Jid userID) {
  39.         this.userID = userID;
  40.     }

  41.     public Jid getUserID() {
  42.         return this.userID;
  43.     }

  44.     @Override
  45.     public String getElementName() {
  46.         return ELEMENT_NAME;
  47.     }

  48.     @Override
  49.     public String getNamespace() {
  50.         return NAMESPACE;
  51.     }

  52.     @Override
  53.     public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  54.         StringBuilder buf = new StringBuilder();

  55.         buf.append('<').append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" ");
  56.         buf.append("id=\"").append(this.getUserID());
  57.         buf.append("\"/>");

  58.         return buf.toString();
  59.     }

  60.     public static class Provider extends ExtensionElementProvider<UserID> {

  61.         @Override
  62.         public UserID parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment)
  63.                         throws XmlPullParserException, IOException {
  64.             Jid userID = ParserUtils.getJidAttribute(parser, "id");

  65.             // Advance to end of extension.
  66.             parser.next();

  67.             return new UserID(userID);
  68.         }
  69.     }
  70. }