Package com.rometools.rome.feed.atom

Examples of com.rometools.rome.feed.atom.Feed


   * <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


  @Test
  public void read() throws IOException {
    InputStream is = getClass().getResourceAsStream("atom.xml");
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
    inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", utf8));
    Feed result = converter.read(Feed.class, inputMessage);
    assertEquals("title", result.getTitle());
    assertEquals("subtitle", result.getSubtitle().getValue());
    List<?> entries = result.getEntries();
    assertEquals(2, entries.size());

    Entry entry1 = (Entry) entries.get(0);
    assertEquals("id1", entry1.getId());
    assertEquals("title1", entry1.getTitle());
View Full Code Here

    assertEquals("title2", entry2.getTitle());
  }

  @Test
  public void write() throws IOException, SAXException {
    Feed feed = new Feed("atom_1.0");
    feed.setTitle("title");

    Entry entry1 = new Entry();
    entry1.setId("id1");
    entry1.setTitle("title1");

    Entry entry2 = new Entry();
    entry2.setId("id2");
    entry2.setTitle("title2");

    List<Entry> entries = new ArrayList<Entry>(2);
    entries.add(entry1);
    entries.add(entry2);
    feed.setEntries(entries);

    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(feed, null, outputMessage);

    assertEquals("Invalid content-type", new MediaType("application", "atom+xml", utf8),
View Full Code Here

    assertXMLEqual(expected, outputMessage.getBodyAsString(utf8));
  }

  @Test
  public void writeOtherCharset() throws IOException, SAXException {
    Feed feed = new Feed("atom_1.0");
    feed.setTitle("title");
    String encoding = "ISO-8859-1";
    feed.setEncoding(encoding);

    MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
    converter.write(feed, null, outputMessage);

    assertEquals("Invalid content-type", new MediaType("application", "atom+xml", Charset.forName(encoding)),
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

import com.rometools.rome.feed.atom.Feed;

public class TestEqualsBean extends TestCase {

    public void testEquals() {
        final Feed feed1 = new Feed();
        final Feed feed2 = new Feed();
        final Feed feed3 = new Feed();
        final Feed feed4 = new Feed();
        feed4.setId("a");

        // reflexive
        assertTrue(feed1.equals(feed1));

        // symmetric
        assertTrue(feed1.equals(feed2));
        assertTrue(feed2.equals(feed1));

        assertFalse(feed1.equals(feed4));
        assertFalse(feed4.equals(feed1));

        // transitive
        assertTrue(feed1.equals(feed2));
        assertTrue(feed2.equals(feed3));
        assertTrue(feed1.equals(feed3));
View Full Code Here

        return ATOM_NS;
    }

    @Override
    public Document generate(final WireFeed wFeed) throws FeedException {
        final Feed feed = (Feed) wFeed;
        final Element root = createRootElement(feed);
        populateFeed(feed, root);
        purgeUnusedNamespaceDeclarations(root);
        return createDocument(root);
    }
View Full Code Here

    }

    @Override
    public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {

        final Feed aFeed = (Feed) feed;

        syndFeed.setModules(ModuleUtils.cloneModules(aFeed.getModules()));

        final List<Element> foreignMarkup = feed.getForeignMarkup();
        if (Lists.isNotEmpty(foreignMarkup)) {
            syndFeed.setForeignMarkup(foreignMarkup);
        }

        syndFeed.setEncoding(aFeed.getEncoding());
        syndFeed.setStyleSheet(aFeed.getStyleSheet());

        final String logo = aFeed.getLogo();
        final String icon = aFeed.getIcon();

        if (logo != null) {
            final SyndImage image = new SyndImageImpl();
            image.setUrl(logo);
            syndFeed.setImage(image);
        } else if (icon != null) {
            final SyndImage image = new SyndImageImpl();
            image.setUrl(icon);
            syndFeed.setImage(image);
        }

        syndFeed.setUri(aFeed.getId());

        syndFeed.setTitle(aFeed.getTitle());

        // use first alternate links as THE link
        final List<Link> alternateLinks = aFeed.getAlternateLinks();
        if (Lists.isNotEmpty(alternateLinks)) {
            final Link link = alternateLinks.get(0);
            syndFeed.setLink(link.getHrefResolved());
        }
        // lump alternate and other links together
        final List<SyndLink> syndLinks = new ArrayList<SyndLink>();
        if (Lists.isNotEmpty(alternateLinks)) {
            syndLinks.addAll(createSyndLinks(alternateLinks));
        }
        final List<Link> otherLinks = aFeed.getOtherLinks();
        if (Lists.isNotEmpty(otherLinks)) {
            syndLinks.addAll(createSyndLinks(otherLinks));
        }
        syndFeed.setLinks(syndLinks);

        final Content tagline = aFeed.getTagline();
        if (tagline != null) {
            syndFeed.setDescription(tagline.getValue());
        }

        final List<Entry> aEntries = aFeed.getEntries();
        if (Lists.isNotEmpty(aEntries)) {
            syndFeed.setEntries(createSyndEntries(aEntries, syndFeed.isPreservingWireFeed()));
        }

        // Core Atom language/author/copyright/modified elements have precedence
        // over DC equivalent info.

        final String language = aFeed.getLanguage();
        if (language != null) {
            syndFeed.setLanguage(language);
        }

        final List<SyndPerson> authors = aFeed.getAuthors();
        if (Lists.isNotEmpty(authors)) {
            syndFeed.setAuthors(createSyndPersons(authors));
        }

        final String copyright = aFeed.getCopyright();
        if (copyright != null) {
            syndFeed.setCopyright(copyright);
        }

        final Date date = aFeed.getModified();
        if (date != null) {
            syndFeed.setPublishedDate(date);
        }

    }
View Full Code Here

        return syndEncl;
    }

    @Override
    public WireFeed createRealFeed(final SyndFeed syndFeed) {
        final Feed aFeed = new Feed(getType());
        aFeed.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));

        aFeed.setEncoding(syndFeed.getEncoding());
        aFeed.setStyleSheet(syndFeed.getStyleSheet());

        aFeed.setId(syndFeed.getUri());

        final SyndContent sTitle = syndFeed.getTitleEx();
        if (sTitle != null) {

            final Content title = new Content();
            final String type = sTitle.getType();
            if (type != null) {
                title.setType(type);
            }

            final String mode = sTitle.getMode();
            if (mode != null) {
                title.setMode(mode);
            }

            title.setValue(sTitle.getValue());
            aFeed.setTitleEx(title);
        }

        // separate SyndEntry's links collection into alternate and other links
        final List<Link> alternateLinks = new ArrayList<Link>();
        final List<Link> otherLinks = new ArrayList<Link>();

        final List<SyndLink> slinks = syndFeed.getLinks();
        if (slinks != null) {
            for (final SyndLink syndLink2 : slinks) {
                final SyndLink syndLink = syndLink2;
                final Link link = createAtomLink(syndLink);
                final String rel = link.getRel();
                if (Strings.isBlank(rel) || "alternate".equals(rel)) {
                    alternateLinks.add(link);
                } else {
                    otherLinks.add(link);
                }
            }
        }
        // no alternate link? then use THE link if there is one
        final String sLink = syndFeed.getLink();
        if (alternateLinks.isEmpty() && sLink != null) {
            final Link link = new Link();
            link.setRel("alternate");
            link.setHref(sLink);
            alternateLinks.add(link);
        }

        if (!alternateLinks.isEmpty()) {
            aFeed.setAlternateLinks(alternateLinks);
        }
        if (!otherLinks.isEmpty()) {
            aFeed.setOtherLinks(otherLinks);
        }

        final String sDesc = syndFeed.getDescription();
        if (sDesc != null) {
            final Content tagline = new Content();
            tagline.setValue(sDesc);
            aFeed.setTagline(tagline);
        }

        aFeed.setLanguage(syndFeed.getLanguage());

        final List<SyndPerson> authors = syndFeed.getAuthors();
        if (Lists.isNotEmpty(authors)) {
            aFeed.setAuthors(createAtomPersons(authors));
        }

        aFeed.setCopyright(syndFeed.getCopyright());

        aFeed.setModified(syndFeed.getPublishedDate());

        final List<SyndEntry> sEntries = syndFeed.getEntries();
        if (sEntries != null) {
            aFeed.setEntries(createAtomEntries(sEntries));
        }

        return aFeed;
    }
View Full Code Here

        final String type = getType();
        final Document document = eFeed.getDocument();
        final String styleSheet = getStyleSheet(document);

        final Feed feed = new Feed(type);
        feed.setStyleSheet(styleSheet);

        final Element title = eFeed.getChild("title", getAtomNamespace());
        if (title != null) {
            feed.setTitleEx(parseContent(title));
        }

        final List<Element> links = eFeed.getChildren("link", getAtomNamespace());
        feed.setAlternateLinks(parseAlternateLinks(links));
        feed.setOtherLinks(parseOtherLinks(links));

        final Element author = eFeed.getChild("author", getAtomNamespace());
        if (author != null) {
            final List<SyndPerson> authors = new ArrayList<SyndPerson>();
            authors.add(parsePerson(author));
            feed.setAuthors(authors);
        }

        final List<Element> contributors = eFeed.getChildren("contributor", getAtomNamespace());
        if (!contributors.isEmpty()) {
            feed.setContributors(parsePersons(contributors));
        }

        final Element tagline = eFeed.getChild("tagline", getAtomNamespace());
        if (tagline != null) {
            feed.setTagline(parseContent(tagline));
        }

        final Element id = eFeed.getChild("id", getAtomNamespace());
        if (id != null) {
            feed.setId(id.getText());
        }

        final Element generator = eFeed.getChild("generator", getAtomNamespace());
        if (generator != null) {
            final Generator gen = new Generator();
            gen.setValue(generator.getText());
            String att = getAttributeValue(generator, "url");
            if (att != null) {
                gen.setUrl(att);
            }
            att = getAttributeValue(generator, "version");
            if (att != null) {
                gen.setVersion(att);
            }
            feed.setGenerator(gen);
        }

        final Element copyright = eFeed.getChild("copyright", getAtomNamespace());
        if (copyright != null) {
            feed.setCopyright(copyright.getText());
        }

        final Element info = eFeed.getChild("info", getAtomNamespace());
        if (info != null) {
            feed.setInfo(parseContent(info));
        }

        final Element modified = eFeed.getChild("modified", getAtomNamespace());
        if (modified != null) {
            feed.setModified(DateParser.parseDate(modified.getText(), locale));
        }

        feed.setModules(parseFeedModules(eFeed, locale));

        final List<Element> entries = eFeed.getChildren("entry", getAtomNamespace());
        if (!entries.isEmpty()) {
            feed.setEntries(parseEntries(entries, locale));
        }

        final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
        if (!foreignMarkup.isEmpty()) {
            feed.setForeignMarkup(foreignMarkup);
        }

        return feed;

    }
View Full Code Here

TOP

Related Classes of com.rometools.rome.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.