Home | History | Annotate | Download | only in packet
      1 /**
      2  * $Revision$
      3  * $Date$
      4  *
      5  * Copyright 2003-2007 Jive Software.
      6  *
      7  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      8  * you may not use this file except in compliance with the License.
      9  * You may obtain a copy of the License at
     10  *
     11  *     http://www.apache.org/licenses/LICENSE-2.0
     12  *
     13  * Unless required by applicable law or agreed to in writing, software
     14  * distributed under the License is distributed on an "AS IS" BASIS,
     15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16  * See the License for the specific language governing permissions and
     17  * limitations under the License.
     18  */
     19 
     20 package org.jivesoftware.smackx.workgroup.packet;
     21 
     22 import org.jivesoftware.smack.packet.IQ;
     23 import org.jivesoftware.smack.packet.Packet;
     24 
     25 import java.util.ArrayList;
     26 import java.util.Collections;
     27 import java.util.Iterator;
     28 import java.util.List;
     29 
     30 /**
     31  * Represents the conversation transcript that occured in a group chat room between an Agent
     32  * and a user that requested assistance. The transcript contains all the Messages that were sent
     33  * to the room as well as the sent presences.
     34  *
     35  * @author Gaston Dombiak
     36  */
     37 public class Transcript extends IQ {
     38     private String sessionID;
     39     private List<Packet> packets;
     40 
     41     /**
     42      * Creates a transcript request for the given sessionID.
     43      *
     44      * @param sessionID the id of the session to get the conversation transcript.
     45      */
     46     public Transcript(String sessionID) {
     47         this.sessionID = sessionID;
     48         this.packets = new ArrayList<Packet>();
     49     }
     50 
     51     /**
     52      * Creates a new transcript for the given sessionID and list of packets. The list of packets
     53      * may include Messages and/or Presences.
     54      *
     55      * @param sessionID the id of the session that generated this conversation transcript.
     56      * @param packets the list of messages and presences send to the room.
     57      */
     58     public Transcript(String sessionID, List<Packet> packets) {
     59         this.sessionID = sessionID;
     60         this.packets = packets;
     61     }
     62 
     63     /**
     64      * Returns id of the session that generated this conversation transcript. The sessionID is a
     65      * value generated by the server when a new request is received.
     66      *
     67      * @return id of the session that generated this conversation transcript.
     68      */
     69     public String getSessionID() {
     70         return sessionID;
     71     }
     72 
     73     /**
     74      * Returns the list of Messages and Presences that were sent to the room.
     75      *
     76      * @return the list of Messages and Presences that were sent to the room.
     77      */
     78     public List<Packet> getPackets() {
     79         return Collections.unmodifiableList(packets);
     80     }
     81 
     82     public String getChildElementXML() {
     83         StringBuilder buf = new StringBuilder();
     84 
     85         buf.append("<transcript xmlns=\"http://jivesoftware.com/protocol/workgroup\" sessionID=\"")
     86                 .append(sessionID)
     87                 .append("\">");
     88 
     89         for (Iterator<Packet> it=packets.iterator(); it.hasNext();) {
     90             Packet packet = it.next();
     91             buf.append(packet.toXML());
     92         }
     93 
     94         buf.append("</transcript>");
     95 
     96         return buf.toString();
     97     }
     98 }
     99