Package com.sun.syndication.feed.atom

Examples of com.sun.syndication.feed.atom.Feed


    private static void serializeEntry(Entry entry, OutputStream out)
    throws IllegalArgumentException, FeedException, IOException {
        // Build a feed containing only the entry
        List entries = new ArrayList();
        entries.add(entry);
        Feed feed1 = new Feed();
        feed1.setFeedType( FEED_TYPE);
        feed1.setEntries(entries);
       
        // Use Rome to output feed as a JDOM document
        WireFeedOutput wireFeedOutput = new WireFeedOutput();
        Document feedDoc = wireFeedOutput.outputJDom(feed1);
       
View Full Code Here


    }
  }

  public WireFeed toFeed(List<Message> messages, Date lastModified, IPreferences prefs, IChannelPreferences cPrefs)
      throws RenderException {
    final Feed f = new Feed("atom_1.0");

    // TODO allow rendered titles
    f.setTitle(_feedTitle);
    f.setUpdated(lastModified == null ? new Date() : lastModified);

    Person author = new Person();
    author.setName(_authorName);

    f.setAuthors(Arrays.asList(author));

    final List<Entry> entries = Lists.newArrayList();

    for (final Message msg : messages) {
      final Entry e = new Entry();
      final Content c = new Content();

      c.setType("text/html");
      c.setValue(msg.getHtml());

      e.setId(Hash.md5(msg.getSubject()).toHex());
      e.setUpdated(new Date()); // TODO updated date? not easy ...
      e.setTitle(msg.getSubject());
      e.setContents(Arrays.asList(c));
      entries.add(e);
    }

    f.setEntries(entries);
    return f;
  }
View Full Code Here

    public Message invoke(Message msg) {
        try {
            logger.info(">>> RSSBindingInvoker (" + feedType + ") " + uri);

            // Read the configured feed URI into a Feed object
            Feed feed;
            if (feedType.startsWith("atom_")) {

                // Read an Atom feed
                WireFeedInput input = new WireFeedInput();
                feed = (Feed)input.build(new XmlReader(new URL(uri)));
View Full Code Here

                outputter.output(document, getWriter(response));

            } else if (path == null || path.length() == 0 || path.equals("/")) {

                // Return a feed containing the entries in the collection
                Feed feed = null;
                if (supportsFeedEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (Feed)responseMessage.getBody();
                   
                } else {

                    // The service implementation does not support feed entries,
                    // invoke its getAll operation to get the data item collection, then create
                    // feed entries from the items
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage;
                    if (request.getQueryString() != null) {
                        requestMessage.setBody(new Object[] {request.getQueryString()});
                        responseMessage = queryInvoker.invoke(requestMessage);
                    } else {
                        responseMessage = getAllInvoker.invoke(requestMessage);
                    }
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    org.apache.tuscany.sca.data.collection.Entry<Object, Object>[] collection =
                        (org.apache.tuscany.sca.data.collection.Entry<Object, Object>[])responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (org.apache.tuscany.sca.data.collection.Entry<Object, Object> entry: collection) {
                            Entry feedEntry = createFeedEntry(entry);
                            feed.getEntries().add(feedEntry);
                        }
                    }
                }
                if (feed != null) {
                   
                    // Write the Atom feed
                    response.setContentType("application/atom+xml; charset=utf-8");
                    feed.setFeedType(requestFeedType);
                    WireFeedOutput feedOutput = new WireFeedOutput();
                    try {
                        feedOutput.output(feed, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }
               
            } else if (path.startsWith("/")) {

                // Return a specific entry in the collection
                Entry feedEntry;

                // Invoke the get operation on the service implementation
                Message requestMessage = messageFactory.createMessage();
                String id = path.substring(1);
                requestMessage.setBody(new Object[] {id});
                Message responseMessage = getInvoker.invoke(requestMessage);
                if (responseMessage.isFault()) {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }
                if (supportsFeedEntries) {
                   
                    // The service implementation returns a feed entry
                    feedEntry = responseMessage.getBody();
                   
                } else {
                   
                    // The service implementation only returns a data item, create an entry
                    // from it
                    feedEntry = createFeedEntry(new org.apache.tuscany.sca.data.collection.Entry<Object, Object>(id, responseMessage.getBody()));
                }

                // Write the Atom entry
                if (feedEntry != null) {
                    response.setContentType("application/atom+xml; charset=utf-8");
                    try {
                        AtomFeedEntryUtil.writeFeedEntry(feedEntry, feedType, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }

            } else {

                // Path doesn't match any known pattern
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
        } else {

            // Handle an RSS request
            if (path == null || path.length() == 0 || path.equals("/")) {

                // Return an RSS feed containing the entries in the collection
                Feed feed = null;
                if (supportsFeedEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (Feed)responseMessage.getBody();
                   
                } else {

                    // The service implementation does not support feed entries, invoke its
                    // getAll operation to get the data item collection. then create feed entries
                    // from the data items
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage;
                    if (request.getQueryString() != null) {
                        requestMessage.setBody(new Object[] {request.getQueryString()});
                        responseMessage = queryInvoker.invoke(requestMessage);
                    } else {
                        responseMessage = getAllInvoker.invoke(requestMessage);
                    }
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    org.apache.tuscany.sca.data.collection.Entry<Object, Object>[] collection =
                        (org.apache.tuscany.sca.data.collection.Entry<Object, Object>[])responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (org.apache.tuscany.sca.data.collection.Entry<Object, Object> entry: collection) {
                            Entry feedEntry = createFeedEntry(entry);
                            feed.getEntries().add(feedEntry);
                        }
                    }
                }

                // Convert to an RSS feed
                if (feed != null) {
                    response.setContentType("application/rss+xml; charset=utf-8");
                    feed.setFeedType("atom_1.0");
                    SyndFeed syndFeed = new SyndFeedImpl(feed);
                    syndFeed.setFeedType(requestFeedType);
                    syndFeed.setLink(path);
                    SyndFeedOutput syndOutput = new SyndFeedOutput();
                    try {
View Full Code Here

   
    @SuppressWarnings("unchecked")
    public com.sun.syndication.feed.atom.Feed getFeed() {
       
        // Create a new Feed
        Feed feed = new Feed();
        feed.setId("accounts");
        feed.setTitle("Account Report Feed");
        Content subtitle = new Content();
        subtitle.setValue("This is a sample feed");
        feed.setSubtitle(subtitle);
        Link link = new Link();
        link.setHref("http://incubator.apache.org/tuscany");
        feed.getAlternateLinks().add(link);

        // Add the Account report entry
        Entry entry = get("1234");
        feed.getEntries().add(entry);

        return feed;
    }
View Full Code Here

   
    @SuppressWarnings("unchecked")
    public com.sun.syndication.feed.atom.Feed getFeed() {
       
        // Create a new Feed
        Feed feed = new Feed();
        feed.setId("accounts");
        feed.setTitle("Account Report Feed");
        Content subtitle = new Content();
        subtitle.setValue("This is a sample feed");
        feed.setSubtitle(subtitle);
        Link link = new Link();
        link.setHref("http://incubator.apache.org/tuscany");
        feed.getAlternateLinks().add(link);

        // Add the Account report entry
        Entry entry = get("1234");
        feed.getEntries().add(entry);

        return feed;
    }
View Full Code Here

                outputter.output(document, getWriter(response));

            } else if (path == null || path.length() == 0 || path.equals("/")) {

                // Return a feed containing the entries in the collection
                Feed feed = null;
                if (supportsEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (Feed)responseMessage.getBody();
                   
                } else {

                    // The service implementation does not support feed entries,
                    // invoke its getAll operation to get the data item collection, then create
                    // feed entries from the items
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getAllInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    Map<Object, Object> collection = (Map<Object, Object>)responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (Map.Entry<Object, Object> item: collection.entrySet()) {
                            Entry entry = createEntry(item.getKey(), item.getValue());
                            feed.getEntries().add(entry);
                        }
                    }
                }
                if (feed != null) {
                   
                    // Write the Atom feed
                    response.setContentType("application/atom+xml; charset=utf-8");
                    feed.setFeedType(requestFeedType);
                    WireFeedOutput feedOutput = new WireFeedOutput();
                    try {
                        feedOutput.output(feed, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }
               
            } else if (path.startsWith("/")) {

                // Return a specific entry in the collection
                Entry entry;

                // Invoke the get operation on the service implementation
                Message requestMessage = messageFactory.createMessage();
                String id = path.substring(1);
                requestMessage.setBody(new Object[] {id});
                Message responseMessage = getInvoker.invoke(requestMessage);
                if (responseMessage.isFault()) {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }
                if (supportsEntries) {
                   
                    // The service implementation returns a feed entry
                    entry = responseMessage.getBody();
                   
                } else {
                   
                    // The service implementation only returns a data item, create an entry
                    // from it
                    entry = createEntry(id, responseMessage.getBody());
                }

                // Write the Atom entry
                if (entry != null) {
                    response.setContentType("application/atom+xml; charset=utf-8");
                    try {
                        AtomEntryUtil.writeEntry(entry, feedType, getWriter(response));
                    } catch (FeedException e) {
                        throw new ServletException(e);
                    }
                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }

            } else {

                // Path doesn't match any known pattern
                response.sendError(HttpServletResponse.SC_NOT_FOUND);
            }
        } else {

            // Handle an RSS request
            if (path == null || path.length() == 0 || path.equals("/")) {

                // Return an RSS feed containing the entries in the collection
                Feed feed = null;
                if (supportsEntries) {

                    // The service implementation supports feed entries, invoke its getFeed operation
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getFeedInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    feed = (Feed)responseMessage.getBody();
                   
                } else {

                    // The service implementation does not support feed entries, invoke its
                    // getAll operation to get the data item collection. then create feed entries
                    // from the data items
                    Message requestMessage = messageFactory.createMessage();
                    Message responseMessage = getAllInvoker.invoke(requestMessage);
                    if (responseMessage.isFault()) {
                        throw new ServletException((Throwable)responseMessage.getBody());
                    }
                    Map<Object, Object> collection = (Map<Object, Object>)responseMessage.getBody();
                    if (collection != null) {
                        // Create the feed
                        feed = new Feed();
                        feed.setTitle("Feed");
                        for (Map.Entry<Object, Object> item: collection.entrySet()) {
                            Entry entry = createEntry(item.getKey(), item.getValue());
                            feed.getEntries().add(entry);
                        }
                    }
                }

                // Convert to an RSS feed
                if (feed != null) {
                    response.setContentType("application/rss+xml; charset=utf-8");
                    feed.setFeedType("atom_1.0");
                    SyndFeed syndFeed = new SyndFeedImpl(feed);
                    syndFeed.setFeedType(requestFeedType);
                    SyndFeedOutput syndOutput = new SyndFeedOutput();
                    try {
                        syndOutput.output(syndFeed, getWriter(response));
View Full Code Here

        FeedException {
        SAXBuilder builder = new SAXBuilder();
        Document document = builder.build(reader);
        Element root = document.getRootElement();
        root.detach();
        Feed feed = new Feed();
        feed.setFeedType(feedType);
        WireFeedOutput wireFeedOutput = new WireFeedOutput();
        document = wireFeedOutput.outputJDom(feed);
        document.getRootElement().addContent(root);
        WireFeedInput input = new WireFeedInput();
        feed = (Feed)input.build(document);
        Entry entry = (Entry)feed.getEntries().get(0);
        if (entry.getContents().size() != 0) {
            Content content = (Content)entry.getContents().get(0);
            if ("text/xml".equals(content.getType())) {
                Element element = root.getChild("content", root.getNamespace());
                if (!element.getChildren().isEmpty()) {
View Full Code Here

     * @throws IOException
     * @throws ServletException
     */
    static void writeEntry(Entry entry, String feedType, Writer writer) throws IllegalArgumentException, FeedException,
        IOException {
        Feed feed = new Feed();
        feed.setFeedType(feedType);
        List<Entry> entries = new ArrayList<Entry>();
        entries.add(entry);
        feed.setEntries(entries);

        WireFeedOutput wireFeedOutput = new WireFeedOutput();
        Document document = wireFeedOutput.outputJDom(feed);
        Element root = document.getRootElement();
        Element element = (Element)root.getChildren().get(0);
View Full Code Here

    public Message invoke(Message msg) {
        try {
            logger.info(">>> RSSBindingInvoker (" + feedType + ") " + uri);

            // Read the configured feed URI into a Feed object
            Feed feed;
            if (feedType.startsWith("atom_")) {

                // Read an Atom feed
                WireFeedInput input = new WireFeedInput();
                feed = (Feed)input.build(new XmlReader(new URL(uri)));
View Full Code Here

TOP

Related Classes of com.sun.syndication.feed.atom.Feed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.