Search in sources :

Example 1 with OfferContent

use of org.jivesoftware.smackx.workgroup.agent.OfferContent in project Smack by igniterealtime.

the class OfferRequestProvider method parse.

// FIXME It seems because OfferRequestPacket is also defined here, we can
// not add it as generic to the provider, the provider and the packet should
// be split, but since this is legacy code, I don't think that this will
// happen anytime soon.
@Override
public OfferRequestPacket parse(XmlPullParser parser, int initialDepth) 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
    }
    Jid userJID = ParserUtils.getJidAttribute(parser);
    // Default userID to the JID.
    Jid 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 = ParserUtils.getJidAttribute(parser, "id");
            } else if ("user-request".equals(elemName)) {
                content = UserRequest.getInstance();
            } else if (RoomInvitation.ELEMENT_NAME.equals(elemName)) {
                RoomInvitation invitation = (RoomInvitation) PacketParserUtils.parseExtensionElement(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.parseExtensionElement(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;
}
Also used : Jid(org.jxmpp.jid.Jid) HashMap(java.util.HashMap) InvitationRequest(org.jivesoftware.smackx.workgroup.agent.InvitationRequest) TransferRequest(org.jivesoftware.smackx.workgroup.agent.TransferRequest) OfferContent(org.jivesoftware.smackx.workgroup.agent.OfferContent) List(java.util.List)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 InvitationRequest (org.jivesoftware.smackx.workgroup.agent.InvitationRequest)1 OfferContent (org.jivesoftware.smackx.workgroup.agent.OfferContent)1 TransferRequest (org.jivesoftware.smackx.workgroup.agent.TransferRequest)1 Jid (org.jxmpp.jid.Jid)1