aboutsummaryrefslogtreecommitdiff
path: root/src/org/jivesoftware/smackx/workgroup/packet
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/jivesoftware/smackx/workgroup/packet')
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/AgentInfo.java132
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java266
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/AgentStatusRequest.java163
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java129
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java75
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/MetaDataProvider.java49
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/MonitorPacket.java113
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java173
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java211
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java112
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java199
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java160
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/QueueUpdate.java122
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/RoomInvitation.java177
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/RoomTransfer.java177
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/SessionID.java77
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/Transcript.java98
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/TranscriptProvider.java66
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/TranscriptSearch.java87
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/Transcripts.java247
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java148
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/UserID.java77
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/WorkgroupInformation.java86
23 files changed, 3144 insertions, 0 deletions
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/AgentInfo.java b/src/org/jivesoftware/smackx/workgroup/packet/AgentInfo.java
new file mode 100644
index 0000000..8b9d230
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/AgentInfo.java
@@ -0,0 +1,132 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * IQ packet for retrieving and changing the Agent personal information.
+ */
+public class AgentInfo extends IQ {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "agent-info";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
+
+ private String jid;
+ private String name;
+
+ /**
+ * Returns the Agent's jid.
+ *
+ * @return the Agent's jid.
+ */
+ public String getJid() {
+ return jid;
+ }
+
+ /**
+ * Sets the Agent's jid.
+ *
+ * @param jid the jid of the agent.
+ */
+ public void setJid(String jid) {
+ this.jid = jid;
+ }
+
+ /**
+ * Returns the Agent's name. The name of the agent may be different than the user's name.
+ * This property may be shown in the webchat client.
+ *
+ * @return the Agent's name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the Agent's name. The name of the agent may be different than the user's name.
+ * This property may be shown in the webchat client.
+ *
+ * @param name the new name of the agent.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
+ if (jid != null) {
+ buf.append("<jid>").append(getJid()).append("</jid>");
+ }
+ if (name != null) {
+ buf.append("<name>").append(getName()).append("</name>");
+ }
+ buf.append("</").append(ELEMENT_NAME).append("> ");
+
+ return buf.toString();
+ }
+
+ /**
+ * An IQProvider for AgentInfo packets.
+ *
+ * @author Gaston Dombiak
+ */
+ public static class Provider implements IQProvider {
+
+ public Provider() {
+ super();
+ }
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ AgentInfo answer = new AgentInfo();
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("jid")) {
+ answer.setJid(parser.nextText());
+ }
+ else if (parser.getName().equals("name")) {
+ answer.setName(parser.nextText());
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals(ELEMENT_NAME)) {
+ done = true;
+ }
+ }
+ }
+
+ return answer;
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java b/src/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java
new file mode 100644
index 0000000..9f49033
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/AgentStatus.java
@@ -0,0 +1,266 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * Agent status packet.
+ *
+ * @author Matt Tucker
+ */
+public class AgentStatus implements PacketExtension {
+
+ private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
+
+ static {
+ UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
+ }
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "agent-status";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ private String workgroupJID;
+ private List<ChatInfo> currentChats = new ArrayList<ChatInfo>();
+ private int maxChats = -1;
+
+ AgentStatus() {
+ }
+
+ public String getWorkgroupJID() {
+ return workgroupJID;
+ }
+
+ /**
+ * Returns a collection of ChatInfo where each ChatInfo represents a Chat where this agent
+ * is participating.
+ *
+ * @return a collection of ChatInfo where each ChatInfo represents a Chat where this agent
+ * is participating.
+ */
+ public List<ChatInfo> getCurrentChats() {
+ return Collections.unmodifiableList(currentChats);
+ }
+
+ public int getMaxChats() {
+ return maxChats;
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\"");
+ if (workgroupJID != null) {
+ buf.append(" jid=\"").append(workgroupJID).append("\"");
+ }
+ buf.append(">");
+ if (maxChats != -1) {
+ buf.append("<max-chats>").append(maxChats).append("</max-chats>");
+ }
+ if (!currentChats.isEmpty()) {
+ buf.append("<current-chats xmlns= \"http://jivesoftware.com/protocol/workgroup\">");
+ for (Iterator<ChatInfo> it = currentChats.iterator(); it.hasNext();) {
+ buf.append(((ChatInfo)it.next()).toXML());
+ }
+ buf.append("</current-chats>");
+ }
+ buf.append("</").append(this.getElementName()).append("> ");
+
+ return buf.toString();
+ }
+
+ /**
+ * Represents information about a Chat where this Agent is participating.
+ *
+ * @author Gaston Dombiak
+ */
+ public static class ChatInfo {
+
+ private String sessionID;
+ private String userID;
+ private Date date;
+ private String email;
+ private String username;
+ private String question;
+
+ public ChatInfo(String sessionID, String userID, Date date, String email, String username, String question) {
+ this.sessionID = sessionID;
+ this.userID = userID;
+ this.date = date;
+ this.email = email;
+ this.username = username;
+ this.question = question;
+ }
+
+ /**
+ * Returns the sessionID associated to this chat. Each chat will have a unique sessionID
+ * that could be used for retrieving the whole transcript of the conversation.
+ *
+ * @return the sessionID associated to this chat.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ /**
+ * Returns the user unique identification of the user that made the initial request and
+ * for which this chat was generated. If the user joined using an anonymous connection
+ * then the userID will be the value of the ID attribute of the USER element. Otherwise,
+ * the userID will be the bare JID of the user that made the request.
+ *
+ * @return the user unique identification of the user that made the initial request.
+ */
+ public String getUserID() {
+ return userID;
+ }
+
+ /**
+ * Returns the date when this agent joined the chat.
+ *
+ * @return the date when this agent joined the chat.
+ */
+ public Date getDate() {
+ return date;
+ }
+
+ /**
+ * Returns the email address associated with the user.
+ *
+ * @return the email address associated with the user.
+ */
+ public String getEmail() {
+ return email;
+ }
+
+ /**
+ * Returns the username(nickname) associated with the user.
+ *
+ * @return the username associated with the user.
+ */
+ public String getUsername() {
+ return username;
+ }
+
+ /**
+ * Returns the question the user asked.
+ *
+ * @return the question the user asked, if any.
+ */
+ public String getQuestion() {
+ return question;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<chat ");
+ if (sessionID != null) {
+ buf.append(" sessionID=\"").append(sessionID).append("\"");
+ }
+ if (userID != null) {
+ buf.append(" userID=\"").append(userID).append("\"");
+ }
+ if (date != null) {
+ buf.append(" startTime=\"").append(UTC_FORMAT.format(date)).append("\"");
+ }
+ if (email != null) {
+ buf.append(" email=\"").append(email).append("\"");
+ }
+ if (username != null) {
+ buf.append(" username=\"").append(username).append("\"");
+ }
+ if (question != null) {
+ buf.append(" question=\"").append(question).append("\"");
+ }
+ buf.append("/>");
+
+ return buf.toString();
+ }
+ }
+
+ /**
+ * Packet extension provider for AgentStatus packets.
+ */
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+ AgentStatus agentStatus = new AgentStatus();
+
+ agentStatus.workgroupJID = parser.getAttributeValue("", "jid");
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+
+ if (eventType == XmlPullParser.START_TAG) {
+ if ("chat".equals(parser.getName())) {
+ agentStatus.currentChats.add(parseChatInfo(parser));
+ }
+ else if ("max-chats".equals(parser.getName())) {
+ agentStatus.maxChats = Integer.parseInt(parser.nextText());
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG &&
+ ELEMENT_NAME.equals(parser.getName())) {
+ done = true;
+ }
+ }
+ return agentStatus;
+ }
+
+ private ChatInfo parseChatInfo(XmlPullParser parser) {
+
+ String sessionID = parser.getAttributeValue("", "sessionID");
+ String userID = parser.getAttributeValue("", "userID");
+ Date date = null;
+ try {
+ date = UTC_FORMAT.parse(parser.getAttributeValue("", "startTime"));
+ }
+ catch (ParseException e) {
+ }
+
+ String email = parser.getAttributeValue("", "email");
+ String username = parser.getAttributeValue("", "username");
+ String question = parser.getAttributeValue("", "question");
+
+ return new ChatInfo(sessionID, userID, date, email, username, question);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/AgentStatusRequest.java b/src/org/jivesoftware/smackx/workgroup/packet/AgentStatusRequest.java
new file mode 100644
index 0000000..48549d2
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/AgentStatusRequest.java
@@ -0,0 +1,163 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Agent status request packet. This packet is used by agents to request the list of
+ * agents in a workgroup. The response packet contains a list of packets. Presence
+ * packets from individual agents follow.
+ *
+ * @author Matt Tucker
+ */
+public class AgentStatusRequest extends IQ {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "agent-status-request";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ private Set<Item> agents;
+
+ public AgentStatusRequest() {
+ agents = new HashSet<Item>();
+ }
+
+ public int getAgentCount() {
+ return agents.size();
+ }
+
+ public Set<Item> getAgents() {
+ return Collections.unmodifiableSet(agents);
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
+ synchronized (agents) {
+ for (Iterator<Item> i=agents.iterator(); i.hasNext(); ) {
+ Item item = (Item) i.next();
+ buf.append("<agent jid=\"").append(item.getJID()).append("\">");
+ if (item.getName() != null) {
+ buf.append("<name xmlns=\""+ AgentInfo.NAMESPACE + "\">");
+ buf.append(item.getName());
+ buf.append("</name>");
+ }
+ buf.append("</agent>");
+ }
+ }
+ buf.append("</").append(this.getElementName()).append("> ");
+ return buf.toString();
+ }
+
+ public static class Item {
+
+ private String jid;
+ private String type;
+ private String name;
+
+ public Item(String jid, String type, String name) {
+ this.jid = jid;
+ this.type = type;
+ this.name = name;
+ }
+
+ public String getJID() {
+ return jid;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
+ /**
+ * Packet extension provider for AgentStatusRequest packets.
+ */
+ public static class Provider implements IQProvider {
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ AgentStatusRequest statusRequest = new AgentStatusRequest();
+
+ if (parser.getEventType() != XmlPullParser.START_TAG) {
+ throw new IllegalStateException("Parser not in proper position, or bad XML.");
+ }
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if ((eventType == XmlPullParser.START_TAG) && ("agent".equals(parser.getName()))) {
+ statusRequest.agents.add(parseAgent(parser));
+ }
+ else if (eventType == XmlPullParser.END_TAG &&
+ "agent-status-request".equals(parser.getName()))
+ {
+ done = true;
+ }
+ }
+ return statusRequest;
+ }
+
+ private Item parseAgent(XmlPullParser parser) throws Exception {
+
+ boolean done = false;
+ String jid = parser.getAttributeValue("", "jid");
+ String type = parser.getAttributeValue("", "type");
+ String name = null;
+ while (!done) {
+ int eventType = parser.next();
+ if ((eventType == XmlPullParser.START_TAG) && ("name".equals(parser.getName()))) {
+ name = parser.nextText();
+ }
+ else if (eventType == XmlPullParser.END_TAG &&
+ "agent".equals(parser.getName()))
+ {
+ done = true;
+ }
+ }
+ return new Item(jid, type, name);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java b/src/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java
new file mode 100644
index 0000000..292a640
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/AgentWorkgroups.java
@@ -0,0 +1,129 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Represents a request for getting the jid of the workgroups where an agent can work or could
+ * represent the result of such request which will contain the list of workgroups JIDs where the
+ * agent can work.
+ *
+ * @author Gaston Dombiak
+ */
+public class AgentWorkgroups extends IQ {
+
+ private String agentJID;
+ private List<String> workgroups;
+
+ /**
+ * Creates an AgentWorkgroups request for the given agent. This IQ will be sent and an answer
+ * will be received with the jid of the workgroups where the agent can work.
+ *
+ * @param agentJID the id of the agent to get his workgroups.
+ */
+ public AgentWorkgroups(String agentJID) {
+ this.agentJID = agentJID;
+ this.workgroups = new ArrayList<String>();
+ }
+
+ /**
+ * Creates an AgentWorkgroups which will contain the JIDs of the workgroups where an agent can
+ * work.
+ *
+ * @param agentJID the id of the agent that can work in the list of workgroups.
+ * @param workgroups the list of workgroup JIDs where the agent can work.
+ */
+ public AgentWorkgroups(String agentJID, List<String> workgroups) {
+ this.agentJID = agentJID;
+ this.workgroups = workgroups;
+ }
+
+ public String getAgentJID() {
+ return agentJID;
+ }
+
+ /**
+ * Returns a list of workgroup JIDs where the agent can work.
+ *
+ * @return a list of workgroup JIDs where the agent can work.
+ */
+ public List<String> getWorkgroups() {
+ return Collections.unmodifiableList(workgroups);
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<workgroups xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"")
+ .append(agentJID)
+ .append("\">");
+
+ for (Iterator<String> it=workgroups.iterator(); it.hasNext();) {
+ String workgroupJID = it.next();
+ buf.append("<workgroup jid=\"" + workgroupJID + "\"/>");
+ }
+
+ buf.append("</workgroups>");
+
+ return buf.toString();
+ }
+
+ /**
+ * An IQProvider for AgentWorkgroups packets.
+ *
+ * @author Gaston Dombiak
+ */
+ public static class Provider implements IQProvider {
+
+ public Provider() {
+ super();
+ }
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ String agentJID = parser.getAttributeValue("", "jid");
+ List<String> workgroups = new ArrayList<String>();
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("workgroup")) {
+ workgroups.add(parser.getAttributeValue("", "jid"));
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals("workgroups")) {
+ done = true;
+ }
+ }
+ }
+
+ return new AgentWorkgroups(agentJID, workgroups);
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java b/src/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java
new file mode 100644
index 0000000..620291c
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/DepartQueuePacket.java
@@ -0,0 +1,75 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+
+/**
+ * A IQ packet used to depart a workgroup queue. There are two cases for issuing a depart
+ * queue request:<ul>
+ * <li>The user wants to leave the queue. In this case, an instance of this class
+ * should be created without passing in a user address.
+ * <li>An administrator or the server removes wants to remove a user from the queue.
+ * In that case, the address of the user to remove from the queue should be
+ * used to create an instance of this class.</ul>
+ *
+ * @author loki der quaeler
+ */
+public class DepartQueuePacket extends IQ {
+
+ private String user;
+
+ /**
+ * Creates a depart queue request packet to the specified workgroup.
+ *
+ * @param workgroup the workgroup to depart.
+ */
+ public DepartQueuePacket(String workgroup) {
+ this(workgroup, null);
+ }
+
+ /**
+ * Creates a depart queue request to the specified workgroup and for the
+ * specified user.
+ *
+ * @param workgroup the workgroup to depart.
+ * @param user the user to make depart from the queue.
+ */
+ public DepartQueuePacket(String workgroup, String user) {
+ this.user = user;
+
+ setTo(workgroup);
+ setType(IQ.Type.SET);
+ setFrom(user);
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder("<depart-queue xmlns=\"http://jabber.org/protocol/workgroup\"");
+
+ if (this.user != null) {
+ buf.append("><jid>").append(this.user).append("</jid></depart-queue>");
+ }
+ else {
+ buf.append("/>");
+ }
+
+ return buf.toString();
+ }
+} \ No newline at end of file
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/MetaDataProvider.java b/src/org/jivesoftware/smackx/workgroup/packet/MetaDataProvider.java
new file mode 100644
index 0000000..af76986
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/MetaDataProvider.java
@@ -0,0 +1,49 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import java.util.List;
+import java.util.Map;
+
+import org.jivesoftware.smackx.workgroup.MetaData;
+import org.jivesoftware.smackx.workgroup.util.MetaDataUtils;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * This provider parses meta data if it's not contained already in a larger extension provider.
+ *
+ * @author loki der quaeler
+ */
+public class MetaDataProvider implements PacketExtensionProvider {
+
+ /**
+ * PacketExtensionProvider implementation
+ */
+ public PacketExtension parseExtension (XmlPullParser parser)
+ throws Exception {
+ Map<String, List<String>> metaData = MetaDataUtils.parseMetaData(parser);
+
+ return new MetaData(metaData);
+ }
+} \ No newline at end of file
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/MonitorPacket.java b/src/org/jivesoftware/smackx/workgroup/packet/MonitorPacket.java
new file mode 100644
index 0000000..0ceecae
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/MonitorPacket.java
@@ -0,0 +1,113 @@
+/**
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+public class MonitorPacket extends IQ {
+
+ private String sessionID;
+
+ private boolean isMonitor;
+
+ public boolean isMonitor() {
+ return isMonitor;
+ }
+
+ public void setMonitor(boolean monitor) {
+ isMonitor = monitor;
+ }
+
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ public void setSessionID(String sessionID) {
+ this.sessionID = sessionID;
+ }
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "monitor";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=");
+ buf.append('"');
+ buf.append(NAMESPACE);
+ buf.append('"');
+ buf.append(">");
+ if (sessionID != null) {
+ buf.append("<makeOwner sessionID=\""+sessionID+"\"></makeOwner>");
+ }
+ buf.append("</").append(ELEMENT_NAME).append("> ");
+ return buf.toString();
+ }
+
+
+ /**
+ * Packet extension provider for Monitor Packets.
+ */
+ public static class InternalProvider implements IQProvider {
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ if (parser.getEventType() != XmlPullParser.START_TAG) {
+ throw new IllegalStateException("Parser not in proper position, or bad XML.");
+ }
+
+ MonitorPacket packet = new MonitorPacket();
+
+ boolean done = false;
+
+
+ while (!done) {
+ int eventType = parser.next();
+ if ((eventType == XmlPullParser.START_TAG) && ("isMonitor".equals(parser.getName()))) {
+ String value = parser.nextText();
+ if ("false".equalsIgnoreCase(value)) {
+ packet.setMonitor(false);
+ }
+ else {
+ packet.setMonitor(true);
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG && "monitor".equals(parser.getName())) {
+ done = true;
+ }
+ }
+
+ return packet;
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java b/src/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java
new file mode 100644
index 0000000..0f80866
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/OccupantsInfo.java
@@ -0,0 +1,173 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * Packet used for requesting information about occupants of a room or for retrieving information
+ * such information.
+ *
+ * @author Gaston Dombiak
+ */
+public class OccupantsInfo extends IQ {
+
+ private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
+
+ static {
+ UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
+ }
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "occupants-info";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
+
+ private String roomID;
+ private final Set<OccupantInfo> occupants;
+
+ public OccupantsInfo(String roomID) {
+ this.roomID = roomID;
+ this.occupants = new HashSet<OccupantInfo>();
+ }
+
+ public String getRoomID() {
+ return roomID;
+ }
+
+ public int getOccupantsCount() {
+ return occupants.size();
+ }
+
+ public Set<OccupantInfo> getOccupants() {
+ return Collections.unmodifiableSet(occupants);
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE);
+ buf.append("\" roomID=\"").append(roomID).append("\">");
+ synchronized (occupants) {
+ for (OccupantInfo occupant : occupants) {
+ buf.append("<occupant>");
+ // Add the occupant jid
+ buf.append("<jid>");
+ buf.append(occupant.getJID());
+ buf.append("</jid>");
+ // Add the occupant nickname
+ buf.append("<name>");
+ buf.append(occupant.getNickname());
+ buf.append("</name>");
+ // Add the date when the occupant joined the room
+ buf.append("<joined>");
+ buf.append(UTC_FORMAT.format(occupant.getJoined()));
+ buf.append("</joined>");
+ buf.append("</occupant>");
+ }
+ }
+ buf.append("</").append(ELEMENT_NAME).append("> ");
+ return buf.toString();
+ }
+
+ public static class OccupantInfo {
+
+ private String jid;
+ private String nickname;
+ private Date joined;
+
+ public OccupantInfo(String jid, String nickname, Date joined) {
+ this.jid = jid;
+ this.nickname = nickname;
+ this.joined = joined;
+ }
+
+ public String getJID() {
+ return jid;
+ }
+
+ public String getNickname() {
+ return nickname;
+ }
+
+ public Date getJoined() {
+ return joined;
+ }
+ }
+
+ /**
+ * Packet extension provider for AgentStatusRequest packets.
+ */
+ public static class Provider implements IQProvider {
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ if (parser.getEventType() != XmlPullParser.START_TAG) {
+ throw new IllegalStateException("Parser not in proper position, or bad XML.");
+ }
+ OccupantsInfo occupantsInfo = new OccupantsInfo(parser.getAttributeValue("", "roomID"));
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if ((eventType == XmlPullParser.START_TAG) &&
+ ("occupant".equals(parser.getName()))) {
+ occupantsInfo.occupants.add(parseOccupantInfo(parser));
+ } else if (eventType == XmlPullParser.END_TAG &&
+ ELEMENT_NAME.equals(parser.getName())) {
+ done = true;
+ }
+ }
+ return occupantsInfo;
+ }
+
+ private OccupantInfo parseOccupantInfo(XmlPullParser parser) throws Exception {
+
+ boolean done = false;
+ String jid = null;
+ String nickname = null;
+ Date joined = null;
+ while (!done) {
+ int eventType = parser.next();
+ if ((eventType == XmlPullParser.START_TAG) && ("jid".equals(parser.getName()))) {
+ jid = parser.nextText();
+ } else if ((eventType == XmlPullParser.START_TAG) &&
+ ("nickname".equals(parser.getName()))) {
+ nickname = parser.nextText();
+ } else if ((eventType == XmlPullParser.START_TAG) &&
+ ("joined".equals(parser.getName()))) {
+ joined = UTC_FORMAT.parse(parser.nextText());
+ } else if (eventType == XmlPullParser.END_TAG &&
+ "occupant".equals(parser.getName())) {
+ done = true;
+ }
+ }
+ return new OccupantInfo(jid, nickname, joined);
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java b/src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java
new file mode 100644
index 0000000..8f56b78
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java
@@ -0,0 +1,211 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smackx.workgroup.MetaData;
+import org.jivesoftware.smackx.workgroup.agent.InvitationRequest;
+import org.jivesoftware.smackx.workgroup.agent.OfferContent;
+import org.jivesoftware.smackx.workgroup.agent.TransferRequest;
+import org.jivesoftware.smackx.workgroup.agent.UserRequest;
+import org.jivesoftware.smackx.workgroup.util.MetaDataUtils;
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.jivesoftware.smack.util.PacketParserUtils;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An IQProvider for agent offer requests.
+ *
+ * @author loki der quaeler
+ */
+public class OfferRequestProvider implements IQProvider {
+
+ public OfferRequestProvider() {
+ }
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ int eventType = parser.getEventType();
+ String sessionID = null;
+ int timeout = -1;
+ OfferContent content = null;
+ boolean done = false;
+ Map<String, List<String>> metaData = new HashMap<String, List<String>>();
+
+ if (eventType != XmlPullParser.START_TAG) {
+ // throw exception
+ }
+
+ String userJID = parser.getAttributeValue("", "jid");
+ // Default userID to the JID.
+ String userID = userJID;
+
+ while (!done) {
+ eventType = parser.next();
+
+ if (eventType == XmlPullParser.START_TAG) {
+ String elemName = parser.getName();
+
+ if ("timeout".equals(elemName)) {
+ timeout = Integer.parseInt(parser.nextText());
+ }
+ else if (MetaData.ELEMENT_NAME.equals(elemName)) {
+ metaData = MetaDataUtils.parseMetaData(parser);
+ }
+ else if (SessionID.ELEMENT_NAME.equals(elemName)) {
+ sessionID = parser.getAttributeValue("", "id");
+ }
+ else if (UserID.ELEMENT_NAME.equals(elemName)) {
+ userID = parser.getAttributeValue("", "id");
+ }
+ else if ("user-request".equals(elemName)) {
+ content = UserRequest.getInstance();
+ }
+ else if (RoomInvitation.ELEMENT_NAME.equals(elemName)) {
+ RoomInvitation invitation = (RoomInvitation) PacketParserUtils
+ .parsePacketExtension(RoomInvitation.ELEMENT_NAME, RoomInvitation.NAMESPACE, parser);
+ content = new InvitationRequest(invitation.getInviter(), invitation.getRoom(),
+ invitation.getReason());
+ }
+ else if (RoomTransfer.ELEMENT_NAME.equals(elemName)) {
+ RoomTransfer transfer = (RoomTransfer) PacketParserUtils
+ .parsePacketExtension(RoomTransfer.ELEMENT_NAME, RoomTransfer.NAMESPACE, parser);
+ content = new TransferRequest(transfer.getInviter(), transfer.getRoom(), transfer.getReason());
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if ("offer".equals(parser.getName())) {
+ done = true;
+ }
+ }
+ }
+
+ OfferRequestPacket offerRequest =
+ new OfferRequestPacket(userJID, userID, timeout, metaData, sessionID, content);
+ offerRequest.setType(IQ.Type.SET);
+
+ return offerRequest;
+ }
+
+ public static class OfferRequestPacket extends IQ {
+
+ private int timeout;
+ private String userID;
+ private String userJID;
+ private Map<String, List<String>> metaData;
+ private String sessionID;
+ private OfferContent content;
+
+ public OfferRequestPacket(String userJID, String userID, int timeout, Map<String, List<String>> metaData,
+ String sessionID, OfferContent content)
+ {
+ this.userJID = userJID;
+ this.userID = userID;
+ this.timeout = timeout;
+ this.metaData = metaData;
+ this.sessionID = sessionID;
+ this.content = content;
+ }
+
+ /**
+ * Returns the userID, which is either the same as the userJID or a special
+ * value that the user provided as part of their "join queue" request.
+ *
+ * @return the user ID.
+ */
+ public String getUserID() {
+ return userID;
+ }
+
+ /**
+ * The JID of the user that made the "join queue" request.
+ *
+ * @return the user JID.
+ */
+ public String getUserJID() {
+ return userJID;
+ }
+
+ /**
+ * Returns the session ID associated with the request and ensuing chat. If the offer
+ * does not contain a session ID, <tt>null</tt> will be returned.
+ *
+ * @return the session id associated with the request.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ /**
+ * Returns the number of seconds the agent has to accept the offer before
+ * it times out.
+ *
+ * @return the offer timeout (in seconds).
+ */
+ public int getTimeout() {
+ return this.timeout;
+ }
+
+ public OfferContent getContent() {
+ return content;
+ }
+
+ /**
+ * Returns any meta-data associated with the offer.
+ *
+ * @return meta-data associated with the offer.
+ */
+ public Map<String, List<String>> getMetaData() {
+ return this.metaData;
+ }
+
+ public String getChildElementXML () {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<offer xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"").append(userJID).append("\">");
+ buf.append("<timeout>").append(timeout).append("</timeout>");
+
+ if (sessionID != null) {
+ buf.append('<').append(SessionID.ELEMENT_NAME);
+ buf.append(" session=\"");
+ buf.append(getSessionID()).append("\" xmlns=\"");
+ buf.append(SessionID.NAMESPACE).append("\"/>");
+ }
+
+ if (metaData != null) {
+ buf.append(MetaDataUtils.serializeMetaData(metaData));
+ }
+
+ if (userID != null) {
+ buf.append('<').append(UserID.ELEMENT_NAME);
+ buf.append(" id=\"");
+ buf.append(userID).append("\" xmlns=\"");
+ buf.append(UserID.NAMESPACE).append("\"/>");
+ }
+
+ buf.append("</offer>");
+
+ return buf.toString();
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java b/src/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java
new file mode 100644
index 0000000..202824c
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/OfferRevokeProvider.java
@@ -0,0 +1,112 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * An IQProvider class which has savvy about the offer-revoke tag.<br>
+ *
+ * @author loki der quaeler
+ */
+public class OfferRevokeProvider implements IQProvider {
+
+ public IQ parseIQ (XmlPullParser parser) throws Exception {
+ // The parser will be positioned on the opening IQ tag, so get the JID attribute.
+ String userJID = parser.getAttributeValue("", "jid");
+ // Default the userID to the JID.
+ String userID = userJID;
+ String reason = null;
+ String sessionID = null;
+ boolean done = false;
+
+ while (!done) {
+ int eventType = parser.next();
+
+ if ((eventType == XmlPullParser.START_TAG) && parser.getName().equals("reason")) {
+ reason = parser.nextText();
+ }
+ else if ((eventType == XmlPullParser.START_TAG)
+ && parser.getName().equals(SessionID.ELEMENT_NAME)) {
+ sessionID = parser.getAttributeValue("", "id");
+ }
+ else if ((eventType == XmlPullParser.START_TAG)
+ && parser.getName().equals(UserID.ELEMENT_NAME)) {
+ userID = parser.getAttributeValue("", "id");
+ }
+ else if ((eventType == XmlPullParser.END_TAG) && parser.getName().equals(
+ "offer-revoke"))
+ {
+ done = true;
+ }
+ }
+
+ return new OfferRevokePacket(userJID, userID, reason, sessionID);
+ }
+
+ public class OfferRevokePacket extends IQ {
+
+ private String userJID;
+ private String userID;
+ private String sessionID;
+ private String reason;
+
+ public OfferRevokePacket (String userJID, String userID, String cause, String sessionID) {
+ this.userJID = userJID;
+ this.userID = userID;
+ this.reason = cause;
+ this.sessionID = sessionID;
+ }
+
+ public String getUserJID() {
+ return userJID;
+ }
+
+ public String getUserID() {
+ return this.userID;
+ }
+
+ public String getReason() {
+ return this.reason;
+ }
+
+ public String getSessionID() {
+ return this.sessionID;
+ }
+
+ public String getChildElementXML () {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<offer-revoke xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"").append(userID).append("\">");
+ if (reason != null) {
+ buf.append("<reason>").append(reason).append("</reason>");
+ }
+ if (sessionID != null) {
+ buf.append(new SessionID(sessionID).toXML());
+ }
+ if (userID != null) {
+ buf.append(new UserID(userID).toXML());
+ }
+ buf.append("</offer-revoke>");
+ return buf.toString();
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java b/src/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java
new file mode 100644
index 0000000..ef11a78
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/QueueDetails.java
@@ -0,0 +1,199 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smackx.workgroup.QueueUser;
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * Queue details packet extension, which contains details about the users
+ * currently in a queue.
+ */
+public class QueueDetails implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "notify-queue-details";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ private static final String DATE_FORMAT = "yyyyMMdd'T'HH:mm:ss";
+
+ private SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+ /**
+ * The list of users in the queue.
+ */
+ private Set<QueueUser> users;
+
+ /**
+ * Creates a new QueueDetails packet
+ */
+ private QueueDetails() {
+ users = new HashSet<QueueUser>();
+ }
+
+ /**
+ * Returns the number of users currently in the queue that are waiting to
+ * be routed to an agent.
+ *
+ * @return the number of users in the queue.
+ */
+ public int getUserCount() {
+ return users.size();
+ }
+
+ /**
+ * Returns the set of users in the queue that are waiting to
+ * be routed to an agent (as QueueUser objects).
+ *
+ * @return a Set for the users waiting in a queue.
+ */
+ public Set<QueueUser> getUsers() {
+ synchronized (users) {
+ return users;
+ }
+ }
+
+ /**
+ * Adds a user to the packet.
+ *
+ * @param user the user.
+ */
+ private void addUser(QueueUser user) {
+ synchronized (users) {
+ users.add(user);
+ }
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
+
+ synchronized (users) {
+ for (Iterator<QueueUser> i=users.iterator(); i.hasNext(); ) {
+ QueueUser user = (QueueUser)i.next();
+ int position = user.getQueuePosition();
+ int timeRemaining = user.getEstimatedRemainingTime();
+ Date timestamp = user.getQueueJoinTimestamp();
+
+ buf.append("<user jid=\"").append(user.getUserID()).append("\">");
+
+ if (position != -1) {
+ buf.append("<position>").append(position).append("</position>");
+ }
+
+ if (timeRemaining != -1) {
+ buf.append("<time>").append(timeRemaining).append("</time>");
+ }
+
+ if (timestamp != null) {
+ buf.append("<join-time>");
+ buf.append(dateFormat.format(timestamp));
+ buf.append("</join-time>");
+ }
+
+ buf.append("</user>");
+ }
+ }
+ buf.append("</").append(ELEMENT_NAME).append(">");
+ return buf.toString();
+ }
+
+ /**
+ * Provider class for QueueDetails packet extensions.
+ */
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+ QueueDetails queueDetails = new QueueDetails();
+
+ int eventType = parser.getEventType();
+ while (eventType != XmlPullParser.END_TAG &&
+ "notify-queue-details".equals(parser.getName()))
+ {
+ eventType = parser.next();
+ while ((eventType == XmlPullParser.START_TAG) && "user".equals(parser.getName())) {
+ String uid = null;
+ int position = -1;
+ int time = -1;
+ Date joinTime = null;
+
+ uid = parser.getAttributeValue("", "jid");
+
+ if (uid == null) {
+ // throw exception
+ }
+
+ eventType = parser.next();
+ while ((eventType != XmlPullParser.END_TAG)
+ || (! "user".equals(parser.getName())))
+ {
+ if ("position".equals(parser.getName())) {
+ position = Integer.parseInt(parser.nextText());
+ }
+ else if ("time".equals(parser.getName())) {
+ time = Integer.parseInt(parser.nextText());
+ }
+ else if ("join-time".equals(parser.getName())) {
+ joinTime = dateFormat.parse(parser.nextText());
+ }
+ else if( parser.getName().equals( "waitTime" ) ) {
+ Date wait = dateFormat.parse(parser.nextText());
+ System.out.println( wait );
+ }
+
+ eventType = parser.next();
+
+ if (eventType != XmlPullParser.END_TAG) {
+ // throw exception
+ }
+ }
+
+ queueDetails.addUser(new QueueUser(uid, position, time, joinTime));
+
+ eventType = parser.next();
+ }
+ }
+ return queueDetails;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java b/src/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java
new file mode 100644
index 0000000..a559579
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/QueueOverview.java
@@ -0,0 +1,160 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smackx.workgroup.agent.WorkgroupQueue;
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class QueueOverview implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static String ELEMENT_NAME = "notify-queue";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ private static final String DATE_FORMAT = "yyyyMMdd'T'HH:mm:ss";
+ private SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+
+ private int averageWaitTime;
+ private Date oldestEntry;
+ private int userCount;
+ private WorkgroupQueue.Status status;
+
+ QueueOverview() {
+ this.averageWaitTime = -1;
+ this.oldestEntry = null;
+ this.userCount = -1;
+ this.status = null;
+ }
+
+ void setAverageWaitTime(int averageWaitTime) {
+ this.averageWaitTime = averageWaitTime;
+ }
+
+ public int getAverageWaitTime () {
+ return averageWaitTime;
+ }
+
+ void setOldestEntry(Date oldestEntry) {
+ this.oldestEntry = oldestEntry;
+ }
+
+ public Date getOldestEntry() {
+ return oldestEntry;
+ }
+
+ void setUserCount(int userCount) {
+ this.userCount = userCount;
+ }
+
+ public int getUserCount() {
+ return userCount;
+ }
+
+ public WorkgroupQueue.Status getStatus() {
+ return status;
+ }
+
+ void setStatus(WorkgroupQueue.Status status) {
+ this.status = status;
+ }
+
+ public String getElementName () {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace () {
+ return NAMESPACE;
+ }
+
+ public String toXML () {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
+
+ if (userCount != -1) {
+ buf.append("<count>").append(userCount).append("</count>");
+ }
+ if (oldestEntry != null) {
+ buf.append("<oldest>").append(dateFormat.format(oldestEntry)).append("</oldest>");
+ }
+ if (averageWaitTime != -1) {
+ buf.append("<time>").append(averageWaitTime).append("</time>");
+ }
+ if (status != null) {
+ buf.append("<status>").append(status).append("</status>");
+ }
+ buf.append("</").append(ELEMENT_NAME).append(">");
+
+ return buf.toString();
+ }
+
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension (XmlPullParser parser) throws Exception {
+ int eventType = parser.getEventType();
+ QueueOverview queueOverview = new QueueOverview();
+ SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
+
+ if (eventType != XmlPullParser.START_TAG) {
+ // throw exception
+ }
+
+ eventType = parser.next();
+ while ((eventType != XmlPullParser.END_TAG)
+ || (!ELEMENT_NAME.equals(parser.getName())))
+ {
+ if ("count".equals(parser.getName())) {
+ queueOverview.setUserCount(Integer.parseInt(parser.nextText()));
+ }
+ else if ("time".equals(parser.getName())) {
+ queueOverview.setAverageWaitTime(Integer.parseInt(parser.nextText()));
+ }
+ else if ("oldest".equals(parser.getName())) {
+ queueOverview.setOldestEntry((dateFormat.parse(parser.nextText())));
+ }
+ else if ("status".equals(parser.getName())) {
+ queueOverview.setStatus(WorkgroupQueue.Status.fromString(parser.nextText()));
+ }
+
+ eventType = parser.next();
+
+ if (eventType != XmlPullParser.END_TAG) {
+ // throw exception
+ }
+ }
+
+ if (eventType != XmlPullParser.END_TAG) {
+ // throw exception
+ }
+
+ return queueOverview;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/QueueUpdate.java b/src/org/jivesoftware/smackx/workgroup/packet/QueueUpdate.java
new file mode 100644
index 0000000..c326a57
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/QueueUpdate.java
@@ -0,0 +1,122 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * An IQ packet that encapsulates both types of workgroup queue
+ * status notifications -- position updates, and estimated time
+ * left in the queue updates.
+ */
+public class QueueUpdate implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "queue-status";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ private int position;
+ private int remainingTime;
+
+ public QueueUpdate(int position, int remainingTime) {
+ this.position = position;
+ this.remainingTime = remainingTime;
+ }
+
+ /**
+ * Returns the user's position in the workgroup queue, or -1 if the
+ * value isn't set on this packet.
+ *
+ * @return the position in the workgroup queue.
+ */
+ public int getPosition() {
+ return this.position;
+ }
+
+ /**
+ * Returns the user's estimated time left in the workgroup queue, or
+ * -1 if the value isn't set on this packet.
+ *
+ * @return the estimated time left in the workgroup queue.
+ */
+ public int getRemaingTime() {
+ return remainingTime;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+ buf.append("<queue-status xmlns=\"http://jabber.org/protocol/workgroup\">");
+ if (position != -1) {
+ buf.append("<position>").append(position).append("</position>");
+ }
+ if (remainingTime != -1) {
+ buf.append("<time>").append(remainingTime).append("</time>");
+ }
+ buf.append("</queue-status>");
+ return buf.toString();
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+ boolean done = false;
+ int position = -1;
+ int timeRemaining = -1;
+ while (!done) {
+ parser.next();
+ String elementName = parser.getName();
+ if (parser.getEventType() == XmlPullParser.START_TAG && "position".equals(elementName)) {
+ try {
+ position = Integer.parseInt(parser.nextText());
+ }
+ catch (NumberFormatException nfe) {
+ }
+ }
+ else if (parser.getEventType() == XmlPullParser.START_TAG && "time".equals(elementName)) {
+ try {
+ timeRemaining = Integer.parseInt(parser.nextText());
+ }
+ catch (NumberFormatException nfe) {
+ }
+ }
+ else if (parser.getEventType() == XmlPullParser.END_TAG && "queue-status".equals(elementName)) {
+ done = true;
+ }
+ }
+ return new QueueUpdate(position, timeRemaining);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/RoomInvitation.java b/src/org/jivesoftware/smackx/workgroup/packet/RoomInvitation.java
new file mode 100644
index 0000000..34555de
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/RoomInvitation.java
@@ -0,0 +1,177 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * Packet extension for {@link org.jivesoftware.smackx.workgroup.agent.InvitationRequest}.
+ *
+ * @author Gaston Dombiak
+ */
+public class RoomInvitation implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "invite";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ /**
+ * Type of entity being invited to a groupchat support session.
+ */
+ private Type type;
+ /**
+ * JID of the entity being invited. The entity could be another agent, user , a queue or a workgroup. In
+ * the case of a queue or a workgroup the server will select the best agent to invite.
+ */
+ private String invitee;
+ /**
+ * Full JID of the user that sent the invitation.
+ */
+ private String inviter;
+ /**
+ * ID of the session that originated the initial user request.
+ */
+ private String sessionID;
+ /**
+ * JID of the room to join if offer is accepted.
+ */
+ private String room;
+ /**
+ * Text provided by the inviter explaining the reason why the invitee is invited.
+ */
+ private String reason;
+
+ public RoomInvitation(Type type, String invitee, String sessionID, String reason) {
+ this.type = type;
+ this.invitee = invitee;
+ this.sessionID = sessionID;
+ this.reason = reason;
+ }
+
+ private RoomInvitation() {
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String getInviter() {
+ return inviter;
+ }
+
+ public String getRoom() {
+ return room;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE);
+ buf.append("\" type=\"").append(type).append("\">");
+ buf.append("<session xmlns=\"http://jivesoftware.com/protocol/workgroup\" id=\"").append(sessionID).append("\"></session>");
+ if (invitee != null) {
+ buf.append("<invitee>").append(invitee).append("</invitee>");
+ }
+ if (inviter != null) {
+ buf.append("<inviter>").append(inviter).append("</inviter>");
+ }
+ if (reason != null) {
+ buf.append("<reason>").append(reason).append("</reason>");
+ }
+ // Add packet extensions, if any are defined.
+ buf.append("</").append(ELEMENT_NAME).append("> ");
+
+ return buf.toString();
+ }
+
+ /**
+ * Type of entity being invited to a groupchat support session.
+ */
+ public static enum Type {
+ /**
+ * A user is being invited to a groupchat support session. The user could be another agent
+ * or just a regular XMPP user.
+ */
+ user,
+ /**
+ * Some agent of the specified queue will be invited to the groupchat support session.
+ */
+ queue,
+ /**
+ * Some agent of the specified workgroup will be invited to the groupchat support session.
+ */
+ workgroup
+ }
+
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+ final RoomInvitation invitation = new RoomInvitation();
+ invitation.type = Type.valueOf(parser.getAttributeValue("", "type"));
+
+ boolean done = false;
+ while (!done) {
+ parser.next();
+ String elementName = parser.getName();
+ if (parser.getEventType() == XmlPullParser.START_TAG) {
+ if ("session".equals(elementName)) {
+ invitation.sessionID = parser.getAttributeValue("", "id");
+ }
+ else if ("invitee".equals(elementName)) {
+ invitation.invitee = parser.nextText();
+ }
+ else if ("inviter".equals(elementName)) {
+ invitation.inviter = parser.nextText();
+ }
+ else if ("reason".equals(elementName)) {
+ invitation.reason = parser.nextText();
+ }
+ else if ("room".equals(elementName)) {
+ invitation.room = parser.nextText();
+ }
+ }
+ else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
+ done = true;
+ }
+ }
+ return invitation;
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/RoomTransfer.java b/src/org/jivesoftware/smackx/workgroup/packet/RoomTransfer.java
new file mode 100644
index 0000000..d1e83e2
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/RoomTransfer.java
@@ -0,0 +1,177 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * Packet extension for {@link org.jivesoftware.smackx.workgroup.agent.TransferRequest}.
+ *
+ * @author Gaston Dombiak
+ */
+public class RoomTransfer implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "transfer";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ /**
+ * Type of entity being invited to a groupchat support session.
+ */
+ private RoomTransfer.Type type;
+ /**
+ * JID of the entity being invited. The entity could be another agent, user , a queue or a workgroup. In
+ * the case of a queue or a workgroup the server will select the best agent to invite.
+ */
+ private String invitee;
+ /**
+ * Full JID of the user that sent the invitation.
+ */
+ private String inviter;
+ /**
+ * ID of the session that originated the initial user request.
+ */
+ private String sessionID;
+ /**
+ * JID of the room to join if offer is accepted.
+ */
+ private String room;
+ /**
+ * Text provided by the inviter explaining the reason why the invitee is invited.
+ */
+ private String reason;
+
+ public RoomTransfer(RoomTransfer.Type type, String invitee, String sessionID, String reason) {
+ this.type = type;
+ this.invitee = invitee;
+ this.sessionID = sessionID;
+ this.reason = reason;
+ }
+
+ private RoomTransfer() {
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String getInviter() {
+ return inviter;
+ }
+
+ public String getRoom() {
+ return room;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE);
+ buf.append("\" type=\"").append(type).append("\">");
+ buf.append("<session xmlns=\"http://jivesoftware.com/protocol/workgroup\" id=\"").append(sessionID).append("\"></session>");
+ if (invitee != null) {
+ buf.append("<invitee>").append(invitee).append("</invitee>");
+ }
+ if (inviter != null) {
+ buf.append("<inviter>").append(inviter).append("</inviter>");
+ }
+ if (reason != null) {
+ buf.append("<reason>").append(reason).append("</reason>");
+ }
+ // Add packet extensions, if any are defined.
+ buf.append("</").append(ELEMENT_NAME).append("> ");
+
+ return buf.toString();
+ }
+
+ /**
+ * Type of entity being invited to a groupchat support session.
+ */
+ public static enum Type {
+ /**
+ * A user is being invited to a groupchat support session. The user could be another agent
+ * or just a regular XMPP user.
+ */
+ user,
+ /**
+ * Some agent of the specified queue will be invited to the groupchat support session.
+ */
+ queue,
+ /**
+ * Some agent of the specified workgroup will be invited to the groupchat support session.
+ */
+ workgroup
+ }
+
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+ final RoomTransfer invitation = new RoomTransfer();
+ invitation.type = RoomTransfer.Type.valueOf(parser.getAttributeValue("", "type"));
+
+ boolean done = false;
+ while (!done) {
+ parser.next();
+ String elementName = parser.getName();
+ if (parser.getEventType() == XmlPullParser.START_TAG) {
+ if ("session".equals(elementName)) {
+ invitation.sessionID = parser.getAttributeValue("", "id");
+ }
+ else if ("invitee".equals(elementName)) {
+ invitation.invitee = parser.nextText();
+ }
+ else if ("inviter".equals(elementName)) {
+ invitation.inviter = parser.nextText();
+ }
+ else if ("reason".equals(elementName)) {
+ invitation.reason = parser.nextText();
+ }
+ else if ("room".equals(elementName)) {
+ invitation.room = parser.nextText();
+ }
+ }
+ else if (parser.getEventType() == XmlPullParser.END_TAG && ELEMENT_NAME.equals(elementName)) {
+ done = true;
+ }
+ }
+ return invitation;
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/SessionID.java b/src/org/jivesoftware/smackx/workgroup/packet/SessionID.java
new file mode 100644
index 0000000..bfd7cfd
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/SessionID.java
@@ -0,0 +1,77 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+public class SessionID implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "session";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
+
+ private String sessionID;
+
+ public SessionID(String sessionID) {
+ this.sessionID = sessionID;
+ }
+
+ public String getSessionID() {
+ return this.sessionID;
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" ");
+ buf.append("id=\"").append(this.getSessionID());
+ buf.append("\"/>");
+
+ return buf.toString();
+ }
+
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+ String sessionID = parser.getAttributeValue("", "id");
+
+ // Advance to end of extension.
+ parser.next();
+
+ return new SessionID(sessionID);
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/Transcript.java b/src/org/jivesoftware/smackx/workgroup/packet/Transcript.java
new file mode 100644
index 0000000..7f8f29e
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/Transcript.java
@@ -0,0 +1,98 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.packet.Packet;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Represents the conversation transcript that occured in a group chat room between an Agent
+ * and a user that requested assistance. The transcript contains all the Messages that were sent
+ * to the room as well as the sent presences.
+ *
+ * @author Gaston Dombiak
+ */
+public class Transcript extends IQ {
+ private String sessionID;
+ private List<Packet> packets;
+
+ /**
+ * Creates a transcript request for the given sessionID.
+ *
+ * @param sessionID the id of the session to get the conversation transcript.
+ */
+ public Transcript(String sessionID) {
+ this.sessionID = sessionID;
+ this.packets = new ArrayList<Packet>();
+ }
+
+ /**
+ * Creates a new transcript for the given sessionID and list of packets. The list of packets
+ * may include Messages and/or Presences.
+ *
+ * @param sessionID the id of the session that generated this conversation transcript.
+ * @param packets the list of messages and presences send to the room.
+ */
+ public Transcript(String sessionID, List<Packet> packets) {
+ this.sessionID = sessionID;
+ this.packets = packets;
+ }
+
+ /**
+ * Returns id of the session that generated this conversation transcript. The sessionID is a
+ * value generated by the server when a new request is received.
+ *
+ * @return id of the session that generated this conversation transcript.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ /**
+ * Returns the list of Messages and Presences that were sent to the room.
+ *
+ * @return the list of Messages and Presences that were sent to the room.
+ */
+ public List<Packet> getPackets() {
+ return Collections.unmodifiableList(packets);
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<transcript xmlns=\"http://jivesoftware.com/protocol/workgroup\" sessionID=\"")
+ .append(sessionID)
+ .append("\">");
+
+ for (Iterator<Packet> it=packets.iterator(); it.hasNext();) {
+ Packet packet = it.next();
+ buf.append(packet.toXML());
+ }
+
+ buf.append("</transcript>");
+
+ return buf.toString();
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/TranscriptProvider.java b/src/org/jivesoftware/smackx/workgroup/packet/TranscriptProvider.java
new file mode 100644
index 0000000..791b06e
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/TranscriptProvider.java
@@ -0,0 +1,66 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.provider.IQProvider;
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.util.PacketParserUtils;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * An IQProvider for transcripts.
+ *
+ * @author Gaston Dombiak
+ */
+public class TranscriptProvider implements IQProvider {
+
+ public TranscriptProvider() {
+ super();
+ }
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ String sessionID = parser.getAttributeValue("", "sessionID");
+ List<Packet> packets = new ArrayList<Packet>();
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("message")) {
+ packets.add(PacketParserUtils.parseMessage(parser));
+ }
+ else if (parser.getName().equals("presence")) {
+ packets.add(PacketParserUtils.parsePresence(parser));
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals("transcript")) {
+ done = true;
+ }
+ }
+ }
+
+ return new Transcript(sessionID, packets);
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/TranscriptSearch.java b/src/org/jivesoftware/smackx/workgroup/packet/TranscriptSearch.java
new file mode 100644
index 0000000..72693c4
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/TranscriptSearch.java
@@ -0,0 +1,87 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.jivesoftware.smack.util.PacketParserUtils;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * IQ packet for retrieving the transcript search form, submiting the completed search form
+ * or retrieving the answer of a transcript search.
+ *
+ * @author Gaston Dombiak
+ */
+public class TranscriptSearch extends IQ {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "transcript-search";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
+ // Add packet extensions, if any are defined.
+ buf.append(getExtensionsXML());
+ buf.append("</").append(ELEMENT_NAME).append("> ");
+
+ return buf.toString();
+ }
+
+ /**
+ * An IQProvider for TranscriptSearch packets.
+ *
+ * @author Gaston Dombiak
+ */
+ public static class Provider implements IQProvider {
+
+ public Provider() {
+ super();
+ }
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ TranscriptSearch answer = new TranscriptSearch();
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ // Parse the packet extension
+ answer.addExtension(PacketParserUtils.parsePacketExtension(parser.getName(), parser.getNamespace(), parser));
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals(ELEMENT_NAME)) {
+ done = true;
+ }
+ }
+ }
+
+ return answer;
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/Transcripts.java b/src/org/jivesoftware/smackx/workgroup/packet/Transcripts.java
new file mode 100644
index 0000000..66ddaad
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/Transcripts.java
@@ -0,0 +1,247 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+/**
+ * Represents a list of conversation transcripts that a user had in all his history. Each
+ * transcript summary includes the sessionID which may be used for getting more detailed
+ * information about the conversation. {@link org.jivesoftware.smackx.workgroup.packet.Transcript}
+ *
+ * @author Gaston Dombiak
+ */
+public class Transcripts extends IQ {
+
+ private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
+ static {
+ UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
+ }
+
+ private String userID;
+ private List<Transcripts.TranscriptSummary> summaries;
+
+
+ /**
+ * Creates a transcripts request for the given userID.
+ *
+ * @param userID the id of the user to get his conversations transcripts.
+ */
+ public Transcripts(String userID) {
+ this.userID = userID;
+ this.summaries = new ArrayList<Transcripts.TranscriptSummary>();
+ }
+
+ /**
+ * Creates a Transcripts which will contain the transcript summaries of the given user.
+ *
+ * @param userID the id of the user. Could be a real JID or a unique String that identifies
+ * anonymous users.
+ * @param summaries the list of TranscriptSummaries.
+ */
+ public Transcripts(String userID, List<Transcripts.TranscriptSummary> summaries) {
+ this.userID = userID;
+ this.summaries = summaries;
+ }
+
+ /**
+ * Returns the id of the user that was involved in the conversations. The userID could be a
+ * real JID if the connected user was not anonymous. Otherwise, the userID will be a String
+ * that was provided by the anonymous user as a way to idenitify the user across many user
+ * sessions.
+ *
+ * @return the id of the user that was involved in the conversations.
+ */
+ public String getUserID() {
+ return userID;
+ }
+
+ /**
+ * Returns a list of TranscriptSummary. A TranscriptSummary does not contain the conversation
+ * transcript but some summary information like the sessionID and the time when the
+ * conversation started and finished. Once you have the sessionID it is possible to get the
+ * full conversation transcript.
+ *
+ * @return a list of TranscriptSummary.
+ */
+ public List<Transcripts.TranscriptSummary> getSummaries() {
+ return Collections.unmodifiableList(summaries);
+ }
+
+ public String getChildElementXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<transcripts xmlns=\"http://jivesoftware.com/protocol/workgroup\" userID=\"")
+ .append(userID)
+ .append("\">");
+
+ for (TranscriptSummary transcriptSummary : summaries) {
+ buf.append(transcriptSummary.toXML());
+ }
+
+ buf.append("</transcripts>");
+
+ return buf.toString();
+ }
+
+ /**
+ * A TranscriptSummary contains some information about a conversation such as the ID of the
+ * session or the date when the conversation started and finished. You will need to use the
+ * sessionID to get the full conversation transcript.
+ */
+ public static class TranscriptSummary {
+ private String sessionID;
+ private Date joinTime;
+ private Date leftTime;
+ private List<AgentDetail> agentDetails;
+
+ public TranscriptSummary(String sessionID, Date joinTime, Date leftTime, List<AgentDetail> agentDetails) {
+ this.sessionID = sessionID;
+ this.joinTime = joinTime;
+ this.leftTime = leftTime;
+ this.agentDetails = agentDetails;
+ }
+
+ /**
+ * Returns the ID of the session that is related to this conversation transcript. The
+ * sessionID could be used for getting the full conversation transcript.
+ *
+ * @return the ID of the session that is related to this conversation transcript.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ /**
+ * Returns the Date when the conversation started.
+ *
+ * @return the Date when the conversation started.
+ */
+ public Date getJoinTime() {
+ return joinTime;
+ }
+
+ /**
+ * Returns the Date when the conversation finished.
+ *
+ * @return the Date when the conversation finished.
+ */
+ public Date getLeftTime() {
+ return leftTime;
+ }
+
+ /**
+ * Returns a list of AgentDetails. For each Agent that was involved in the conversation
+ * the list will include an AgentDetail. An AgentDetail contains the JID of the agent
+ * as well as the time when the Agent joined and left the conversation.
+ *
+ * @return a list of AgentDetails.
+ */
+ public List<AgentDetail> getAgentDetails() {
+ return agentDetails;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<transcript sessionID=\"")
+ .append(sessionID)
+ .append("\">");
+
+ if (joinTime != null) {
+ buf.append("<joinTime>").append(UTC_FORMAT.format(joinTime)).append("</joinTime>");
+ }
+ if (leftTime != null) {
+ buf.append("<leftTime>").append(UTC_FORMAT.format(leftTime)).append("</leftTime>");
+ }
+ buf.append("<agents>");
+ for (AgentDetail agentDetail : agentDetails) {
+ buf.append(agentDetail.toXML());
+ }
+ buf.append("</agents></transcript>");
+
+ return buf.toString();
+ }
+ }
+
+ /**
+ * An AgentDetail contains information of an Agent that was involved in a conversation.
+ */
+ public static class AgentDetail {
+ private String agentJID;
+ private Date joinTime;
+ private Date leftTime;
+
+ public AgentDetail(String agentJID, Date joinTime, Date leftTime) {
+ this.agentJID = agentJID;
+ this.joinTime = joinTime;
+ this.leftTime = leftTime;
+ }
+
+ /**
+ * Returns the bare JID of the Agent that was involved in the conversation.
+ *
+ * @return the bared JID of the Agent that was involved in the conversation.
+ */
+ public String getAgentJID() {
+ return agentJID;
+ }
+
+ /**
+ * Returns the Date when the Agent joined the conversation.
+ *
+ * @return the Date when the Agent joined the conversation.
+ */
+ public Date getJoinTime() {
+ return joinTime;
+ }
+
+ /**
+ * Returns the Date when the Agent left the conversation.
+ *
+ * @return the Date when the Agent left the conversation.
+ */
+ public Date getLeftTime() {
+ return leftTime;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<agent>");
+
+ if (agentJID != null) {
+ buf.append("<agentJID>").append(agentJID).append("</agentJID>");
+ }
+ if (joinTime != null) {
+ buf.append("<joinTime>").append(UTC_FORMAT.format(joinTime)).append("</joinTime>");
+ }
+ if (leftTime != null) {
+ buf.append("<leftTime>").append(UTC_FORMAT.format(leftTime)).append("</leftTime>");
+ }
+ buf.append("</agent>");
+
+ return buf.toString();
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java b/src/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java
new file mode 100644
index 0000000..cb8f429
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/TranscriptsProvider.java
@@ -0,0 +1,148 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.TimeZone;
+
+/**
+ * An IQProvider for transcripts summaries.
+ *
+ * @author Gaston Dombiak
+ */
+public class TranscriptsProvider implements IQProvider {
+
+ private static final SimpleDateFormat UTC_FORMAT = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
+ static {
+ UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("GMT+0"));
+ }
+
+ public TranscriptsProvider() {
+ super();
+ }
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ String userID = parser.getAttributeValue("", "userID");
+ List<Transcripts.TranscriptSummary> summaries = new ArrayList<Transcripts.TranscriptSummary>();
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("transcript")) {
+ summaries.add(parseSummary(parser));
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals("transcripts")) {
+ done = true;
+ }
+ }
+ }
+
+ return new Transcripts(userID, summaries);
+ }
+
+ private Transcripts.TranscriptSummary parseSummary(XmlPullParser parser) throws IOException,
+ XmlPullParserException {
+ String sessionID = parser.getAttributeValue("", "sessionID");
+ Date joinTime = null;
+ Date leftTime = null;
+ List<Transcripts.AgentDetail> agents = new ArrayList<Transcripts.AgentDetail>();
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("joinTime")) {
+ try {
+ joinTime = UTC_FORMAT.parse(parser.nextText());
+ } catch (ParseException e) {}
+ }
+ else if (parser.getName().equals("leftTime")) {
+ try {
+ leftTime = UTC_FORMAT.parse(parser.nextText());
+ } catch (ParseException e) {}
+ }
+ else if (parser.getName().equals("agents")) {
+ agents = parseAgents(parser);
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals("transcript")) {
+ done = true;
+ }
+ }
+ }
+
+ return new Transcripts.TranscriptSummary(sessionID, joinTime, leftTime, agents);
+ }
+
+ private List<Transcripts.AgentDetail> parseAgents(XmlPullParser parser) throws IOException, XmlPullParserException {
+ List<Transcripts.AgentDetail> agents = new ArrayList<Transcripts.AgentDetail>();
+ String agentJID = null;
+ Date joinTime = null;
+ Date leftTime = null;
+
+ boolean done = false;
+ while (!done) {
+ int eventType = parser.next();
+ if (eventType == XmlPullParser.START_TAG) {
+ if (parser.getName().equals("agentJID")) {
+ agentJID = parser.nextText();
+ }
+ else if (parser.getName().equals("joinTime")) {
+ try {
+ joinTime = UTC_FORMAT.parse(parser.nextText());
+ } catch (ParseException e) {}
+ }
+ else if (parser.getName().equals("leftTime")) {
+ try {
+ leftTime = UTC_FORMAT.parse(parser.nextText());
+ } catch (ParseException e) {}
+ }
+ else if (parser.getName().equals("agent")) {
+ agentJID = null;
+ joinTime = null;
+ leftTime = null;
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if (parser.getName().equals("agents")) {
+ done = true;
+ }
+ else if (parser.getName().equals("agent")) {
+ agents.add(new Transcripts.AgentDetail(agentJID, joinTime, leftTime));
+ }
+ }
+ }
+ return agents;
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/UserID.java b/src/org/jivesoftware/smackx/workgroup/packet/UserID.java
new file mode 100644
index 0000000..8bf4589
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/UserID.java
@@ -0,0 +1,77 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+public class UserID implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "user";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
+
+ private String userID;
+
+ public UserID(String userID) {
+ this.userID = userID;
+ }
+
+ public String getUserID() {
+ return this.userID;
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" ");
+ buf.append("id=\"").append(this.getUserID());
+ buf.append("\"/>");
+
+ return buf.toString();
+ }
+
+ public static class Provider implements PacketExtensionProvider {
+
+ public PacketExtension parseExtension(XmlPullParser parser) throws Exception {
+ String userID = parser.getAttributeValue("", "id");
+
+ // Advance to end of extension.
+ parser.next();
+
+ return new UserID(userID);
+ }
+ }
+}
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/WorkgroupInformation.java b/src/org/jivesoftware/smackx/workgroup/packet/WorkgroupInformation.java
new file mode 100644
index 0000000..b0ea447
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/WorkgroupInformation.java
@@ -0,0 +1,86 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smack.packet.PacketExtension;
+import org.jivesoftware.smack.provider.PacketExtensionProvider;
+import org.xmlpull.v1.XmlPullParser;
+
+/**
+ * A packet extension that contains information about the user and agent in a
+ * workgroup chat. The packet extension is attached to group chat invitations.
+ */
+public class WorkgroupInformation implements PacketExtension {
+
+ /**
+ * Element name of the packet extension.
+ */
+ public static final String ELEMENT_NAME = "workgroup";
+
+ /**
+ * Namespace of the packet extension.
+ */
+ public static final String NAMESPACE = "http://jabber.org/protocol/workgroup";
+
+ private String workgroupJID;
+
+ public WorkgroupInformation(String workgroupJID){
+ this.workgroupJID = workgroupJID;
+ }
+
+ public String getWorkgroupJID() {
+ return workgroupJID;
+ }
+
+ public String getElementName() {
+ return ELEMENT_NAME;
+ }
+
+ public String getNamespace() {
+ return NAMESPACE;
+ }
+
+ public String toXML() {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append('<').append(ELEMENT_NAME);
+ buf.append(" jid=\"").append(getWorkgroupJID()).append("\"");
+ buf.append(" xmlns=\"").append(NAMESPACE).append("\" />");
+
+ return buf.toString();
+ }
+
+ public static class Provider implements PacketExtensionProvider {
+
+ /**
+ * PacketExtensionProvider implementation
+ */
+ public PacketExtension parseExtension (XmlPullParser parser)
+ throws Exception {
+ String workgroupJID = parser.getAttributeValue("", "jid");
+
+ // since this is a start and end tag, and we arrive on the start, this should guarantee
+ // we leave on the end
+ parser.next();
+
+ return new WorkgroupInformation(workgroupJID);
+ }
+ }
+} \ No newline at end of file