blob: 791b06ef2e07c324efe15b260bed8600098a20a0 [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/**
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
20package org.jivesoftware.smackx.workgroup.packet;
21
22import org.jivesoftware.smack.provider.IQProvider;
23import org.jivesoftware.smack.packet.IQ;
24import org.jivesoftware.smack.packet.Packet;
25import org.jivesoftware.smack.util.PacketParserUtils;
26import org.xmlpull.v1.XmlPullParser;
27
28import java.util.ArrayList;
29import java.util.List;
30
31/**
32 * An IQProvider for transcripts.
33 *
34 * @author Gaston Dombiak
35 */
36public class TranscriptProvider implements IQProvider {
37
38 public TranscriptProvider() {
39 super();
40 }
41
42 public IQ parseIQ(XmlPullParser parser) throws Exception {
43 String sessionID = parser.getAttributeValue("", "sessionID");
44 List<Packet> packets = new ArrayList<Packet>();
45
46 boolean done = false;
47 while (!done) {
48 int eventType = parser.next();
49 if (eventType == XmlPullParser.START_TAG) {
50 if (parser.getName().equals("message")) {
51 packets.add(PacketParserUtils.parseMessage(parser));
52 }
53 else if (parser.getName().equals("presence")) {
54 packets.add(PacketParserUtils.parsePresence(parser));
55 }
56 }
57 else if (eventType == XmlPullParser.END_TAG) {
58 if (parser.getName().equals("transcript")) {
59 done = true;
60 }
61 }
62 }
63
64 return new Transcript(sessionID, packets);
65 }
66}