SessionID.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. public class SessionID implements ExtensionElement {

  24.     /**
  25.      * Element name of the packet extension.
  26.      */
  27.     public static final String ELEMENT_NAME = "session";

  28.     /**
  29.      * Namespace of the packet extension.
  30.      */
  31.     public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";

  32.     private String sessionID;

  33.     public SessionID(String sessionID) {
  34.         this.sessionID = sessionID;
  35.     }

  36.     public String getSessionID() {
  37.         return this.sessionID;
  38.     }

  39.     public String getElementName() {
  40.         return ELEMENT_NAME;
  41.     }

  42.     public String getNamespace() {
  43.         return NAMESPACE;
  44.     }

  45.     public String toXML() {
  46.         StringBuilder buf = new StringBuilder();

  47.         buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" ");
  48.         buf.append("id=\"").append(this.getSessionID());
  49.         buf.append("\"/>");

  50.         return buf.toString();
  51.     }

  52.     public static class Provider extends ExtensionElementProvider<SessionID> {

  53.         @Override
  54.         public SessionID parse(XmlPullParser parser, int initialDepth)
  55.                         throws XmlPullParserException, IOException {
  56.             String sessionID = parser.getAttributeValue("", "id");

  57.             // Advance to end of extension.
  58.             parser.next();

  59.             return new SessionID(sessionID);
  60.         }
  61.     }
  62. }