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