📄 chatsettingsmanager.java
字号:
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
// Add to cache
ChatSettings chatSettings = cachedSettings.get(setting.getWorkgroupNode());
if (chatSettings != null) {
chatSettings.removeChatSetting(setting);
}
}
/**
* Removes a <code>WebChatSetting</code> from the database.
*
* @param key the key of the chat setting to remove.
* @param workgroup the workgroup the key belongs to.
*/
public void removeChatSetting(KeyEnum key, Workgroup workgroup) {
String workgroupNode = workgroup.getJID().getNode();
Connection con;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
try {
pstmt = con.prepareStatement(DELETE_SINGLE_CHAT_SETTING);
pstmt.setString(1, key.toString());
pstmt.setString(2, workgroupNode);
pstmt.executeUpdate();
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
// Add to cache
ChatSettings chatSettings = cachedSettings.get(workgroupNode);
if (chatSettings != null) {
ChatSetting setting = chatSettings.getChatSetting(key);
if (setting != null) {
chatSettings.removeChatSetting(setting);
}
}
}
/**
* Retrieves a <code>WebChatSetting</code> based on the owning workgroup and setting key.
*
* @param workgroup the owning workgroup.
* @param key the setting key to find.
* @return the ChatSetting found, otherwise null is returned.
*/
public ChatSetting getChatSetting(Workgroup workgroup, String key) {
ChatSettings chatSettings = getChatSettings(workgroup);
if (chatSettings != null) {
return chatSettings.getChatSetting(key);
}
return null;
}
/**
* Send all WebChat settings for a particular Workgroup.
*
* @param packet the original packet that made the request.
* @param workgroup the workgroup the packet was sent to.
*/
public void getAllChatSettings(IQ packet, Workgroup workgroup) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the web chat setting.
ChatSettings chatSettings = getChatSettings(workgroup);
if (chatSettings == null) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element webSettings = reply.setChildElement("chat-settings", "http://jivesoftware.com/protocol/workgroup");
for (ChatSetting setting : chatSettings.getChatSettings()) {
Element root = webSettings.addElement("chat-setting");
try {
root.addElement("key").setText(setting.getKey().toString());
root.addElement("value").setText(setting.getValue());
root.addElement("type").setText(Integer.toString(setting.getType().getType()));
}
catch (Exception e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
}
workgroup.send(reply);
}
/**
* Send all WebChat settings for a particular Workgroup and type.
*
* @param packet the original packet that made the request.
* @param workgroup the workgroup the packet was sent to.
* @param type the type.
*/
public void getChatSettingsByType(IQ packet, Workgroup workgroup, int type) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the web chat setting.
ChatSettings chatSettings = getChatSettings(workgroup);
if (chatSettings == null) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element webSettings = reply.setChildElement("chat-settings", "http://jivesoftware.com/protocol/workgroup");
for (ChatSetting setting : chatSettings.getChatSettings()) {
if (setting.getType().getType() == type) {
Element root = webSettings.addElement("chat-setting");
root.addElement("key").setText(setting.getKey().toString());
root.addElement("value").setText(setting.getValue());
root.addElement("type").setText(Integer.toString(setting.getType().getType()));
}
}
workgroup.send(reply);
}
/**
* Send a single WebChat setting a given workgroup.
*
* @param packet the original packet that made the request.
* @param workgroup the workgroup the packet was sent to.
* @param key the mapped setting key.
*/
public void getChatSettingByKey(IQ packet, Workgroup workgroup, String key) {
IQ reply = IQ.createResultIQ(packet);
// Retrieve the web chat setting.
ChatSetting setting = getChatSetting(workgroup, key);
if (setting == null) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(new PacketError(PacketError.Condition.item_not_found));
workgroup.send(reply);
return;
}
Element webSettings = reply.setChildElement("chat-settings", "http://jivesoftware.com/protocol/workgroup");
Element root = webSettings.addElement("chat-setting");
root.addElement("key").setText(setting.getKey().toString());
root.addElement("value").setText(setting.getValue());
root.addElement("type").setText(Integer.toString(setting.getType().getType()));
workgroup.send(reply);
}
public void workgroupCreated(Workgroup workgroup) {
}
public void workgroupDeleting(Workgroup workgroup) {
}
public void workgroupDeleted(Workgroup workgroup) {
String workgroupNode = workgroup.getJID().getNode();
// Remove settings from cache
cachedSettings.remove(workgroupNode);
// Delete from DB.
Connection con;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
try {
pstmt = con.prepareStatement(DELETE_CHAT_SETTINGS);
pstmt.setString(1, workgroupNode);
pstmt.executeUpdate();
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
}
catch (Exception ex) {
ComponentManagerFactory.getComponentManager().getLog().error(ex);
}
}
public void workgroupOpened(Workgroup workgroup) {
}
public void workgroupClosed(Workgroup workgroup) {
}
public void agentJoined(Workgroup workgroup, AgentSession agentSession) {
}
public void agentDeparted(Workgroup workgroup, AgentSession agentSession) {
}
public void chatSupportStarted(Workgroup workgroup, String sessionID) {
}
public void chatSupportFinished(Workgroup workgroup, String sessionID) {
}
public void agentJoinedChatSupport(Workgroup workgroup, String sessionID, AgentSession agentSession) {
}
public void agentLeftChatSupport(Workgroup workgroup, String sessionID, AgentSession agentSession) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -