Search in sources :

Example 76 with ID

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;
}
Also used : IChatRoomContainer(org.eclipse.ecf.presence.chatroom.IChatRoomContainer) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ArrayList(java.util.ArrayList) List(java.util.List) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ID(org.eclipse.ecf.core.identity.ID)

Example 77 with ID

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[] {});
}
Also used : ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) Collection(java.util.Collection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPID(org.eclipse.ecf.provider.xmpp.identity.XMPPID) XMPPRoomID(org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID) ID(org.eclipse.ecf.core.identity.ID) XMPPException(org.jivesoftware.smack.XMPPException) HostedRoom(org.jivesoftware.smackx.muc.HostedRoom)

Example 78 with 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.");
}
Also used : RssFeed(org.eclipse.higgins.rsse.RssFeed) IChannelListener(org.eclipse.ecf.datashare.IChannelListener) IChannelEvent(org.eclipse.ecf.datashare.events.IChannelEvent) HashMap(java.util.HashMap) ContainerTypeDescription(org.eclipse.ecf.core.ContainerTypeDescription) IMergeableChannel(org.eclipse.ecf.datashare.mergeable.IMergeableChannel) List(java.util.List) RssItem(org.eclipse.higgins.rsse.RssItem) ID(org.eclipse.ecf.core.identity.ID) StringID(org.eclipse.ecf.core.identity.StringID) IMergeableChannelContainerAdapter(org.eclipse.ecf.datashare.mergeable.IMergeableChannelContainerAdapter) File(java.io.File)

Example 79 with ID

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);
            }
        }
    });
}
Also used : IContainerListener(org.eclipse.ecf.core.IContainerListener) IChatMessageEvent(org.eclipse.ecf.presence.im.IChatMessageEvent) IIMMessageEvent(org.eclipse.ecf.presence.IIMMessageEvent) IIMMessageListener(org.eclipse.ecf.presence.IIMMessageListener) IChatMessage(org.eclipse.ecf.presence.im.IChatMessage) ID(org.eclipse.ecf.core.identity.ID)

Example 80 with ID

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();
}
Also used : ID(org.eclipse.ecf.core.identity.ID)

Aggregations

ID (org.eclipse.ecf.core.identity.ID)256 IContainer (org.eclipse.ecf.core.IContainer)29 IOException (java.io.IOException)19 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)18 UUID (java.util.UUID)17 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)11 ContainerConnectException (org.eclipse.ecf.core.ContainerConnectException)11 GUID (org.eclipse.ecf.core.identity.GUID)11 ISharedObjectManager (org.eclipse.ecf.core.sharedobject.ISharedObjectManager)11 XMPPRoomID (org.eclipse.ecf.provider.xmpp.identity.XMPPRoomID)11 Namespace (org.eclipse.ecf.core.identity.Namespace)10 XMPPID (org.eclipse.ecf.provider.xmpp.identity.XMPPID)10 Map (java.util.Map)9 Matcher (java.util.regex.Matcher)9 ECFException (org.eclipse.ecf.core.util.ECFException)9 List (java.util.List)8 ISharedObject (org.eclipse.ecf.core.sharedobject.ISharedObject)8 IChannel (org.eclipse.ecf.datashare.IChannel)8 Iterator (java.util.Iterator)7