Handles XMPP URI Mappings

/**
     * Handles XMPP URI Mappings.
     *
     * @param arguments the arguments passed into Spark.
     */
    public void handleURIMapping(String arguments) {
        if(arguments == null){
            return;
        }
        
        if (arguments.indexOf("xmpp") == -1) {
            return;
        }

        if (arguments.indexOf(UriManager.uritypes.message.getXML()) != -1) {
            try {
                _uriManager.handleMessage(arguments);
            }
            catch (Exception e) {
                Log.error("error with ?message URI",e);
            }
        }
        else if (arguments.indexOf(UriManager.uritypes.join.getXML()) != -1) {
            try {
                _uriManager.handleConference(arguments);
            }
            catch (Exception e) {
                Log.error("error with ?join URI",e);
            }
        }
        else if (arguments.contains(UriManager.uritypes.subscribe.getXML())) {
        try {
        _uriManager.handleSubscribe(arguments);
        } catch (Exception e) {
        Log.error("error with ?subscribe URI", e);
        }
    } 
        else if (arguments.contains(UriManager.uritypes.unsubscribe.getXML())) {
        try {
        _uriManager.handleUnsubscribe(arguments);
        } catch (Exception e) {
        Log.error("error with ?subscribe URI", e);
        }
    }
        else if(arguments.contains(UriManager.uritypes.roster.getXML()))
        {
        try {
        _uriManager.handleRoster(arguments);
        } catch (Exception e) {
        Log.error("error with ?subscribe URI", e);
        }
        }
        else if (arguments.contains(UriManager.uritypes.remove.getXML()))
        {
        try {
        _uriManager.handleRemove(arguments);
        } catch (Exception e) {
        Log.error("error with ?subscribe URI", e);
        }
        }
        else if (arguments.indexOf("?") == -1) {
            // Then use the direct jid
            int index = arguments.indexOf(":");
            if (index != -1) {
                String jid = arguments.substring(index + 1);

                UserManager userManager = SparkManager.getUserManager();
                String nickname = userManager.getUserNicknameFromJID(jid);
                if (nickname == null) {
                    nickname = jid;
                }

                ChatManager chatManager = SparkManager.getChatManager();
                ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname);
                chatManager.getChatContainer().activateChatRoom(chatRoom);
            }
        }

    }

 

posted on 2013-05-24 18:09  CVT-wangxin  阅读(223)  评论(0编辑  收藏  举报

导航