mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-06 05:01:12 +01:00
Code out of date, new version already in use in another project.
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2459 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
7a7008a6c7
commit
94f7bc5103
23 changed files with 0 additions and 3489 deletions
|
|
@ -1,376 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.*;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.jivesoftware.smack.provider.ProviderManager;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.jivesoftware.smackx.workgroup.agent.Agent;
|
||||
|
||||
/**
|
||||
* Packet extension implementation for agent status. Information about each agent includes
|
||||
* their JID, current chat count, max chats they can handle, and their presence in the
|
||||
* workgroup.
|
||||
*
|
||||
* @author Matt Tucker
|
||||
*/
|
||||
public class AgentStatus implements PacketExtension {
|
||||
|
||||
/**
|
||||
* Element name of the packet extension.
|
||||
*/
|
||||
public static final String ELEMENT_NAME = "agent-status";
|
||||
|
||||
/**
|
||||
* Namespace of the packet extension.
|
||||
*/
|
||||
public static final String NAMESPACE = "xmpp:workgroup";
|
||||
|
||||
private Set agents;
|
||||
|
||||
AgentStatus() {
|
||||
agents = new HashSet();
|
||||
}
|
||||
|
||||
void addAgent(Agent agent) {
|
||||
synchronized (agents) {
|
||||
agents.add(agent);
|
||||
}
|
||||
}
|
||||
|
||||
public int getAgentCount() {
|
||||
synchronized (agents) {
|
||||
return agents.size();
|
||||
}
|
||||
}
|
||||
|
||||
public Set getAgents() {
|
||||
synchronized (agents) {
|
||||
return Collections.unmodifiableSet(agents);
|
||||
}
|
||||
}
|
||||
|
||||
public String getElementName() {
|
||||
return ELEMENT_NAME;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
public String toXML () {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\">");
|
||||
|
||||
synchronized (agents) {
|
||||
for (Iterator i=agents.iterator(); i.hasNext(); ) {
|
||||
Agent agent = (Agent)i.next();
|
||||
buf.append("<agent jid=\"").append(agent.getUser()).append("\">");
|
||||
|
||||
if (agent.getCurrentChats() != -1) {
|
||||
buf.append("<current-chats>");
|
||||
buf.append(agent.getCurrentChats());
|
||||
buf.append("</current-chats>");
|
||||
}
|
||||
|
||||
if (agent.getMaxChats() != -1) {
|
||||
buf.append("<max-chats>").append(agent.getMaxChats()).append("</max-chats>");
|
||||
}
|
||||
|
||||
if (agent.getPresence() != null) {
|
||||
buf.append(agent.getPresence().toXML());
|
||||
}
|
||||
|
||||
buf.append("</agent>");
|
||||
}
|
||||
}
|
||||
|
||||
buf.append("</").append(ELEMENT_NAME).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();
|
||||
|
||||
int eventType = parser.getEventType();
|
||||
if (eventType != XmlPullParser.START_TAG) {
|
||||
throw new IllegalStateException("Parser not in proper position, or bad XML.");
|
||||
}
|
||||
|
||||
eventType = parser.next();
|
||||
|
||||
while ((eventType == XmlPullParser.START_TAG)
|
||||
&& ("agent".equals(parser.getName()))) {
|
||||
String jid = null;
|
||||
int currentChats = -1;
|
||||
int maxChats = -1;
|
||||
Presence presence = null;
|
||||
|
||||
jid = parser.getAttributeValue("", "jid");
|
||||
if (jid == null) {
|
||||
// throw exception
|
||||
}
|
||||
|
||||
eventType = parser.next();
|
||||
String elementName = parser.getName();
|
||||
while ((eventType != XmlPullParser.END_TAG) || (!"agent".equals(elementName))) {
|
||||
if ("current-chats".equals(elementName)) {
|
||||
currentChats = Integer.parseInt(parser.nextText());
|
||||
parser.next();
|
||||
}
|
||||
else if ("max-chats".equals(elementName)) {
|
||||
maxChats = Integer.parseInt(parser.nextText());
|
||||
parser.next();
|
||||
}
|
||||
else if ("presence".equals(elementName)) {
|
||||
presence = parsePresence(parser);
|
||||
parser.next();
|
||||
}
|
||||
|
||||
eventType = parser.getEventType();
|
||||
elementName = parser.getName();
|
||||
|
||||
if (eventType != XmlPullParser.END_TAG) {
|
||||
// throw exception
|
||||
}
|
||||
}
|
||||
|
||||
Agent agent = new Agent(jid, currentChats, maxChats, presence);
|
||||
agentStatus.addAgent(agent);
|
||||
|
||||
eventType = parser.next();
|
||||
}
|
||||
|
||||
if (eventType != XmlPullParser.END_TAG) {
|
||||
// throw exception -- PENDING logic verify: useless case?
|
||||
}
|
||||
|
||||
return agentStatus;
|
||||
}
|
||||
|
||||
|
||||
// Note: all methods below are copied directly from the Smack PacketReader class
|
||||
// and represent all methods that are needed for presence packet parsing.
|
||||
// Unfortunately, there is no elegant way to pass of presence packet parsing to
|
||||
// Smack core when the presence packet context is a non-standard one such as in
|
||||
// the agent-status protocol. Future Smack changes may change this situation,
|
||||
// which would allow us to delete the code copy.
|
||||
|
||||
/**
|
||||
* Parses a presence packet.
|
||||
*
|
||||
* @param parser the XML parser, positioned at the start of a presence packet.
|
||||
* @return an Presence object.
|
||||
* @throws Exception if an exception occurs while parsing the packet.
|
||||
*/
|
||||
private Presence parsePresence(XmlPullParser parser) throws Exception {
|
||||
Presence.Type type = Presence.Type.fromString(parser.getAttributeValue("", "type"));
|
||||
|
||||
Presence presence = new Presence(type);
|
||||
presence.setTo(parser.getAttributeValue("", "to"));
|
||||
presence.setFrom(parser.getAttributeValue("", "from"));
|
||||
presence.setPacketID(parser.getAttributeValue("", "id"));
|
||||
|
||||
// Parse sub-elements
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String elementName = parser.getName();
|
||||
String namespace = parser.getNamespace();
|
||||
if (elementName.equals("status")) {
|
||||
presence.setStatus(parser.nextText());
|
||||
}
|
||||
else if (elementName.equals("priority")) {
|
||||
try {
|
||||
int priority = Integer.parseInt(parser.nextText());
|
||||
presence.setPriority(priority);
|
||||
}
|
||||
catch (NumberFormatException nfe) { }
|
||||
}
|
||||
else if (elementName.equals("show")) {
|
||||
presence.setMode(Presence.Mode.fromString(parser.nextText()));
|
||||
}
|
||||
else if (elementName.equals("error")) {
|
||||
presence.setError(parseError(parser));
|
||||
}
|
||||
// Otherwise, it must be a packet extension.
|
||||
else {
|
||||
presence.addExtension(parsePacketExtension(elementName, namespace, parser));
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals("presence")) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return presence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a packet extension sub-packet.
|
||||
*
|
||||
* @param elementName the XML element name of the packet extension.
|
||||
* @param namespace the XML namespace of the packet extension.
|
||||
* @param parser the XML parser, positioned at the starting element of the extension.
|
||||
* @return a PacketExtension.
|
||||
* @throws Exception if a parsing error occurs.
|
||||
*/
|
||||
private PacketExtension parsePacketExtension(String elementName, String namespace,
|
||||
XmlPullParser parser) throws Exception
|
||||
{
|
||||
// See if a provider is registered to handle the extension.
|
||||
Object provider = ProviderManager.getExtensionProvider(elementName, namespace);
|
||||
if (provider != null) {
|
||||
if (provider instanceof PacketExtensionProvider) {
|
||||
return ((PacketExtensionProvider)provider).parseExtension(parser);
|
||||
}
|
||||
else if (provider instanceof Class) {
|
||||
return (PacketExtension)parseWithIntrospection(
|
||||
elementName, (Class)provider, parser);
|
||||
}
|
||||
}
|
||||
// No providers registered, so use a default extension.
|
||||
DefaultPacketExtension extension = new DefaultPacketExtension(elementName, namespace);
|
||||
boolean done = false;
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = parser.getName();
|
||||
// If an empty element, set the value with the empty string.
|
||||
if (parser.isEmptyElementTag()) {
|
||||
extension.setValue(name,"");
|
||||
}
|
||||
// Otherwise, get the the element text.
|
||||
else {
|
||||
eventType = parser.next();
|
||||
if (eventType == XmlPullParser.TEXT) {
|
||||
String value = parser.getText();
|
||||
extension.setValue(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(elementName)) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return extension;
|
||||
}
|
||||
|
||||
private Object parseWithIntrospection(String elementName,
|
||||
Class objectClass, XmlPullParser parser) throws Exception
|
||||
{
|
||||
boolean done = false;
|
||||
Object object = objectClass.newInstance();
|
||||
while (!done) {
|
||||
int eventType = parser.next();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
String name = parser.getName();
|
||||
String stringValue = parser.nextText();
|
||||
PropertyDescriptor descriptor = new PropertyDescriptor(name, objectClass);
|
||||
// Load the class type of the property.
|
||||
Class propertyType = descriptor.getPropertyType();
|
||||
// Get the value of the property by converting it from a
|
||||
// String to the correct object type.
|
||||
Object value = decode(propertyType, stringValue);
|
||||
// Set the value of the bean.
|
||||
descriptor.getWriteMethod().invoke(object, new Object[] { value });
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if (parser.getName().equals(elementName)) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes a String into an object of the specified type. If the object
|
||||
* type is not supported, null will be returned.
|
||||
*
|
||||
* @param type the type of the property.
|
||||
* @param value the encode String value to decode.
|
||||
* @return the String value decoded into the specified type.
|
||||
*/
|
||||
private static Object decode(Class type, String value) throws Exception {
|
||||
if (type.getName().equals("java.lang.String")) {
|
||||
return value;
|
||||
}
|
||||
if (type.getName().equals("boolean")) {
|
||||
return Boolean.valueOf(value);
|
||||
}
|
||||
if (type.getName().equals("int")) {
|
||||
return Integer.valueOf(value);
|
||||
}
|
||||
if (type.getName().equals("long")) {
|
||||
return Long.valueOf(value);
|
||||
}
|
||||
if (type.getName().equals("float")) {
|
||||
return Float.valueOf(value);
|
||||
}
|
||||
if (type.getName().equals("double")) {
|
||||
return Double.valueOf(value);
|
||||
}
|
||||
if (type.getName().equals("java.lang.Class")) {
|
||||
return Class.forName(value);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses error sub-packets.
|
||||
*
|
||||
* @param parser the XML parser.
|
||||
* @return an error sub-packet.
|
||||
* @throws Exception if an exception occurs while parsing the packet.
|
||||
*/
|
||||
private XMPPError parseError(XmlPullParser parser) throws Exception {
|
||||
String errorCode = null;
|
||||
for (int i=0; i<parser.getAttributeCount(); i++) {
|
||||
if (parser.getAttributeName(i).equals("code")) {
|
||||
errorCode = parser.getAttributeValue("", "code");
|
||||
}
|
||||
}
|
||||
String message = parser.nextText();
|
||||
while (true) {
|
||||
if (parser.getEventType() == XmlPullParser.END_TAG && parser.getName().equals("error")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new XMPPError(Integer.parseInt(errorCode), message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,76 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.*;
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
StringBuffer buf = new StringBuffer("<depart-queue xmlns=\"xmpp:workgroup\"");
|
||||
|
||||
if (this.user != null) {
|
||||
buf.append("><jid>").append(this.user).append("</jid></depart-queue>");
|
||||
}
|
||||
else {
|
||||
buf.append("/>");
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.util.MetaDataUtils;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
||||
/**
|
||||
* MetaData packet extension.
|
||||
*/
|
||||
public class MetaData implements PacketExtension {
|
||||
|
||||
/**
|
||||
* Element name of the packet extension.
|
||||
*/
|
||||
public static final String ELEMENT_NAME = "metadata";
|
||||
|
||||
/**
|
||||
* Namespace of the packet extension.
|
||||
*/
|
||||
public static final String NAMESPACE = "http://www.jivesoftware.com/workgroup/metadata";
|
||||
|
||||
private Map metaData;
|
||||
|
||||
public MetaData(Map metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the Map of metadata contained by this instance
|
||||
*/
|
||||
public Map getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public String getElementName() {
|
||||
return ELEMENT_NAME;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
public String toXML() {
|
||||
return MetaDataUtils.encodeMetaData(this.getMetaData());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.*;
|
||||
|
||||
import org.jivesoftware.smackx.workgroup.*;
|
||||
import org.jivesoftware.smackx.workgroup.util.MetaDataUtils;
|
||||
|
||||
import org.jivesoftware.smack.packet.*;
|
||||
import org.jivesoftware.smack.provider.*;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
* 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 uid = null;
|
||||
String sessionID = null;
|
||||
int timeout = -1;
|
||||
boolean done = false;
|
||||
Map metaData = new HashMap();
|
||||
|
||||
if (eventType != XmlPullParser.START_TAG) {
|
||||
// throw exception
|
||||
}
|
||||
|
||||
uid = parser.getAttributeValue("", "jid");
|
||||
if (uid == null) {
|
||||
// throw exception
|
||||
}
|
||||
|
||||
parser.nextTag();
|
||||
while (!done) {
|
||||
eventType = parser.getEventType();
|
||||
|
||||
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("", "session");
|
||||
|
||||
parser.nextTag();
|
||||
}
|
||||
}
|
||||
else if (eventType == XmlPullParser.END_TAG) {
|
||||
if ("offer".equals(parser.getName())) {
|
||||
done = true;
|
||||
}
|
||||
else {
|
||||
parser.nextTag();
|
||||
}
|
||||
}
|
||||
else {
|
||||
parser.nextTag();
|
||||
}
|
||||
}
|
||||
|
||||
OfferRequestPacket offerRequest = new OfferRequestPacket(uid, timeout, metaData, sessionID);
|
||||
offerRequest.setType(IQ.Type.SET);
|
||||
|
||||
return offerRequest;
|
||||
}
|
||||
|
||||
public static class OfferRequestPacket extends IQ {
|
||||
|
||||
private int timeout;
|
||||
private String userID;
|
||||
private Map metaData;
|
||||
private String sessionID;
|
||||
|
||||
public OfferRequestPacket(String uid, int timeout, Map metaData, String sID) {
|
||||
this.userID = uid;
|
||||
this.timeout = timeout;
|
||||
this.metaData = metaData;
|
||||
this.sessionID = sID;
|
||||
}
|
||||
|
||||
public String getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session id which will be associated with the customer for whom this offer
|
||||
* is extended, or null if the offer did not contain one.
|
||||
*
|
||||
* @return the session id associated to the customer
|
||||
*/
|
||||
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 Map getMetaData() {
|
||||
return this.metaData;
|
||||
}
|
||||
|
||||
public String getChildElementXML () {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
buf.append("<offer xmlns=\"xmpp:workgroup\" jid=\"").append(userID).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.encodeMetaData(metaData));
|
||||
}
|
||||
|
||||
buf.append("</offer>");
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.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 uid = parser.getAttributeValue("", "jid");
|
||||
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("", "session");
|
||||
}
|
||||
else if ((eventType == XmlPullParser.END_TAG)
|
||||
&& parser.getName().equals("offer-revoke")) {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
return new OfferRevokePacket(uid, reason, sessionID);
|
||||
}
|
||||
|
||||
public class OfferRevokePacket extends IQ {
|
||||
|
||||
protected String userID;
|
||||
protected String sessionID;
|
||||
protected String reason;
|
||||
|
||||
public OfferRevokePacket (String uid, String cause, String sid) {
|
||||
this.userID = uid;
|
||||
this.reason = cause;
|
||||
this.sessionID = sid;
|
||||
}
|
||||
|
||||
public String getUserID () {
|
||||
return this.userID;
|
||||
}
|
||||
|
||||
public String getReason () {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
public String getSessionID () {
|
||||
return this.sessionID;
|
||||
}
|
||||
|
||||
public String getChildElementXML () {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("<offer-revoke xmlns=\"xmpp:workgroup\" jid=\"").append(userID).append("\">");
|
||||
if (reason != null) {
|
||||
buf.append("<reason>").append(reason).append("</reason>");
|
||||
}
|
||||
buf.append("</offer-revoke>");
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,197 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.util.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* 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 = "xmpp: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() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,160 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.util.Date;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.jivesoftware.smackx.workgroup.agent.WorkgroupQueue;
|
||||
|
||||
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 = "xmpp: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 () {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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 IQ packet that encapsulates both types of workgroup queue
|
||||
* status notifications -- position updates, and estimated time
|
||||
* left in the queue updates.
|
||||
*/
|
||||
public class QueueUpdate extends IQ {
|
||||
|
||||
/**
|
||||
* Element name of the packet extension.
|
||||
*/
|
||||
public static final String ELEMENT_NAME = "queue-status";
|
||||
|
||||
/**
|
||||
* Namespace of the packet extension.
|
||||
*/
|
||||
public static final String NAMESPACE = "xmpp: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 getChildElementXML () {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
buf.append("<queue-status xmlns=\"xmpp:workgroup\">");
|
||||
if (position != -1) {
|
||||
buf.append("<queue-position>").append(position).append("</queue-position>");
|
||||
}
|
||||
else if (remainingTime != -1) {
|
||||
buf.append("<queue-time>").append(remainingTime).append("</queue-time>");
|
||||
}
|
||||
buf.append("</queue-status>");
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public static class Provider implements IQProvider {
|
||||
|
||||
public IQ parseIQ(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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.Date;
|
||||
|
||||
/**
|
||||
* An immutable class which wraps up customer-in-queue data return from the server; depending on
|
||||
* the type of information dispatched from the server, not all information will be available in
|
||||
* any given instance.
|
||||
*
|
||||
* @author loki der quaeler
|
||||
*/
|
||||
public class QueueUser {
|
||||
|
||||
private String userID;
|
||||
|
||||
private int queuePosition;
|
||||
private int estimatedTime;
|
||||
private Date joinDate;
|
||||
|
||||
/**
|
||||
* @param uid the user jid of the customer in the queue
|
||||
* @param position the position customer sits in the queue
|
||||
* @param time the estimate of how much longer the customer will be in the queue in seconds
|
||||
* @param joinedAt the timestamp of when the customer entered the queue
|
||||
*/
|
||||
public QueueUser (String uid, int position, int time, Date joinedAt) {
|
||||
super();
|
||||
|
||||
this.userID = uid;
|
||||
this.queuePosition = position;
|
||||
this.estimatedTime = time;
|
||||
this.joinDate = joinedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the user jid of the customer in the queue
|
||||
*/
|
||||
public String getUserID () {
|
||||
return this.userID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the position in the queue at which the customer sits, or -1 if the update which
|
||||
* this instance embodies is only a time update instead
|
||||
*/
|
||||
public int getQueuePosition () {
|
||||
return this.queuePosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the estimated time remaining of the customer in the queue in seconds, or -1 if
|
||||
* if the update which this instance embodies is only a position update instead
|
||||
*/
|
||||
public int getEstimatedRemainingTime () {
|
||||
return this.estimatedTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timestamp of when this customer entered the queue, or null if the server did not
|
||||
* provide this information
|
||||
*/
|
||||
public Date getQueueJoinTimestamp () {
|
||||
return this.joinDate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,78 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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 = "jive";
|
||||
|
||||
/**
|
||||
* Namespace of the packet extension.
|
||||
*/
|
||||
public static final String NAMESPACE = "http://jivesoftware.com/protocol/workgroup";
|
||||
|
||||
private String sessionID;
|
||||
|
||||
protected 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() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
buf.append("<").append(ELEMENT_NAME).append(" xmlns=\"").append(NAMESPACE).append("\" ");
|
||||
buf.append("session=\"").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("", "session");
|
||||
|
||||
// Advance to end of extension.
|
||||
parser.next();
|
||||
|
||||
return new SessionID(sessionID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
/**
|
||||
* $RCSfile$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* Copyright 2003-2004 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 = "xmpp:workgroup";
|
||||
|
||||
private String userID;
|
||||
private String agentID;
|
||||
|
||||
protected WorkgroupInformation(String userID, String agentID) {
|
||||
this.userID = userID;
|
||||
this.agentID = agentID;
|
||||
}
|
||||
|
||||
public String getUserID() {
|
||||
return userID;
|
||||
}
|
||||
|
||||
public String getAgentID() {
|
||||
return agentID;
|
||||
}
|
||||
|
||||
public String getElementName() {
|
||||
return ELEMENT_NAME;
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
return NAMESPACE;
|
||||
}
|
||||
|
||||
public String toXML() {
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
buf.append('<').append(ELEMENT_NAME);
|
||||
buf.append(" user=\"").append(userID).append("\"");
|
||||
buf.append(" agent=\"").append(agentID);
|
||||
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 user = parser.getAttributeValue("", "user");
|
||||
String agent = parser.getAttributeValue("", "agent");
|
||||
|
||||
// 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(user, agent);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue