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 030public class SessionID implements ExtensionElement { 031 032 /** 033 * Element name of the stanza extension. 034 */ 035 public static final String ELEMENT_NAME = "session"; 036 037 /** 038 * Namespace of the stanza extension. 039 */ 040 public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup"; 041 042 public static final QName QNAME = new QName(NAMESPACE, ELEMENT_NAME); 043 044 private final String sessionID; 045 046 public SessionID(String sessionID) { 047 this.sessionID = sessionID; 048 } 049 050 public String getSessionID() { 051 return this.sessionID; 052 } 053 054 @Override 055 public String getElementName() { 056 return ELEMENT_NAME; 057 } 058 059 @Override 060 public String getNamespace() { 061 return NAMESPACE; 062 } 063 064 @Override 065 public String toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 066 StringBuilder buf = new StringBuilder(); 067 068 buf.append('<').append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" "); 069 buf.append("id=\"").append(this.getSessionID()); 070 buf.append("\"/>"); 071 072 return buf.toString(); 073 } 074 075 public static class Provider extends ExtensionElementProvider<SessionID> { 076 077 @Override 078 public SessionID parse(XmlPullParser parser, int initialDepth, XmlEnvironment xmlEnvironment) 079 throws XmlPullParserException, IOException { 080 String sessionID = parser.getAttributeValue("", "id"); 081 082 // Advance to end of extension. 083 parser.next(); 084 085 return new SessionID(sessionID); 086 } 087 } 088}