/**
 * Copyright (C) 2004-2010 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.spark.plugin.ofmeet;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;

import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.util.*;
import org.jivesoftware.spark.util.log.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jxmpp.util.XmppStringUtils;

import sun.misc.BASE64Decoder;

public class ChatRoomDecorator
{
    public RolloverButton ofmeetButton;
    public ChatRoom room;


    private final String url;

    public ChatRoomDecorator(final ChatRoom room, final String url, final SparkMeetPlugin plugin)
    {
        this.room = room;
        this.url = url;

        try {
            BASE64Decoder decoder = new BASE64Decoder();
            String imageString = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAKDSURBVDhPXVM7axVBFP5m7maN5gFyJTdNEEVDUt3C/yAIKkRSidjEUsTKRyrtLSyi/gArSRfFOiBqY5UqICaRYDCvm7177+7Ozj7G70wSSJzlmzk75/WdmTMqLwq3ubKCcGQEOgjgBgKoYACq0YBrKGh+rqrh6gKqqFGVBVCUKJMexqenoba2t937qSmcu3QRmk5aN7yz4tfQGrVzkOG4ermuUBPdzT+4v7wMHYYhMg3k1JkaSJktyQyigwPsdfYRRV0keY7EWpiyRFpWMGJbVQjPDCLQSiGJe9Bxn2lI0VUYao1jcmYGDTJJow6+v3mH860xlkSGcNBOI4oPyBGgv0bKmpIiR7+wPmP7ziyuP37EWi2utK/hdZKgZwyyNEWaW29r8hJK84w0p5yRLBWWNAVRt4vVL9+w+OIlXt27i6+LHzC78BbR7i5y6gUZfRTZ0531EDlrt5VDQWS5Qd9knmJIbP1cg7HG6wViK0lFHwiDHQqms8eZTGqHDg9tdH8XG/y/PDmJG/PP8XC8hR5Pv087cfxLaEq8KEbkT8lAHpTjuIuxdhvzH5dw8+kTzDWb2NneQR3oU3aHh8hFAuQ8WSugbEjxx6fPeHbrNhbmHqDb6bA3gkM9IbapBOCtkYA7OgPeLyHBMpvD8r4HKQtN9qDXHcPbUsd7lxKopGjJR8BGRZJkiPsxqhP7/0MS0R/K9mN3dXgUY7JxNKQMqXGIOGzk04P++E382lgnQ7avZK25e4yA/0JfgggLjxN6gfhI+Srd33PDzQtoycbR4NPwmY9XGbIyl88u2CKi1VWosq5db30N4dkh35q+tRRfI7tMwImJ6MpsruZKyMussgzhxAT+AQRKd557vsR7AAAAAElFTkSuQmCC";
            byte[] imageByte = decoder.decodeBuffer(imageString);
            ImageIcon ofmeetIcon = new ImageIcon(imageByte);
            ofmeetButton = new RolloverButton(ofmeetIcon);
            ofmeetButton.setToolTipText(GraphicUtils.createToolTip("Pade Meetings"));
            final String roomId = getNode(room.getBareJid().toString());
            final String sessionID = roomId + "-" + System.currentTimeMillis();
            final String nickname = getNode(XmppStringUtils.parseBareAddress(SparkManager.getSessionManager().getJID().toString()));

            ofmeetButton.addActionListener( new ActionListener()
            {
                    public void actionPerformed(ActionEvent event)
                    {
                        String newUrl, newRoomId;

                        if ("groupchat".equals(room.getChatType().toString()))
                        {
                            newRoomId = roomId + "-" + sessionID;
                            newUrl = url + newRoomId;
                            plugin.handleClick(newUrl, room, newUrl, Message.Type.groupchat);

                        } else {
                            newRoomId = sessionID;
                            newUrl = url + newRoomId;
                            plugin.handleClick(newUrl, room, newUrl, Message.Type.chat);
                        }
                    }
            });
            room.getEditorBar().add(ofmeetButton);

        } catch (Exception e) {

            Log.error("cannot create pade meetings icon", e);
        }

    }

    public void finished()
    {
        Log.warning("ChatRoomDecorator: finished " + room.getBareJid());
    }

    private String getNode(String jid)
    {
        String node = jid;
        int pos = node.indexOf("@");

        if (pos > -1)
            node = jid.substring(0, pos);

        return node;
    }
}

@@ -2966,141 +2966,8 @@
 s();
-%0A            final String nickname = getNode(XmppStringUtils.parseBareAddress(SparkManager.getSessionManager().getJID().toString()));
 %0A%0A  

Delete usage of deprecated method.