001/* 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smackx.workgroup.packet; 019 020import java.io.IOException; 021 022import javax.xml.namespace.QName; 023 024import org.jivesoftware.smack.packet.ExtensionElement; 025import org.jivesoftware.smack.packet.XmlEnvironment; 026import org.jivesoftware.smack.provider.ExtensionElementProvider; 027import org.jivesoftware.smack.xml.XmlPullParser; 028import org.jivesoftware.smack.xml.XmlPullParserException; 029 030import org.jxmpp.JxmppContext; 031 032public class SessionID implements ExtensionElement { 033 034 /** 035 * Element name of the stanza extension. 036 */ 037 public static final String ELEMENT_NAME = "session"; 038 039 /** 040 * Namespace of the stanza extension. 041 */ 042 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 043 044 public static final QName QNAME = new QName(NAMESPACE, ELEMENT_NAME); 045 046 private final String sessionID; 047 048 public SessionID(String sessionID) { 049 this.sessionID = sessionID; 050 } 051 052 public String getSessionID() { 053 return this.sessionID; 054 } 055 056 @Override 057 public String getElementName() { 058 return ELEMENT_NAME; 059 } 060 061 @Override 062 public String getNamespace() { 063 return NAMESPACE; 064 } 065 066 @Override 067 public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 068 StringBuilder buf = new StringBuilder(); 069 070 buf.append('<').append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" "); 071 buf.append("id=\"").append(this.getSessionID()); 072 buf.append("\"/>"); 073 074 return buf.toString(); 075 } 076 077 public static class Provider extends ExtensionElementProvider<SessionID> { 078 079 @Override 080 public SessionID parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment, JxmppContext jxmppContext) 081 throws XmlPullParserException, IOException { 082 String sessionID = parser.getAttributeValue("", "id"); 083 084 // Advance to end of extension. 085 parser.next(); 086 087 return new SessionID(sessionID); 088 } 089 } 090}