Search in sources :

Example 1 with IMergeableChannelContainerAdapter

use of org.eclipse.ecf.datashare.mergeable.IMergeableChannelContainerAdapter 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 2 with IMergeableChannelContainerAdapter

use of org.eclipse.ecf.datashare.mergeable.IMergeableChannelContainerAdapter in project ecf by eclipse.

the class FeedSharedObject method init.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ecf.core.ISharedObject#init(org.eclipse.ecf.core.ISharedObjectConfig)
	 */
public void init(ISharedObjectConfig initData) throws SharedObjectInitException {
    if (config == null) {
        config = initData;
    } else {
        throw new SharedObjectInitException("Already initialized.");
    }
    trace("init(" + initData + ")");
    // get local publish path
    publishPathName = (String) initData.getProperties().get(PUBLISH_PROPERTY_NAME);
    publishPathName = publishPathName == null ? "feed.xml" : publishPathName;
    // get local channel container first...throw if we can't get it
    IMergeableChannelContainerAdapter container = (IMergeableChannelContainerAdapter) config.getContext().getAdapter(IMergeableChannelContainerAdapter.class);
    if (container == null) {
        throw new SharedObjectInitException("Channel container is null/not available");
    }
    if (container instanceof RssClientSOContainer) {
        // get rss feed
        try {
            feed = ((RssClientSOContainer) container).receiveFeed(getID().getName());
        } catch (IOException ioe) {
            throw new SharedObjectInitException(ioe);
        }
    }
}
Also used : IOException(java.io.IOException) IMergeableChannelContainerAdapter(org.eclipse.ecf.datashare.mergeable.IMergeableChannelContainerAdapter) SharedObjectInitException(org.eclipse.ecf.core.sharedobject.SharedObjectInitException)

Aggregations

IMergeableChannelContainerAdapter (org.eclipse.ecf.datashare.mergeable.IMergeableChannelContainerAdapter)2 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ContainerTypeDescription (org.eclipse.ecf.core.ContainerTypeDescription)1 ID (org.eclipse.ecf.core.identity.ID)1 StringID (org.eclipse.ecf.core.identity.StringID)1 SharedObjectInitException (org.eclipse.ecf.core.sharedobject.SharedObjectInitException)1 IChannelListener (org.eclipse.ecf.datashare.IChannelListener)1 IChannelEvent (org.eclipse.ecf.datashare.events.IChannelEvent)1 IMergeableChannel (org.eclipse.ecf.datashare.mergeable.IMergeableChannel)1 RssFeed (org.eclipse.higgins.rsse.RssFeed)1 RssItem (org.eclipse.higgins.rsse.RssItem)1