chatmanager.java.svn-base
来自「开源项目openfire的完整源程序」· SVN-BASE 代码 · 共 900 行 · 第 1/3 页
SVN-BASE
900 行
catch (InterruptedException e) {
Log.error("Error in activate chat.", e);
}
ChatContainer chatRooms = chatManager.getChatContainer();
try {
chatRoom = chatRooms.getChatRoom(jid);
}
catch (ChatRoomNotFoundException e) {
}
return chatRoom;
}
public void finished() {
if (chatRoom == null) {
chatRoom = new ChatRoomImpl(jid, nickname, nickname);
chatManager.getChatContainer().addChatRoom(chatRoom);
}
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
};
worker.start();
}
/**
* Checks if a <code>ChatRoom</code> exists.
*
* @param jid the jid of the user.
* @return true if the ChatRoom exists.
*/
public boolean chatRoomExists(String jid) {
try {
getChatContainer().getChatRoom(jid);
}
catch (ChatRoomNotFoundException e) {
return false;
}
return true;
}
/**
* Adds a new <code>MessageFilter</code>.
*
* @param filter the MessageFilter.
*/
public void addMessageFilter(MessageFilter filter) {
messageFilters.add(filter);
}
/**
* Removes a <code>MessageFilter</code>.
*
* @param filter the MessageFilter.
*/
public void removeMessageFilter(MessageFilter filter) {
messageFilters.remove(filter);
}
/**
* Returns a Collection of MessageFilters registered to Spark.
*
* @return the Collection of MessageFilters.
*/
public Collection getMessageFilters() {
return messageFilters;
}
/**
* Adds a new <code>GlobalMessageListener</code>.
*
* @param listener the listener.
*/
public void addGlobalMessageListener(GlobalMessageListener listener) {
globalMessageListeners.add(listener);
}
/**
* Removes a <code>GlobalMessageListener</code>.
*
* @param listener the listener.
*/
public void removeGlobalMessageListener(GlobalMessageListener listener) {
globalMessageListeners.remove(listener);
}
/**
* Notifies all <code>GlobalMessageListeners</code> of a new incoming message.
*
* @param chatRoom the <code>ChatRoom</code> where the message was sent to.
* @param message the <code>Message</code>
*/
public void fireGlobalMessageReceievedListeners(ChatRoom chatRoom, Message message) {
for (GlobalMessageListener listener : globalMessageListeners) {
listener.messageReceived(chatRoom, message);
}
}
/**
* Notifies all <code>GlobalMessageListeners</code> of a new message sent.
*
* @param chatRoom the <code>ChatRoom</code> where the message was sent from.
* @param message the <code>Message</code> sent.
*/
public void fireGlobalMessageSentListeners(ChatRoom chatRoom, Message message) {
for (GlobalMessageListener listener : globalMessageListeners) {
listener.messageSent(chatRoom, message);
}
}
/**
* Filters all incoming messages.
*
* @param room the room the message belongs to.
* @param message the message to filter.
*/
public void filterIncomingMessage(ChatRoom room, Message message) {
// Fire Message Filters
final ChatManager chatManager = SparkManager.getChatManager();
Iterator filters = chatManager.getMessageFilters().iterator();
try {
cancelledNotification(message.getFrom(), "");
}
catch (Exception e) {
Log.error(e);
}
// Notify MessageFilters.
while (filters.hasNext()) {
((MessageFilter)filters.next()).filterIncoming(room, message);
}
}
/**
* Notifies all <code>MessageFilter</code>s about a new outgoing message.
*
* @param room the <code>ChatRoom</code> the message belongs too.
* @param message the <code>Message</code> being sent.
*/
public void filterOutgoingMessage(ChatRoom room, Message message) {
// Fire Message Filters
final ChatManager chatManager = SparkManager.getChatManager();
Iterator filters = chatManager.getMessageFilters().iterator();
while (filters.hasNext()) {
((MessageFilter)filters.next()).filterOutgoing(room, message);
}
}
/**
* Adds a <code>RoomInvitationListener</code>. A RoomInvitationListener is
*
* @param listener the listener.
*/
public void addInvitationListener(RoomInvitationListener listener) {
invitationListeners.add(listener);
}
/**
* Removes a <code>RoomInvitationListener</code>.
*
* @param listener the listener to remove.
*/
public void removeInvitationListener(RoomInvitationListener listener) {
invitationListeners.remove(listener);
}
/**
* Returns all registered <code>RoomInvitationListener</code>s.
*
* @return the Collection of listeners.
*/
public Collection<RoomInvitationListener> getInvitationListeners() {
return Collections.unmodifiableCollection(invitationListeners);
}
/**
* Returns the default conference service. (ex. conference.jivesoftware.com)
*
* @return the default conference service to interact with MUC.
*/
public String getDefaultConferenceService() {
if (conferenceService == null) {
try {
Collection col = MultiUserChat.getServiceNames(SparkManager.getConnection());
if (col.size() > 0) {
conferenceService = (String)col.iterator().next();
}
}
catch (XMPPException e) {
Log.error(e);
}
}
return conferenceService;
}
/**
* Adds a new <code>ContactItemHandler</code>.
*
* @param handler the ContactItemHandler to add.
*/
public void addContactItemHandler(ContactItemHandler handler) {
contactItemHandlers.add(handler);
}
/**
* Removes a <code>ContactItemHandler</code>.
*
* @param handler the ContactItemHandler to remove.
*/
public void removeContactItemHandler(ContactItemHandler handler) {
contactItemHandlers.remove(handler);
}
/**
* Notifies all <code>ContactItemHandler</code>s of presence changes.
*
* @param item the ContactItem where the presence changed.
* @param presence the new presence.
* @return true if it was handled.
*/
public boolean fireContactItemPresenceChanged(ContactItem item, Presence presence) {
for (ContactItemHandler handler : contactItemHandlers) {
if (handler.handlePresence(item, presence)) {
return true;
}
}
return false;
}
/**
* Notifies all <code>ContactItemHandlers</code> that a <code>ContactItem</code> was double-clicked.
*
* @param item the ContactItem that was double clicked.
* @return true if the event was intercepted and handled.
*/
public boolean fireContactItemDoubleClicked(ContactItem item) {
for (ContactItemHandler handler : contactItemHandlers) {
if (handler.handleDoubleClick(item)) {
return true;
}
}
return false;
}
/**
* Returns the icon from a <code>ContactItemHandler</code>.
*
* @param jid the jid.
* @return the icon of the handler.
*/
public Icon getIconForContactHandler(String jid) {
for (ContactItemHandler handler : contactItemHandlers) {
Icon icon = handler.getIcon(jid);
if (icon != null) {
return icon;
}
}
return null;
}
/**
* Returns the icon to use in the tab.
*
* @param presence the presence.
* @return the icon.
*/
public Icon getTabIconForContactHandler(Presence presence) {
for (ContactItemHandler handler : contactItemHandlers) {
Icon icon = handler.getTabIcon(presence);
if (icon != null) {
return icon;
}
}
return null;
}
// Implemenation of MessageEventListener
public void deliveredNotification(String from, String packetID) {
}
public void displayedNotification(String from, String packetID) {
}
public void composingNotification(final String from, String packetID) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
final ContactList contactList = SparkManager.getWorkspace().getContactList();
ChatRoom chatRoom = null;
try {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?