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.IQ;
021import org.jivesoftware.smack.packet.Stanza;
022
023import java.util.ArrayList;
024import java.util.Collections;
025import java.util.Iterator;
026import java.util.List;
027
028/**
029 * Represents the conversation transcript that occured in a group chat room between an Agent
030 * and a user that requested assistance. The transcript contains all the Messages that were sent
031 * to the room as well as the sent presences. 
032 *
033 * @author Gaston Dombiak
034 */
035public class Transcript extends IQ {
036    private String sessionID;
037    private List<Stanza> packets;
038
039    /**
040     * Creates a transcript request for the given sessionID.
041     *
042     * @param sessionID the id of the session to get the conversation transcript.
043     */
044    public Transcript(String sessionID) {
045        this(sessionID, new ArrayList<Stanza>());
046    }
047
048    /**
049     * Creates a new transcript for the given sessionID and list of packets. The list of packets
050     * may include Messages and/or Presences.
051     *
052     * @param sessionID the id of the session that generated this conversation transcript.
053     * @param packets the list of messages and presences send to the room.
054     */
055    public Transcript(String sessionID, List<Stanza> packets) {
056        super("transcript", "http://jabber.org/protocol/workgroup");
057        this.sessionID = sessionID;
058        this.packets = packets;
059    }
060
061    /**
062     * Returns id of the session that generated this conversation transcript. The sessionID is a
063     * value generated by the server when a new request is received.
064     *
065     * @return id of the session that generated this conversation transcript.
066     */
067    public String getSessionID() {
068        return sessionID;
069    }
070
071    /**
072     * Returns the list of Messages and Presences that were sent to the room.
073     *
074     * @return the list of Messages and Presences that were sent to the room.
075     */
076    public List<Stanza> getPackets() {
077        return Collections.unmodifiableList(packets);
078    }
079
080    @Override
081    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
082        buf.append(" sessionID=\"")
083                .append(sessionID)
084                .append("\">");
085
086        for (Iterator<Stanza> it=packets.iterator(); it.hasNext();) {
087            Stanza packet = it.next();
088            buf.append(packet.toXML());
089        }
090
091        return buf;
092    }
093}