use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class XMPPChatRoomManager method findReceiverChatRoom.
public IChatRoomContainer findReceiverChatRoom(ID toID) {
if (toID == null)
return null;
XMPPRoomID roomID = null;
if (toID instanceof XMPPRoomID) {
roomID = (XMPPRoomID) toID;
final String mucname = roomID.getMucString();
List toNotify = null;
synchronized (chatrooms) {
toNotify = new ArrayList(chatrooms);
}
for (final Iterator i = toNotify.iterator(); i.hasNext(); ) {
final IChatRoomContainer cont = (IChatRoomContainer) i.next();
if (cont == null)
continue;
final ID tid = cont.getConnectedID();
if (tid != null && tid instanceof XMPPRoomID) {
final XMPPRoomID targetID = (XMPPRoomID) tid;
final String tmuc = targetID.getMucString();
if (tmuc.equals(mucname)) {
return cont;
}
}
}
}
return null;
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class XMPPChatRoomManager method getChatRooms.
protected ID[] getChatRooms() {
if (ecfConnection == null)
return null;
final XMPPConnection conn = ecfConnection.getXMPPConnection();
if (conn == null)
return null;
final Collection result = new ArrayList();
try {
final Collection svcs = MultiUserChat.getServiceNames(conn);
for (final Iterator svcsi = svcs.iterator(); svcsi.hasNext(); ) {
final String svc = (String) svcsi.next();
final Collection rooms = MultiUserChat.getHostedRooms(conn, svc);
for (final Iterator roomsi = rooms.iterator(); roomsi.hasNext(); ) {
final HostedRoom room = (HostedRoom) roomsi.next();
final ID roomID = createIDFromHostedRoom(room);
if (roomID != null)
result.add(roomID);
}
}
} catch (final XMPPException e) {
return null;
}
return (ID[]) result.toArray(new ID[] {});
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class RssClientSOContainer method main.
public static final void main(String[] args) throws Exception {
// Get server identity
// String targetURL =
// "http://"+java.net.InetAddress.getLocalHost().getHostName();
String targetURL = "http://feeds.feedburner.com";
if (args.length > 0) {
targetURL = args[0];
}
final ContainerTypeDescription contd = new ContainerTypeDescription(RssContainerInstantiator.class.getName(), RssContainerInstantiator.class.getName(), null);
ContainerFactory.getDefault().addDescription(contd);
final RssClientSOContainer container = new RssClientSOContainer();
// now connect to rss service
final ID serverID = IDFactory.getDefault().createStringID(targetURL);
container.connect(serverID, null);
// get IMergeableChannelContainer adapter
final IMergeableChannelContainerAdapter channelContainer = (IMergeableChannelContainerAdapter) container.getAdapter(IMergeableChannelContainerAdapter.class);
// create channel listener
final IChannelListener listener = new IChannelListener() {
public void handleChannelEvent(IChannelEvent event) {
System.out.println("listener.handleChannelEvent(" + event + ")");
}
};
// create a new channel
final ID channelID = IDFactory.getDefault().createStringID("/reuters/worldNews/");
// ID channelID = IDFactory.getDefault().createStringID("/feed.xml");
final IMergeableChannel channel = channelContainer.createMergeableChannel(channelID, listener, new HashMap());
if (channel instanceof FeedSharedObject) {
// get remote feed (subscribed)
final RssFeed remoteFeed = ((FeedSharedObject) channel).getFeed();
// get local feed (published)
final File feedFile = new File("feed.xml");
RssFeed localFeed = RssFeed.load(feedFile);
if (localFeed == null) {
localFeed = new RssFeed(remoteFeed.getTitle(), remoteFeed.getLink(), remoteFeed.getDescription());
localFeed.setVersion(RssVersion.RSS_2_0);
}
// merge remote feed with local one
localFeed.merge(remoteFeed);
// add a new item to feed
localFeed.addItem(new RssItem("New Google Item", "This is a new item", "http://www.google.com"));
// publish updated feed
localFeed.save(feedFile);
// print item titles
final java.util.List items = localFeed.getItems();
for (int i = 0; i < items.size(); i++) {
System.out.println(" " + i + " " + ((RssItem) items.get(i)).getTitle());
}
}
// remove the channel
channelContainer.removeChannel(channelID);
// disconnect the service
container.disconnect();
container.dispose();
System.out.println("Exiting.");
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class ChatRoomManagerUI method setupNewView.
private void setupNewView() throws Exception {
IChatRoomInfo roomInfo = manager.getChatRoomInfo(null);
Assert.isNotNull(roomInfo, Messages.ChatRoomManagerUI_EXCEPTION_NO_ROOT_CHAT_ROOM_MANAGER);
final IChatRoomContainer managerChatRoom = roomInfo.createChatRoomContainer();
chatroomview.initializeWithManager(ChatRoomManagerView.getUsernameFromID(targetID), ChatRoomManagerView.getHostnameFromID(targetID), managerChatRoom, this, createChatRoomViewCloseListener());
chatroomview.setMessageRenderer(getDefaultMessageRenderer());
// Add listener for container, so that if the container is spontaneously
// disconnected,
// then we will be able to have the UI respond by making itself inactive
container.addListener(new IContainerListener() {
public void handleEvent(final IContainerEvent evt) {
Display.getDefault().syncExec(new Runnable() {
public void run() {
if (evt instanceof IContainerDisconnectedEvent || evt instanceof IContainerEjectedEvent) {
final ID departedContainerID = ((evt instanceof IContainerDisconnectedEvent) ? ((IContainerDisconnectedEvent) evt).getTargetID() : ((IContainerEjectedEvent) evt).getTargetID());
ID connectedID = targetID;
if (connectedID == null || connectedID.equals(departedContainerID)) {
chatroomview.disconnected();
isContainerConnected = false;
}
} else if (evt instanceof IContainerConnectedEvent) {
isContainerConnected = true;
chatroomview.setEnabled(true);
String[] roomsForTarget = getRoomsForTarget();
for (int i = 0; i < roomsForTarget.length; i++) {
IChatRoomInfo info = manager.getChatRoomInfo(roomsForTarget[i]);
chatroomview.joinRoom(info, getPasswordForChatRoomConnect(info));
}
}
}
});
}
});
// Add listeners so that the new chat room gets
// asynch notifications of various relevant chat room events
managerChatRoom.addMessageListener(new IIMMessageListener() {
public void handleMessageEvent(IIMMessageEvent messageEvent) {
if (messageEvent instanceof IChatRoomMessageEvent) {
IChatRoomMessage m = ((IChatRoomMessageEvent) messageEvent).getChatRoomMessage();
chatroomview.handleMessage(m.getFromID(), m.getMessage());
} else if (messageEvent instanceof IChatMessageEvent) {
final IChatMessage chatMessage = ((IChatMessageEvent) messageEvent).getChatMessage();
chatroomview.handleChatMessage(chatMessage);
}
}
});
}
use of org.eclipse.ecf.core.identity.ID in project ecf by eclipse.
the class DestroyIterator method next.
public Object next() {
if (hasNext()) {
final ID value = next;
next = null;
return value;
}
throw new java.util.NoSuchElementException();
}
Aggregations