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 java.util.ArrayList;
  19. import java.util.Collections;
  20. import java.util.List;

  21. import org.jivesoftware.smack.packet.IQ;
  22. import org.jivesoftware.smack.packet.Stanza;

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

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

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

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

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

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

  75.         for (Stanza packet : packets) {
  76.             buf.append(packet.toXML());
  77.         }

  78.         return buf;
  79.     }
  80. }