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