Package com.sun.syndication.feed.atom

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


import com.sun.syndication.feed.atom.Feed;
import com.sun.syndication.feed.atom.Link;

public class AtomFactory {
  public static Feed buildAtom(List<URI> uris) {
    Feed feed = new Feed();
    buildAtomHead(feed, uris);
    buildAtomEntries(feed, uris);
    return feed;
  }
View Full Code Here


        Document entryDoc = builder.build(rd);
        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);
       
        Namespace ns = Namespace.getNamespace(
            "http://roller.apache.org/namespaces/app");
        Element rollerElement = fetchedEntryElement.getChild("atom-draft", ns);
        if (rollerElement == null) {
            log.debug("Client is NOT preserving foreign markup");
        }
               
        WireFeedInput input = new WireFeedInput();
        Feed parsedFeed = (Feed)input.build(feedDoc);
        return (Entry)parsedFeed.getEntries().get(0);
    }
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

            }
            if (!canView(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));

            FileManager fmgr = roller.getFileManager();
            ThemeResource[] files = fmgr.getFiles(website, path);

            SortedSet sortedSet = new TreeSet(new Comparator() {
                public int compare(Object o1, Object o2) {
                    ThemeResource f1 = (ThemeResource)o1;
                    ThemeResource f2 = (ThemeResource)o2;
                    if (f1.getLastModified() < f2.getLastModified()) return 1;
                    else if (f1.getLastModified() == f2.getLastModified()) return 0;
                    else return -1;
                }
            });
                                   
            if (files != null && start < files.length) { 
                for (int j=0; j<files.length; j++) {
                    sortedSet.add(files[j]);
                }
                int count = 0;
                ThemeResource[] sortedResources =
                   (ThemeResource[])sortedSet.toArray(new ThemeResource[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.length) { // 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("Existing");
            return feed;
      
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

                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 feedEntry = (Entry)feed.getEntries().get(0);
        if (feedEntry.getContents().size() != 0) {
            Content content = (Content)feedEntry.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 writeFeedEntry(Entry feedEntry, String feedType, Writer writer) throws IllegalArgumentException, FeedException,
        IOException {
        Feed feed = new Feed();
        feed.setFeedType(feedType);
        List<Entry> feedEntries = new ArrayList<Entry>();
        feedEntries.add(feedEntry);
        feed.setEntries(feedEntries);

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

                    outputter.output(doc, writer);
                    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

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.