Transcript.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.packet;

  18. import org.jivesoftware.smack.packet.IQ;
  19. import org.jivesoftware.smack.packet.Stanza;

  20. import java.util.ArrayList;
  21. import java.util.Collections;
  22. import java.util.Iterator;
  23. import java.util.List;

  24. /**
  25.  * Represents the conversation transcript that occured in a group chat room between an Agent
  26.  * and a user that requested assistance. The transcript contains all the Messages that were sent
  27.  * to the room as well as the sent presences.
  28.  *
  29.  * @author Gaston Dombiak
  30.  */
  31. public class Transcript extends IQ {
  32.     private String sessionID;
  33.     private List<Stanza> packets;

  34.     /**
  35.      * Creates a transcript request for the given sessionID.
  36.      *
  37.      * @param sessionID the id of the session to get the conversation transcript.
  38.      */
  39.     public Transcript(String sessionID) {
  40.         this(sessionID, new ArrayList<Stanza>());
  41.     }

  42.     /**
  43.      * Creates a new transcript for the given sessionID and list of packets. The list of packets
  44.      * may include Messages and/or Presences.
  45.      *
  46.      * @param sessionID the id of the session that generated this conversation transcript.
  47.      * @param packets the list of messages and presences send to the room.
  48.      */
  49.     public Transcript(String sessionID, List<Stanza> packets) {
  50.         super("transcript", "http://jabber.org/protocol/workgroup");
  51.         this.sessionID = sessionID;
  52.         this.packets = packets;
  53.     }

  54.     /**
  55.      * Returns id of the session that generated this conversation transcript. The sessionID is a
  56.      * value generated by the server when a new request is received.
  57.      *
  58.      * @return id of the session that generated this conversation transcript.
  59.      */
  60.     public String getSessionID() {
  61.         return sessionID;
  62.     }

  63.     /**
  64.      * Returns the list of Messages and Presences that were sent to the room.
  65.      *
  66.      * @return the list of Messages and Presences that were sent to the room.
  67.      */
  68.     public List<Stanza> getPackets() {
  69.         return Collections.unmodifiableList(packets);
  70.     }

  71.     @Override
  72.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  73.         buf.append(" sessionID=\"")
  74.                 .append(sessionID)
  75.                 .append("\">");

  76.         for (Iterator<Stanza> it=packets.iterator(); it.hasNext();) {
  77.             Stanza packet = it.next();
  78.             buf.append(packet.toXML());
  79.         }

  80.         return buf;
  81.     }
  82. }