Package com.sun.syndication.feed.atom

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


                Message requestMessage = messageFactory.createMessage();
                Message responseMessage = getFeedInvoker.invoke(requestMessage);
                if (responseMessage.isFault()) {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }
                Feed feed = (Feed)responseMessage.getBody();
                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

                // Get the entry from 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());
                }
                Entry entry = 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("/")) {

                // Get the Feed from the service
                Message requestMessage = messageFactory.createMessage();
                Message responseMessage = getFeedInvoker.invoke(requestMessage);
                if (responseMessage.isFault()) {
                    throw new ServletException((Throwable)responseMessage.getBody());
                }
                Feed feed = (Feed)responseMessage.getBody();
                if (feed != null) {

                    // Convert to an RSS feed
                    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


    @SuppressWarnings("unchecked")
    public Feed getFeed() {
        System.out.println(">>> ResourceCollectionImpl.get collection");

        Feed feed = new Feed();
        feed.setTitle("customers");
        Content subtitle = new Content();
        subtitle.setValue("This is a sample feed");
        feed.setSubtitle(subtitle);
        feed.getEntries().addAll(entries.values());
        return feed;
    }
View Full Code Here

        System.out.println(">>> delete id=" + entry.getId());
        resourceCollection.delete(entry.getId());
        System.out.println("<<< delete id=" + entry.getId());

        System.out.println(">>> get collection");
        Feed feed = resourceCollection.getFeed();
        System.out.println("<<< get collection");
        for (Object o : feed.getEntries()) {
            Entry e = (Entry)o;
            System.out.println("id = " + e.getId() + " entry = " + e.getTitle());
        }
    }
View Full Code Here

                int status = getMethod.getStatusCode();

                // Read the Atom feed
                if (status == 200) {
                    WireFeedInput input = new WireFeedInput();
                    Feed feed = (Feed)input.build(new XmlReader(getMethod.getResponseBodyAsStream()));
                    msg.setBody(feed);

                } else if (status == 404) {
                    msg.setFaultBody(new NotFoundException());
                } else {
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);
        return entry;
    }
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

            }
            if (!RollerAtomHandler.canView(user, website)) {
                throw new AtomNotAuthorizedException("Not authorized to access website");
            }

            Feed feed = new Feed();
            feed.setId(atomURL
                +"/"+website.getHandle() + "/resources/" + path + start);               
            feed.setTitle(website.getName());

            Link link = new Link();
            link.setHref(absUrl + "/" + website.getHandle());
            link.setRel("alternate");
            link.setType("text/html");
            feed.setAlternateLinks(Collections.singletonList(link));

            MediaFileManager fmgr = roller.getMediaFileManager();
            MediaFileDirectory dir = null;
            if (StringUtils.isNotEmpty(path)) {
                log.debug("Fetching resource collection from weblog " + handle + " at path: " + path);
                dir = fmgr.getMediaFileDirectoryByPath(website, path);
            } else {
                log.debug("Fetching root resource collection from weblog " + handle);
                dir = fmgr.getMediaFileRootDirectory(website);
            }
            Set<MediaFile> files = dir.getMediaFiles();

            SortedSet sortedSet = new TreeSet(new Comparator() {
                public int compare(Object o1, Object o2) {
                    MediaFile f1 = (MediaFile)o1;
                    MediaFile f2 = (MediaFile)o2;
                    if (f1.getLastModified() < f2.getLastModified()) return 1;
                    else if (f1.getLastModified() == f2.getLastModified()) return 0;
                    else return -1;
                }
            });
                                   
            if (files != null && start < files.size()) {
                for (MediaFile mf : files) {
                    sortedSet.add(mf);
                }
                int count = 0;
                MediaFile[] sortedResources =
                   (MediaFile[])sortedSet.toArray(new MediaFile[sortedSet.size()]);
                List atomEntries = new ArrayList();
                for (int i=start; i<(start + max) && i<(sortedResources.length); i++) {
                    Entry entry = createAtomResourceEntry(website, sortedResources[i]);
                    atomEntries.add(entry);
                    if (count == 0) {
                        // first entry is most recent
                        feed.setUpdated(entry.getUpdated());
                    }
                    count++;
                }

                List otherLinks = new ArrayList();
                if (start + count < files.size()) { // add next link
                    int nextOffset = start + max;
                    String url = atomURL
                        +"/"+ website.getHandle() + "/resources/" + path + nextOffset;
                    Link nextLink = new Link();
                    nextLink.setRel("next");
                    nextLink.setHref(url);
                    otherLinks.add(nextLink);
                }
                if (start > 0) { // add previous link
                    int prevOffset = start > max ? start - max : 0;
                    String url = atomURL
                        +"/"+website.getHandle() + "/resources/" + path + prevOffset;
                    Link prevLink = new Link();
                    prevLink.setRel("previous");
                    prevLink.setHref(url);
                    otherLinks.add(prevLink);
                }
                feed.setOtherLinks(otherLinks);
                feed.setEntries(atomEntries);

                log.debug("Collection contains: " + count);

            } else {
                log.debug("Returning empty collection");
View Full Code Here

                    "updateTime",      // sortby
                    null,
                    null,              // locale
                    start,             // offset (for range paging)
                    max + 1);          // maxEntries
            Feed feed = new Feed();
            feed.setId(atomURL
                +"/"+website.getHandle() + "/entries/" + start);
            feed.setTitle(website.getName());

            Link link = new Link();
            link.setHref(absUrl + "/" + website.getHandle());
            link.setRel("alternate");
            link.setType("text/html");
            feed.setAlternateLinks(Collections.singletonList(link));

            List atomEntries = new ArrayList();
            int count = 0;
            for (Iterator iter = entries.iterator(); iter.hasNext() && count < maxEntries; count++) {
                WeblogEntry rollerEntry = (WeblogEntry)iter.next();
                Entry entry = createAtomEntry(rollerEntry);
                atomEntries.add(entry);
                if (count == 0) {
                    // first entry is most recent
                    feed.setUpdated(entry.getUpdated());
                }
            }
            List links = new ArrayList();
            if (entries.size() > max) { // add next link
                int nextOffset = start + max;
                String url = atomURL+"/"
                        + website.getHandle() + "/entries/" + nextOffset;
                Link nextLink = new Link();
                nextLink.setRel("next");
                nextLink.setHref(url);
                links.add(nextLink);
            }
            if (start > 0) { // add previous link
                int prevOffset = start > max ? start - max : 0;
                String url = atomURL+"/"
                        +website.getHandle() + "/entries/" + prevOffset;
                Link prevLink = new Link();
                prevLink.setRel("previous");
                prevLink.setHref(url);
                links.add(prevLink);
            }
            if (links.size() > 0) feed.setOtherLinks(links);
            // Use collection URI as id
            feed.setEntries(atomEntries);
           
            log.debug("Exiting");
            return feed;
       
        } catch (WebloggerException re) {
View Full Code Here

public class ShoppingCartImpl implements Collection {

    private static Map<String, Entry> cart = new HashMap<String, Entry>();

    public Feed getFeed() {
        Feed feed = new Feed();
        feed.setTitle("shopping cart");
        Content subtitle = new Content();
        subtitle.setValue("Total : " + getTotal());
        feed.setSubtitle(subtitle);
        feed.getEntries().addAll(cart.values());
        return feed;
    }
View Full Code Here

    return "Read " + feed.getTitle();
  }

  @RequestMapping(value="/atom", method=RequestMethod.GET)
  public @ResponseBody Feed writeFeed() {
    Feed feed = new Feed();
    feed.setFeedType("atom_1.0");
    feed.setTitle("My Atom feed");
    return feed;
  }
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.