Package com.sun.syndication.feed.atom

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


        Document entryDoc = builder.build(in);
        Element fetchedEntryElement = entryDoc.getRootElement();
        fetchedEntryElement.detach();
       
        // Put entry into a JDOM document with 'feed' root so that Rome can handle it
        Feed feed = new Feed();
        feed.setFeedType(FEED_TYPE);
        WireFeedOutput wireFeedOutput = new WireFeedOutput();
        Document feedDoc = wireFeedOutput.outputJDom(feed);
        feedDoc.getRootElement().addContent(fetchedEntryElement);
               
        WireFeedInput input = new WireFeedInput();
        Feed parsedFeed = (Feed)input.build(feedDoc);
        return (Entry)parsedFeed.getEntries().get(0);
    }
View Full Code Here


    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

                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 {
                        OutputStream output = response.getOutputStream();
                        feedOutput.output(feed, new PrintWriter(output));
                    } 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, response.getWriter());
                    } 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 {
                        OutputStream output = response.getOutputStream();
View Full Code Here

                        null,              // status
                        "updateTime",      // sortby
                        null,              // locale
                        start,             // offset (for range paging)
                        max + 1);          // maxEntries
                Feed feed = new Feed();
                feed.setId(URLUtilities.getAtomProtocolURL(true)
                    +"/"+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 < mMaxEntries; count++) {
                    WeblogEntryData rollerEntry = (WeblogEntryData)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 = URLUtilities.getAtomProtocolURL(true)+"/"
                            + 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 = URLUtilities.getAtomProtocolURL(true)+"/"
                            +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);
                return feed;
            }
            throw new AtomNotAuthorizedException("ERROR: not authorized to access website");
       
        } catch (RollerException re) {
View Full Code Here

            }
            FileManager fmgr = mRoller.getFileManager();
            WeblogResource[] files = fmgr.getFiles(website, null);
                       
            if (canView(website)) {
                Feed feed = new Feed();
                feed.setId(URLUtilities.getAtomProtocolURL(true)
                    +"/"+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));
               
                SortedSet sortedSet = new TreeSet(new Comparator() {
                    public int compare(Object o1, Object o2) {
                        WeblogResource f1 = (WeblogResource)o1;
                        WeblogResource f2 = (WeblogResource)o2;
                        if (f1.getLastModified() < f2.getLastModified()) return 1;
                        else if (f1.getLastModified() == f2.getLastModified()) return 0;
                        else return -1;
                    }
                    public boolean equals(Object obj) {
                        return false;
                    }              
                });
                List atomEntries = new ArrayList();
                if (files != null && start < files.length) {
                    for (int i=0; i<files.length; i++) {
                        sortedSet.add(files[i]);
                    }
                }
                int count = 0;
                WeblogResource[] sortedArray = (WeblogResource[])sortedSet.toArray(new WeblogResource[sortedSet.size()]);
                for (int i=start; i<(start + max) && i<(sortedArray.length); i++) {
                    Entry entry = createAtomResourceEntry(website, sortedArray[i]);
                    atomEntries.add(entry);
                    if (count == 0) {
                        // first entry is most recent
                        feed.setUpdated(entry.getUpdated());
                    }
                    count++;
                }
                if (start + count < files.length) { // add next link
                    int nextOffset = start + max;
                    String url = URLUtilities.getAtomProtocolURL(true)
                        +"/"+ website.getHandle() + "/resources/" + nextOffset;
                    Link nextLink = new Link();
                    nextLink.setRel("next");
                    nextLink.setHref(url);
                    List next = new ArrayList();
                    next.add(nextLink);
                    feed.setOtherLinks(next);
                }
                if (start > 0) { // add previous link
                    int prevOffset = start > max ? start - max : 0;
                    String url = URLUtilities.getAtomProtocolURL(true)
                        +"/"+website.getHandle() + "/resources/" + prevOffset;
                    Link prevLink = new Link();
                    prevLink.setRel("previous");
                    prevLink.setHref(url);
                    List prev = new ArrayList();
                    prev.add(prevLink);
                    feed.setOtherLinks(prev);
                }
                feed.setEntries(atomEntries);
                return feed;
            }
            throw new AtomNotAuthorizedException(
                "ERROR: not authorized to access website");
      
View Full Code Here

   * <p>By default returns an Atom 1.0 feed, but the subclass can specify any Feed.
   * @see #setFeedType(String)
   */
  @Override
  protected Feed newFeed() {
    return new Feed(this.feedType);
  }
View Full Code Here

                        null,              // status
                        "updateTime",      // sortby
                        null,              // locale
                        start,             // offset (for range paging)
                        max + 1);          // maxEntries
                Feed feed = new Feed();
                feed.setId(URLUtilities.getAtomProtocolURL(true)
                    +"/"+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 < mMaxEntries; count++) {
                    WeblogEntryData rollerEntry = (WeblogEntryData)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 = URLUtilities.getAtomProtocolURL(true)+"/"
                            + 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 = URLUtilities.getAtomProtocolURL(true)+"/"
                            +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);
                return feed;
            }
            throw new AtomNotAuthorizedException("ERROR: not authorized to access website");
       
        } catch (RollerException re) {
View Full Code Here

            }
            FileManager fmgr = mRoller.getFileManager();
            File[] files = fmgr.getFiles(website.getHandle());
                       
            if (canView(website)) {
                Feed feed = new Feed();
                feed.setId(URLUtilities.getAtomProtocolURL(true)
                    +"/"+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));
               
                SortedSet sortedSet = new TreeSet(new Comparator() {
                    public int compare(Object o1, Object o2) {
                        File f1 = (File)o1;
                        File f2 = (File)o2;
                        if (f1.lastModified() < f2.lastModified()) return 1;
                        else if (f1.lastModified() == f2.lastModified()) return 0;
                        else return -1;
                    }
                    public boolean equals(Object obj) {
                        return false;
                    }              
                });
                List atomEntries = new ArrayList();
                if (files != null && start < files.length) {
                    for (int i=0; i<files.length; i++) {
                        sortedSet.add(files[i]);
                    }
                }
                int count = 0;
                File[] sortedArray = (File[])sortedSet.toArray(new File[sortedSet.size()]);
                for (int i=start; i<(start + max) && i<(sortedArray.length); i++) {
                    Entry entry = createAtomResourceEntry(website, sortedArray[i]);
                    atomEntries.add(entry);
                    if (count == 0) {
                        // first entry is most recent
                        feed.setUpdated(entry.getUpdated());
                    }
                    count++;
                }
                if (start + count < files.length) { // add next link
                    int nextOffset = start + max;
                    String url = URLUtilities.getAtomProtocolURL(true)
                        +"/"+ website.getHandle() + "/resources/" + nextOffset;
                    Link nextLink = new Link();
                    nextLink.setRel("next");
                    nextLink.setHref(url);
                    List next = new ArrayList();
                    next.add(nextLink);
                    feed.setOtherLinks(next);
                }
                if (start > 0) { // add previous link
                    int prevOffset = start > max ? start - max : 0;
                    String url = URLUtilities.getAtomProtocolURL(true)
                        +"/"+website.getHandle() + "/resources/" + prevOffset;
                    Link prevLink = new Link();
                    prevLink.setRel("previous");
                    prevLink.setHref(url);
                    List prev = new ArrayList();
                    prev.add(prevLink);
                    feed.setOtherLinks(prev);
                }
                feed.setEntries(atomEntries);
                return feed;
            }
            throw new AtomNotAuthorizedException(
                "ERROR: not authorized to access website");
      
View Full Code Here

                    writer.close();
                    res.setStatus(HttpServletResponse.SC_OK);
                }
                else if (handler.isCollectionURI(pathInfo)) {
                    // return a collection
                    Feed col = handler.getCollection(pathInfo);
                    col.setFeedType(FEED_TYPE);
                    WireFeedOutput wireFeedOutput = new WireFeedOutput();
                    Document feedDoc = wireFeedOutput.outputJDom(col);
                    res.setContentType("application/atom+xml; charset=utf-8");
                    Writer writer = res.getWriter();
                    XMLOutputter outputter = new XMLOutputter();
View Full Code Here

    public static void serializeEntry(Entry entry, Writer writer)
    throws IllegalArgumentException, FeedException, IOException {
        // Build a feed containing only the entry
        List entries = new ArrayList();
        entries.add(entry);
        Feed feed1 = new Feed();
        feed1.setFeedType(AtomServlet.FEED_TYPE);
        feed1.setEntries(entries);
       
        // Get Rome to output feed as a JDOM document
        WireFeedOutput wireFeedOutput = new WireFeedOutput();
        Document feedDoc = wireFeedOutput.outputJDom(feed1);
       
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.