⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatsettingscreator.java

📁 openfire 服务器源码下载
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/**
 * $RCSfile$
 * $Revision: 26622 $
 * $Date: 2006-01-31 20:52:54 -0800 (Tue, 31 Jan 2006) $
 *
 * Copyright (C) 1999-2008 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
 */

package org.jivesoftware.openfire.fastpath.settings.chat;

import org.jivesoftware.xmpp.workgroup.UnauthorizedException;
import org.jivesoftware.xmpp.workgroup.Workgroup;
import org.jivesoftware.xmpp.workgroup.WorkgroupManager;
import org.jivesoftware.xmpp.workgroup.utils.ModelUtil;
import com.thoughtworks.xstream.XStream;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.util.StringUtils;
import org.xmpp.component.ComponentManagerFactory;
import org.xmpp.packet.JID;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * Creates the default settings for the Web Chat UI. This includes the Web Chat UI
 * images and text settings.
 */
public class ChatSettingsCreator {

    private static final ChatSettingsCreator instance = new ChatSettingsCreator();

    /**
     * Holds the default images to use.
     */
    private final Map<KeyEnum, String> imageMap = new HashMap<KeyEnum, String>();

    /**
     * Holds the default messages to use in the web client.
     */
    private final Map<KeyEnum, String> textMap = new HashMap<KeyEnum, String>();

    /**
     * Holds the default messages to use by the chatbot.
     */
    private final Map<KeyEnum, String> botMap = new HashMap<KeyEnum, String>();

    /**
     * Holds the label to use in the Admin Console while editing the property.
     */
    private final Map<KeyEnum, String> labelMap = new HashMap<KeyEnum, String>();

    /**
     * Holds the description to use in the Admin Console while editing the property.
     */
    private final Map<String, String> descriptions = new HashMap<String, String>();

    private final ChatSettingsManager chatSettingsManager = ChatSettingsManager.getInstance();

    /**
     * Returns the unique instance of this class.
     *
     * @return instance of class
     */
    public static ChatSettingsCreator getInstance() {
        return instance;
    }

    /**
     * Setups up the individual mappings to use for default settings.
     */
    private ChatSettingsCreator() {
        // Populate Image Map
        imageMap.put(KeyEnum.online_image, "online.gif");
        labelMap.put(KeyEnum.online_image, "Online");

        imageMap.put(KeyEnum.offline_image, "offline.gif");
        labelMap.put(KeyEnum.offline_image, "Offline");

        imageMap.put(KeyEnum.title_logo_image, "logo.gif");
        labelMap.put(KeyEnum.title_logo_image, "Title Logo");

        imageMap.put(KeyEnum.powered_by_image, "poweredBy.gif");
        labelMap.put(KeyEnum.powered_by_image, "Powered By");

        imageMap.put(KeyEnum.background_image, "white_background.gif");
        labelMap.put(KeyEnum.background_image, "Background");

        imageMap.put(KeyEnum.end_button_image, "end_button.gif");
        labelMap.put(KeyEnum.end_button_image, "End Button");

        imageMap.put(KeyEnum.secure_image, "secure_button.gif");
        labelMap.put(KeyEnum.secure_image, "Secure Button");

        imageMap.put(KeyEnum.agent_typing_image, "typing_button.gif");
        labelMap.put(KeyEnum.agent_typing_image, "Agent Typing Button");

        imageMap.put(KeyEnum.send_message_image, "send_button.gif");
        labelMap.put(KeyEnum.send_message_image, "Send Message Button");

        imageMap.put(KeyEnum.send_mail_image, "send_transcript_button.gif");
        labelMap.put(KeyEnum.send_mail_image, "Send Mail Button");

        // Populate Text Map
        populateTextMap();

        // Populate Bot Map
        botMap.put(KeyEnum.welcome_message, "Welcome to the workgroup '${workgroup}'.");
        labelMap.put(KeyEnum.welcome_message, "Greetings");

        botMap.put(KeyEnum.join_question, "Would you like to join the chat, yes or no?");
        labelMap.put(KeyEnum.join_question, "Join question");

        botMap.put(KeyEnum.bye_message, "Thanks for coming. We hope to see you soon again.");
        labelMap.put(KeyEnum.bye_message, "User is leaving");

        botMap.put(KeyEnum.routing_message, "You have entered a waiting queue. An agent will be with you soon");
        labelMap.put(KeyEnum.routing_message, "User has entered a queue");

        botMap.put(KeyEnum.position_message, "Your current position in the queue is ${position}");
        labelMap.put(KeyEnum.position_message, "Inform user position in the queue");

        botMap.put(KeyEnum.departure_confirmed_message, "You have left the waiting queue");
        labelMap.put(KeyEnum.departure_confirmed_message, "User cancelled request to join or request timedout");

        botMap.put(KeyEnum.cannot_join_message, "The workgroup is closed or you are not allowed to enter");
        labelMap.put(KeyEnum.cannot_join_message, "Request to join workgroup was denied");

        botMap.put(KeyEnum.fillout_form_message, "Please, fill out this form to contact an agent");
        labelMap.put(KeyEnum.fillout_form_message, "Inform user that a form must be completed");

        botMap.put(KeyEnum.not_acceptable_message, "Invalid or unknown command. Use !help for more information");
        labelMap.put(KeyEnum.not_acceptable_message, "User sent an unknown or invalid command");

        botMap.put(KeyEnum.not_in_queue_message, "Error, you are not in the waiting queue");
        labelMap.put(KeyEnum.not_in_queue_message, "User asked for his position in the queue but he is not in the queue");

        botMap.put(KeyEnum.workgroup_closed_message, "This workgroup is currently closed");
        labelMap.put(KeyEnum.workgroup_closed_message, "Workgroup is closed");

        botMap.put(KeyEnum.send_email_question, "Do you want to receive the chat transcript by email, yes or no?");
        labelMap.put(KeyEnum.send_email_question, "Email question");

        botMap.put(KeyEnum.send_get_email_question, "Please enter your email address to receive the chat transcript");
        labelMap.put(KeyEnum.send_get_email_question, "Enter Email address");

        botMap.put(KeyEnum.invitation_sent_message, "An invitation to start a chat with an agent has been sent");
        labelMap.put(KeyEnum.invitation_sent_message, "User is being routed to an agent");

        botMap.put(KeyEnum.send_invitation_question, "Do you want to receive another room invitation, yes or no?");
        labelMap.put(KeyEnum.send_invitation_question, "Send invitation again question");

        botMap.put(KeyEnum.invitation_resent_message, "The room invitation was sent again");
        labelMap.put(KeyEnum.invitation_resent_message, "Confirmation that the invitation was sent again");

        botMap.put(KeyEnum.email_sent_message, "Transcript sent to the following email address ${email}");
        labelMap.put(KeyEnum.email_sent_message, "Email was sent to the user");

        botMap.put(KeyEnum.back_command, "!back");
        labelMap.put(KeyEnum.back_command, "Text representing the 'back' command");

        botMap.put(KeyEnum.bye_command, "!bye");
        labelMap.put(KeyEnum.bye_command, "Text representing the 'bye' command");

        botMap.put(KeyEnum.help_command, "!help");
        labelMap.put(KeyEnum.help_command, "Text representing the 'help' command");

        botMap.put(KeyEnum.position_command, "!position");
        labelMap.put(KeyEnum.position_command, "Text representing the 'position' command");

        botMap.put(KeyEnum.repeat_command, "!repeat");
        labelMap.put(KeyEnum.repeat_command, "Text representing the 'repeat' command");

        botMap.put(KeyEnum.back_help_message, "!back - Use this command to return to the previous step.");
        labelMap.put(KeyEnum.back_help_message, "Description of the 'back' command");

        botMap.put(KeyEnum.bye_help_message, "!bye - Use this command to finish the chat.");
        labelMap.put(KeyEnum.bye_help_message, "Description of the 'bye' command");

        botMap.put(KeyEnum.help_help_message, "!help - Use this command to display the list of commands.");
        labelMap.put(KeyEnum.help_help_message, "Description of the 'help' command");

        botMap.put(KeyEnum.position_help_message, "!position - Use this command to learn your position in the queue.");
        labelMap.put(KeyEnum.position_help_message, "Description of the 'position' command");

        botMap.put(KeyEnum.repeat_help_message, "!repeat - Use this command to repeat the last question.");
        labelMap.put(KeyEnum.repeat_help_message, "Description of the 'repeat' command");

        // Define image descriptions

        descriptions.put("Online", "The button to show when agents of this workgroup are online.");
        descriptions.put("Offline", "The button to show when no agents in this workgroup are available to chat or offline.");
        descriptions.put("Title Logo", "Image shown at the upper left hand corner of the client.");
        descriptions.put("Powered By", "Powered by images is shown on the right-bottom corner of the client.");
        descriptions.put("Background", "Image used in the background of the client.");
        descriptions.put("Send Message Button", "The button used in the client to send messages.");
        descriptions.put("Send Mail Button", "The send button to use when sending email messages.");
        descriptions.put("End Button", "The button used to end a chat session.");
        descriptions.put("Secure Button", "Used to show a secure connection has been established.");
        descriptions.put("Agent Typing Button", "Used to show that the agent in the conversation is typing a message.");
    }

    /**
     * Adds the encoded imageMap to the database.
     *
     * @param workgroupJID - the jid of the workgroup to setup.
     */
    private void createImageSettings(JID workgroupJID) {
        PluginManager pluginManager = XMPPServer.getInstance().getPluginManager();
        Plugin fastpathPlugin = pluginManager.getPlugin("fastpath");
        File fastpathPluginDirectory = pluginManager.getPluginDirectory(fastpathPlugin);

        File imagesDir = new File(fastpathPluginDirectory, "web/images");

        for (KeyEnum key : imageMap.keySet()) {
            String value = imageMap.get(key);

            File image = new File(imagesDir, value);
            FileInputStream stream = null;
            try {
                stream = new FileInputStream(image);
            }
            catch (FileNotFoundException e) {
                ComponentManagerFactory.getComponentManager().getLog().error(e);
            }

            if (stream != null) {
                byte[] bytes;
                try {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -