aboutsummaryrefslogtreecommitdiff
path: root/src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java
diff options
context:
space:
mode:
authorShuyi Chen <shuyichen@google.com>2013-05-22 14:51:55 -0700
committerShuyi Chen <shuyichen@google.com>2013-05-22 17:19:30 -0700
commitd7955ce24d294fb2014c59d11fca184471056f44 (patch)
treee260500b0b7639127038495d46a0ad6dcbb6d96c /src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java
parent8f4ce9ea0de51fee918bffe19c434612d6bbb2d7 (diff)
downloadsmack-master.tar.gz
Add android smack source.HEADandroid-wear-5.0.0_r1android-sdk-4.4.2_r1.0.1android-sdk-4.4.2_r1android-l-preview_r2android-cts-5.1_r9android-cts-5.1_r8android-cts-5.1_r7android-cts-5.1_r6android-cts-5.1_r5android-cts-5.1_r4android-cts-5.1_r3android-cts-5.1_r28android-cts-5.1_r27android-cts-5.1_r26android-cts-5.1_r25android-cts-5.1_r24android-cts-5.1_r23android-cts-5.1_r22android-cts-5.1_r21android-cts-5.1_r20android-cts-5.1_r2android-cts-5.1_r19android-cts-5.1_r18android-cts-5.1_r17android-cts-5.1_r16android-cts-5.1_r15android-cts-5.1_r14android-cts-5.1_r13android-cts-5.1_r10android-cts-5.1_r1android-cts-5.0_r9android-cts-5.0_r8android-cts-5.0_r7android-cts-5.0_r6android-cts-5.0_r5android-cts-5.0_r4android-cts-5.0_r3android-cts-4.4_r4android-cts-4.4_r1android-5.1.1_r9android-5.1.1_r8android-5.1.1_r7android-5.1.1_r6android-5.1.1_r5android-5.1.1_r4android-5.1.1_r38android-5.1.1_r37android-5.1.1_r36android-5.1.1_r35android-5.1.1_r34android-5.1.1_r33android-5.1.1_r30android-5.1.1_r3android-5.1.1_r29android-5.1.1_r28android-5.1.1_r26android-5.1.1_r25android-5.1.1_r24android-5.1.1_r23android-5.1.1_r22android-5.1.1_r20android-5.1.1_r2android-5.1.1_r19android-5.1.1_r18android-5.1.1_r17android-5.1.1_r16android-5.1.1_r15android-5.1.1_r14android-5.1.1_r13android-5.1.1_r12android-5.1.1_r10android-5.1.1_r1android-5.1.0_r5android-5.1.0_r4android-5.1.0_r3android-5.1.0_r1android-5.0.2_r3android-5.0.2_r1android-5.0.1_r1android-5.0.0_r7android-5.0.0_r6android-5.0.0_r5.1android-5.0.0_r5android-5.0.0_r4android-5.0.0_r3android-5.0.0_r2android-5.0.0_r1android-4.4w_r1android-4.4_r1.2.0.1android-4.4_r1.2android-4.4_r1.1.0.1android-4.4_r1.1android-4.4_r1.0.1android-4.4_r1android-4.4_r0.9android-4.4_r0.8android-4.4_r0.7android-4.4.4_r2.0.1android-4.4.4_r2android-4.4.4_r1.0.1android-4.4.4_r1android-4.4.3_r1.1.0.1android-4.4.3_r1.1android-4.4.3_r1.0.1android-4.4.3_r1android-4.4.2_r2.0.1android-4.4.2_r2android-4.4.2_r1.0.1android-4.4.2_r1android-4.4.1_r1.0.1android-4.4.1_r1android-4.3_r3.1android-4.3_r3android-4.3_r2.3android-4.3_r2.2android-4.3_r2.1android-4.3_r2android-4.3_r1.1android-4.3_r1android-4.3_r0.9.1android-4.3_r0.9android-4.3.1_r1tools_r22.2mastermainlollipop-wear-releaselollipop-releaselollipop-mr1-wfc-releaselollipop-mr1-releaselollipop-mr1-fi-releaselollipop-mr1-devlollipop-mr1-cts-releaselollipop-devlollipop-cts-releasel-previewkitkat-wearkitkat-releasekitkat-mr2.2-releasekitkat-mr2.1-releasekitkat-mr2-releasekitkat-mr1.1-releasekitkat-mr1-releasekitkat-devkitkat-cts-releasekitkat-cts-devjb-mr2.0.0-releasejb-mr2.0-releasejb-mr2-releasejb-mr2-devidea133-weekly-releaseidea133
Change-Id: I49ce97136c17173c4ae3965c694af6e7bc49897d
Diffstat (limited to 'src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java')
-rw-r--r--src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java211
1 files changed, 211 insertions, 0 deletions
diff --git a/src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java b/src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java
new file mode 100644
index 0000000..8f56b78
--- /dev/null
+++ b/src/org/jivesoftware/smackx/workgroup/packet/OfferRequestProvider.java
@@ -0,0 +1,211 @@
+/**
+ * $Revision$
+ * $Date$
+ *
+ * Copyright 2003-2007 Jive Software.
+ *
+ * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jivesoftware.smackx.workgroup.packet;
+
+import org.jivesoftware.smackx.workgroup.MetaData;
+import org.jivesoftware.smackx.workgroup.agent.InvitationRequest;
+import org.jivesoftware.smackx.workgroup.agent.OfferContent;
+import org.jivesoftware.smackx.workgroup.agent.TransferRequest;
+import org.jivesoftware.smackx.workgroup.agent.UserRequest;
+import org.jivesoftware.smackx.workgroup.util.MetaDataUtils;
+import org.jivesoftware.smack.packet.IQ;
+import org.jivesoftware.smack.provider.IQProvider;
+import org.jivesoftware.smack.util.PacketParserUtils;
+import org.xmlpull.v1.XmlPullParser;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * An IQProvider for agent offer requests.
+ *
+ * @author loki der quaeler
+ */
+public class OfferRequestProvider implements IQProvider {
+
+ public OfferRequestProvider() {
+ }
+
+ public IQ parseIQ(XmlPullParser parser) throws Exception {
+ int eventType = parser.getEventType();
+ String sessionID = null;
+ int timeout = -1;
+ OfferContent content = null;
+ boolean done = false;
+ Map<String, List<String>> metaData = new HashMap<String, List<String>>();
+
+ if (eventType != XmlPullParser.START_TAG) {
+ // throw exception
+ }
+
+ String userJID = parser.getAttributeValue("", "jid");
+ // Default userID to the JID.
+ String userID = userJID;
+
+ while (!done) {
+ eventType = parser.next();
+
+ if (eventType == XmlPullParser.START_TAG) {
+ String elemName = parser.getName();
+
+ if ("timeout".equals(elemName)) {
+ timeout = Integer.parseInt(parser.nextText());
+ }
+ else if (MetaData.ELEMENT_NAME.equals(elemName)) {
+ metaData = MetaDataUtils.parseMetaData(parser);
+ }
+ else if (SessionID.ELEMENT_NAME.equals(elemName)) {
+ sessionID = parser.getAttributeValue("", "id");
+ }
+ else if (UserID.ELEMENT_NAME.equals(elemName)) {
+ userID = parser.getAttributeValue("", "id");
+ }
+ else if ("user-request".equals(elemName)) {
+ content = UserRequest.getInstance();
+ }
+ else if (RoomInvitation.ELEMENT_NAME.equals(elemName)) {
+ RoomInvitation invitation = (RoomInvitation) PacketParserUtils
+ .parsePacketExtension(RoomInvitation.ELEMENT_NAME, RoomInvitation.NAMESPACE, parser);
+ content = new InvitationRequest(invitation.getInviter(), invitation.getRoom(),
+ invitation.getReason());
+ }
+ else if (RoomTransfer.ELEMENT_NAME.equals(elemName)) {
+ RoomTransfer transfer = (RoomTransfer) PacketParserUtils
+ .parsePacketExtension(RoomTransfer.ELEMENT_NAME, RoomTransfer.NAMESPACE, parser);
+ content = new TransferRequest(transfer.getInviter(), transfer.getRoom(), transfer.getReason());
+ }
+ }
+ else if (eventType == XmlPullParser.END_TAG) {
+ if ("offer".equals(parser.getName())) {
+ done = true;
+ }
+ }
+ }
+
+ OfferRequestPacket offerRequest =
+ new OfferRequestPacket(userJID, userID, timeout, metaData, sessionID, content);
+ offerRequest.setType(IQ.Type.SET);
+
+ return offerRequest;
+ }
+
+ public static class OfferRequestPacket extends IQ {
+
+ private int timeout;
+ private String userID;
+ private String userJID;
+ private Map<String, List<String>> metaData;
+ private String sessionID;
+ private OfferContent content;
+
+ public OfferRequestPacket(String userJID, String userID, int timeout, Map<String, List<String>> metaData,
+ String sessionID, OfferContent content)
+ {
+ this.userJID = userJID;
+ this.userID = userID;
+ this.timeout = timeout;
+ this.metaData = metaData;
+ this.sessionID = sessionID;
+ this.content = content;
+ }
+
+ /**
+ * Returns the userID, which is either the same as the userJID or a special
+ * value that the user provided as part of their "join queue" request.
+ *
+ * @return the user ID.
+ */
+ public String getUserID() {
+ return userID;
+ }
+
+ /**
+ * The JID of the user that made the "join queue" request.
+ *
+ * @return the user JID.
+ */
+ public String getUserJID() {
+ return userJID;
+ }
+
+ /**
+ * Returns the session ID associated with the request and ensuing chat. If the offer
+ * does not contain a session ID, <tt>null</tt> will be returned.
+ *
+ * @return the session id associated with the request.
+ */
+ public String getSessionID() {
+ return sessionID;
+ }
+
+ /**
+ * Returns the number of seconds the agent has to accept the offer before
+ * it times out.
+ *
+ * @return the offer timeout (in seconds).
+ */
+ public int getTimeout() {
+ return this.timeout;
+ }
+
+ public OfferContent getContent() {
+ return content;
+ }
+
+ /**
+ * Returns any meta-data associated with the offer.
+ *
+ * @return meta-data associated with the offer.
+ */
+ public Map<String, List<String>> getMetaData() {
+ return this.metaData;
+ }
+
+ public String getChildElementXML () {
+ StringBuilder buf = new StringBuilder();
+
+ buf.append("<offer xmlns=\"http://jabber.org/protocol/workgroup\" jid=\"").append(userJID).append("\">");
+ buf.append("<timeout>").append(timeout).append("</timeout>");
+
+ if (sessionID != null) {
+ buf.append('<').append(SessionID.ELEMENT_NAME);
+ buf.append(" session=\"");
+ buf.append(getSessionID()).append("\" xmlns=\"");
+ buf.append(SessionID.NAMESPACE).append("\"/>");
+ }
+
+ if (metaData != null) {
+ buf.append(MetaDataUtils.serializeMetaData(metaData));
+ }
+
+ if (userID != null) {
+ buf.append('<').append(UserID.ELEMENT_NAME);
+ buf.append(" id=\"");
+ buf.append(userID).append("\" xmlns=\"");
+ buf.append(UserID.NAMESPACE).append("\"/>");
+ }
+
+ buf.append("</offer>");
+
+ return buf.toString();
+ }
+ }
+}