Package com.sun.syndication.feed.atom

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


        public Message invoke(Message msg) {

            // Put an entry
            Object[] args = (Object[])msg.getBody();
            String id = (String)args[0];
            Entry feedEntry = (Entry)args[1];

            // Send an HTTP PUT
            PutMethod putMethod = new PutMethod(uri + "/" + id);
            putMethod.setRequestHeader("Authorization", authorizationHeader);
            try {

                // Write the Atom entry
                StringWriter writer = new StringWriter();
                AtomFeedEntryUtil.writeFeedEntry(feedEntry, "atom_1.0", writer);
                putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8");
                putMethod.setRequestEntity(new StringRequestEntity(writer.toString()));

                httpClient.executeMethod(putMethod);
                int status = putMethod.getStatusCode();

                // Read the Atom entry
                if (status == 200 || status == 201) {
                    try {
                        Entry updatedEntry =
                            AtomFeedEntryUtil.readFeedEntry("atom_1.0", new InputStreamReader(putMethod
                                .getResponseBodyAsStream()));
                        msg.setBody(updatedEntry);
                    } catch (Exception e) {
                        // Returning the updated entry is optional
View Full Code Here


        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()) {
                    element = (Element)element.getChildren().get(0);
                    XMLOutputter outputter = new XMLOutputter();
View Full Code Here

  }

  private static void buildAtomEntries(Feed feed, List<URI> uris) {
    List<Entry> entries = new ArrayList<Entry>();
    for (URI uri : uris) {
      Entry entry = buildEntry(uri);
      entries.add(entry);
    }
    feed.setEntries(entries);
  }
View Full Code Here

    }
    feed.setEntries(entries);
  }

  private static Entry buildEntry(URI uri) {
    Entry entry = new Entry();
    entry.setTitle(uri.toString());
    List<Link> links = buildLinks(uri);
    entry.setOtherLinks(links);
    List<Content> contents = buildContents(uri);
    entry.setContents(contents);
    return entry;
  }
View Full Code Here

            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;
View Full Code Here

                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();
View Full Code Here

     * Create a Rome Atom entry based on a Weblogger entry.
     * Content is escaped.
     * Link is stored as rel=alternate link.
     */
    private Entry createAtomEntry(WeblogEntry entry) {
        Entry atomEntry = new Entry();
       
        String absUrl = WebloggerRuntimeConfig.getAbsoluteContextURL();
        atomEntry.setId(        absUrl + entry.getPermaLink());
        atomEntry.setTitle(     entry.getTitle());
        atomEntry.setPublished( entry.getPubTime());
        atomEntry.setUpdated(   entry.getUpdateTime());
       
        Content content = new Content();
        content.setType(Content.HTML);
        content.setValue(entry.getText());
        List contents = new ArrayList();
        contents.add(content);
       
        atomEntry.setContents(contents);
       
        if (StringUtils.isNotEmpty(entry.getSummary())) {
            Content summary = new Content();
            summary.setType(Content.HTML);
            summary.setValue(entry.getSummary());
            atomEntry.setSummary(summary);
        }
       
        User creator = entry.getCreator();
        Person author = new Person();
        author.setName(         creator.getUserName());
        author.setEmail(        creator.getEmailAddress());
        atomEntry.setAuthors(   Collections.singletonList(author));
       
        // Add Atom category for Weblogger category, using category scheme
        List categories = new ArrayList();
        Category atomCat = new Category();
        atomCat.setScheme(getWeblogCategoryScheme(entry.getWebsite()));
        atomCat.setTerm(entry.getCategory().getPath().substring(1));
        categories.add(atomCat);
       
        // Add Atom categories for each Weblogger tag with null scheme
        for (Iterator tagit = entry.getTags().iterator(); tagit.hasNext();) {
            WeblogEntryTag tag = (WeblogEntryTag) tagit.next();
            Category newcat = new Category();
            newcat.setTerm(tag.getName());
            categories.add(newcat);
        }       
        atomEntry.setCategories(categories);
       
        Link altlink = new Link();
        altlink.setRel("alternate");
        altlink.setHref(absUrl + entry.getPermaLink());
        List altlinks = new ArrayList();
        altlinks.add(altlink);
        atomEntry.setAlternateLinks(altlinks);
       
        Link editlink = new Link();
        editlink.setRel("edit");
        editlink.setHref(
                atomURL
                +"/"+entry.getWebsite().getHandle() + "/entry/" + entry.getId());
        List otherlinks = new ArrayList();
        otherlinks.add(editlink);
        atomEntry.setOtherLinks(otherlinks);
       
        List modules = new ArrayList();
        AppModule app = new AppModuleImpl();
        app.setDraft(!WeblogEntry.PUBLISHED.equals(entry.getStatus()));
        app.setEdited(entry.getUpdateTime());
        modules.add(app);
        atomEntry.setModules(modules);
       
        return atomEntry;
    }
View Full Code Here

                ((MimetypesFileTypeMap)map).addMimeTypes("image/png png PNG");
            } catch (Exception ignored) {}
        }
        String contentType = map.getContentType(file.getName());
       
        Entry entry = new Entry();
        entry.setId(editMediaURI);
        entry.setTitle(file.getName());
        entry.setUpdated(new Date(file.getLastModified()));
       
        List otherlinks = new ArrayList();       
        entry.setOtherLinks(otherlinks);
        Link editlink = new Link();
            editlink.setRel("edit");
            editlink.setHref(editURI);       
            otherlinks.add(editlink);           
        Link editMedialink = new Link();
            editMedialink.setRel("edit-media");
            editMedialink.setHref(editMediaURI);       
            otherlinks.add(editMedialink);
       
        Content content = new Content();
        content.setSrc(viewURI);
        content.setType(contentType);
        List contents = new ArrayList();
        contents.add(content);
        entry.setContents(contents);
       
        List modules = new ArrayList();
        AppModule app = new AppModuleImpl();
        app.setDraft(false);
        app.setEdited(entry.getUpdated());
        modules.add(app);
        entry.setModules(modules);
       
        return entry;
    }
View Full Code Here

                    writer.close();
                    res.setStatus(HttpServletResponse.SC_OK);
                }
                else if (handler.isEntryURI(pathInfo)) {
                    // return an entry
                    Entry entry = handler.getEntry(pathInfo);
                    if (entry != null) {
                        res.setContentType("application/atom+xml; charset=utf-8");
                        Writer writer = res.getWriter();
                        serializeEntry(entry, writer);
                        writer.close();
                    } else {
                        res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                    }
                } else if (handler.isMediaEditURI(pathInfo)) {
                    AtomMediaResource entry = handler.getMediaResource(pathInfo);
                    res.setContentType(entry.getContentType());
                    res.setContentLength(entry.getContentLength());
                    Utilities.copyInputToOutput(entry.getInputStream(), res.getOutputStream());
                    res.getOutputStream().flush();
                    res.getOutputStream().close();               
                } else {
                    res.setStatus(HttpServletResponse.SC_NOT_FOUND);
                }
View Full Code Here

                if (handler.isCollectionURI(pathInfo)) {
                   
                    if (req.getContentType().startsWith("application/atom+xml")) {

                        // parse incoming entry
                        Entry unsavedEntry = parseEntry(new BufferedReader(
                            new InputStreamReader(
                                req.getInputStream(), "UTF-8")));

                        // call handler to post it
                        Entry savedEntry = handler.postEntry(pathInfo, unsavedEntry);
                       
                        // return member entry URI as location header
                        Iterator links = savedEntry.getOtherLinks().iterator();
                        while (links.hasNext()) {
                            Link link = (Link) links.next();
                            if (link.getRel().equals("edit") || link.getRel() == null) {
                                res.addHeader("Location", link.getHref());
                                break;
                            }
                        }
                        // write entry back out to response
                        res.setStatus(HttpServletResponse.SC_CREATED);
                        res.setContentType("application/atom+xml; charset=utf-8");
                        Writer writer = res.getWriter();
                        serializeEntry(savedEntry, writer);
                        writer.close();
                   
                    } else if (req.getContentType() != null) {
                        // get incoming title and slug from HTTP header
                        String title = req.getHeader("Title");
                        String slug = req.getHeader("Slug");

                        // hand input stream off to hander to post file
                        Entry resource = handler.postMedia(
                            pathInfo, title, slug, req.getContentType(), req.getInputStream());
                       
                        res.setStatus(HttpServletResponse.SC_CREATED);
                        com.sun.syndication.feed.atom.Content content =
                            (com.sun.syndication.feed.atom.Content)resource.getContents().get(0);

                        // return member entry URI as location header
                        Iterator links = resource.getOtherLinks().iterator();
                        while (links.hasNext()) {
                            Link link = (Link) links.next();
                            if (link.getRel().equals("edit") || link.getRel() == null) {
                                res.addHeader("Location", link.getHref());
                                break;
View Full Code Here

TOP

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

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.