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 org.jivesoftware.smack.packet.PacketExtension;
021import org.jivesoftware.smack.provider.PacketExtensionProvider;
022import org.xmlpull.v1.XmlPullParser;
023
024/**
025 * A packet extension that contains information about the user and agent in a
026 * workgroup chat. The packet extension is attached to group chat invitations.
027 */
028public class WorkgroupInformation implements PacketExtension {
029
030    /**
031     * Element name of the packet extension.
032     */
033    public static final String ELEMENT_NAME = "workgroup";
034
035    /**
036     * Namespace of the packet extension.
037     */
038    public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
039
040    private String workgroupJID;
041
042    public WorkgroupInformation(String workgroupJID){
043        this.workgroupJID = workgroupJID;
044    }
045
046    public String getWorkgroupJID() {
047        return workgroupJID;
048    }
049
050    public String getElementName() {
051        return ELEMENT_NAME;
052    }
053
054    public String getNamespace() {
055        return NAMESPACE;
056    }
057
058    public String toXML() {
059        StringBuilder buf = new StringBuilder();
060
061        buf.append('<').append(ELEMENT_NAME);
062        buf.append(" jid=\"").append(getWorkgroupJID()).append("\"");
063        buf.append(" xmlns=\"").append(NAMESPACE).append("\" />");
064
065        return buf.toString();
066    }
067
068    public static class Provider implements PacketExtensionProvider {
069
070        /**
071         * PacketExtensionProvider implementation
072         */
073        public PacketExtension parseExtension (XmlPullParser parser)
074            throws Exception {
075            String workgroupJID = parser.getAttributeValue("", "jid");
076
077            // since this is a start and end tag, and we arrive on the start, this should guarantee
078            //      we leave on the end
079            parser.next();
080
081            return new WorkgroupInformation(workgroupJID);
082        }
083    }
084}