1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-06 02:51:11 +01:00

Adding workgroup API (SMACK-185).

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7400 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Matt Tucker 2007-03-07 23:38:36 +00:00 committed by matt
parent 939feb9017
commit fe545abeae
64 changed files with 9744 additions and 0 deletions

View file

@ -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;
}
}
}

View file

@ -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 currentChats = new ArrayList();
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 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 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);
}
}
}

View file

@ -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 agents;
public AgentStatusRequest() {
agents = new HashSet();
}
public int getAgentCount() {
return agents.size();
}
public Set 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 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);
}
}
}

View file

@ -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 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();
}
/**
* 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 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 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 it=workgroups.iterator(); it.hasNext();) {
String workgroupJID = (String) 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 workgroups = new ArrayList();
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);
}
}
}

View file

@ -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();
}
}

View file

@ -0,0 +1,48 @@
/**
* $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.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 metaData = MetaDataUtils.parseMetaData(parser);
return new MetaData(metaData);
}
}

View file

@ -0,0 +1,107 @@
/**
* $RCSfile: ,v $
* $Revision: $
* $Date: $
*
* Copyright (C) 1999-2005 Jive Software. All rights reserved.
*
* This software is the proprietary information of Jive Software.
* Use is subject to license terms.
*/
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;
}
}
}

View file

@ -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);
}
}
}

View file

@ -0,0 +1,210 @@
/**
* $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.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 metaData = new HashMap();
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 metaData;
private String sessionID;
private OfferContent content;
public OfferRequestPacket(String userJID, String userID, int timeout, Map 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 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();
}
}
}

View file

@ -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();
}
}
}

View file

@ -0,0 +1,200 @@
/**
* $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 SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
/**
* The list of users in the queue.
*/
private Set users;
/**
* Creates a new QueueDetails packet
*/
private QueueDetails() {
users = new HashSet();
}
/**
* 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 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 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(DATE_FORMATTER.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 {
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 = DATE_FORMATTER.parse(parser.nextText());
}
else if( parser.getName().equals( "waitTime" ) ) {
Date wait = DATE_FORMATTER.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;
}
}
}

View file

@ -0,0 +1,158 @@
/**
* $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 SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
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(DATE_FORMATTER.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();
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((DATE_FORMATTER.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;
}
}
}

View file

@ -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);
}
}
}

View file

@ -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;
}
}
}

View file

@ -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;
}
}
}

View file

@ -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);
}
}
}

View file

@ -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 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();
}
/**
* 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 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 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 it=packets.iterator(); it.hasNext();) {
Packet packet = (Packet) it.next();
buf.append(packet.toXML());
}
buf.append("</transcript>");
return buf.toString();
}
}

View file

@ -0,0 +1,65 @@
/**
* $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.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 packets = new ArrayList();
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);
}
}

View file

@ -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;
}
}
}

View file

@ -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();
}
}
}

View file

@ -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;
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}