com.rometools.rome.feed.WireFeed Java Examples

The following examples show how to use com.rometools.rome.feed.WireFeed. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SyndFeedImpl.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a real feed containing the information of the SyndFeedImpl.
 * <p>
 *
 * @param feedType the feed type for the WireFeed to be created.
 * @return the real feed.
 *
 */
@Override
public WireFeed createWireFeed(final String feedType) {

    if (feedType == null) {
        throw new IllegalArgumentException("Feed type cannot be null");
    }

    final Converter converter = CONVERTERS.getConverter(feedType);
    if (converter == null) {
        throw new IllegalArgumentException("Invalid feed type [" + feedType + "]");
    }

    return converter.createRealFeed(this);

}
 
Example #2
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = (Channel) super.createRealFeed(type, syndFeed);
    channel.setLanguage(syndFeed.getLanguage()); // c
    channel.setCopyright(syndFeed.getCopyright()); // c
    channel.setPubDate(syndFeed.getPublishedDate()); // c
    channel.setDocs(syndFeed.getDocs());
    channel.setManagingEditor(syndFeed.getManagingEditor());
    channel.setWebMaster(syndFeed.getWebMaster());
    channel.setGenerator(syndFeed.getGenerator());

    final List<SyndPerson> authors = syndFeed.getAuthors();
    if (Lists.isNotEmpty(authors)) {
        final SyndPerson author = authors.get(0);
        channel.setManagingEditor(author.getName());
    }

    return channel;
}
 
Example #3
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {

    final Channel channel = (Channel) super.createRealFeed(type, syndFeed);

    final String uri = syndFeed.getUri();
    if (uri != null) {
        channel.setUri(uri);
    } else {
        // if URI is not set use the value for link
        final String link = syndFeed.getLink();
        channel.setUri(link);
    }

    return channel;
}
 
Example #4
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {

    final Channel channel = (Channel) feed;

    super.copyInto(channel, syndFeed);

    final String uri = channel.getUri();
    if (uri != null) {
        syndFeed.setUri(uri);
    } else {
        // if URI is not set use the value for link
        final String link = channel.getLink();
        syndFeed.setUri(link);
    }
}
 
Example #5
Source File: RSS094Parser.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = (Channel) super.parseChannel(rssRoot, locale);

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());

    final List<Element> categories = eChannel.getChildren("category", getRSSNamespace());
    channel.setCategories(parseCategories(categories));

    final Element ttl = eChannel.getChild("ttl", getRSSNamespace());
    if (ttl != null && ttl.getText() != null) {
        final Integer ttlValue = NumberParser.parseInt(ttl.getText());
        if (ttlValue != null) {
            channel.setTtl(ttlValue);
        }
    }

    return channel;
}
 
Example #6
Source File: SyndFeedImpl.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a SyndFeedImpl and populates all its properties out of the given RSS Channel or Atom
 * Feed properties, while optionally preserving the WireFeed for access via the
 * orignalWireFeed() method.
 */
public SyndFeedImpl(final WireFeed feed, final boolean preserveWireFeed) {
    this(SyndFeed.class, IGNORE_PROPERTIES);

    if (preserveWireFeed) {
        wireFeed = feed;
        this.preserveWireFeed = preserveWireFeed;
    }

    if (feed != null) {
        feedType = feed.getFeedType();
        final Converter converter = CONVERTERS.getConverter(feedType);
        if (converter == null) {
            throw new IllegalArgumentException("Invalid feed type [" + feedType + "]");
        }
        converter.copyInto(feed, this);
    }

}
 
Example #7
Source File: FileBasedCollection.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Get feed document representing collection.
 *
 * @throws com.rometools.rome.propono.atom.server.AtomException On error retrieving feed file.
 * @return Atom Feed representing collection.
 */
public Feed getFeedDocument() throws AtomException {
    InputStream in = null;
    synchronized (FileStore.getFileStore()) {
        in = FileStore.getFileStore().getFileInputStream(getFeedPath());
        if (in == null) {
            in = createDefaultFeedDocument(contextURI + servletPath + "/" + handle + "/" + collection);
        }
    }
    try {
        final WireFeedInput input = new WireFeedInput();
        final WireFeed wireFeed = input.build(new InputStreamReader(in, "UTF-8"));
        return (Feed) wireFeed;
    } catch (final Exception ex) {
        throw new AtomException(ex);
    }
}
 
Example #8
Source File: ConverterForRSS090.java    From rome with Apache License 2.0 5 votes vote down vote up
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = new Channel(type);
    channel.setModules(ModuleUtils.cloneModules(syndFeed.getModules()));
    channel.setStyleSheet(syndFeed.getStyleSheet());
    channel.setEncoding(syndFeed.getEncoding());

    channel.setTitle(syndFeed.getTitle());
    final String link = syndFeed.getLink();
    final List<SyndLink> links = syndFeed.getLinks();
    if (link != null) {
        channel.setLink(link);
    } else if (!links.isEmpty()) {
        channel.setLink(links.get(0).getHref());
    }

    channel.setDescription(syndFeed.getDescription());

    final SyndImage sImage = syndFeed.getImage();
    if (sImage != null) {
        channel.setImage(createRSSImage(sImage));
    }

    final List<SyndEntry> sEntries = syndFeed.getEntries();
    if (sEntries != null) {
        channel.setItems(createRSSItems(sEntries));
    }

    final List<Element> foreignMarkup = syndFeed.getForeignMarkup();
    if (!foreignMarkup.isEmpty()) {
        channel.setForeignMarkup(foreignMarkup);
    }

    return channel;
}
 
Example #9
Source File: TestOpsOPML10links.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
    PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1"));
    w.println(sFeed1.toString());
    w.close();
    w = new PrintWriter(new FileOutputStream("target/test-reports/2"));
    w.println(sFeed2.toString());
    w.close();

    assertEquals(sFeed2.createWireFeed(), sFeed1.createWireFeed());
}
 
Example #10
Source File: TestOpsOPML20.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
    PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/3"));
    w.println(sFeed1.toString());
    w.close();
    w = new PrintWriter(new FileOutputStream("target/test-reports/4"));
    w.println(sFeed2.toString());
    w.close();
    assertEquals(sFeed1, sFeed2);
}
 
Example #11
Source File: FeedOpsTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);

    assertEquals(sFeed1, sFeed2);
}
 
Example #12
Source File: ConverterForRSS090.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {

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

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

    syndFeed.setStyleSheet(feed.getStyleSheet());

    syndFeed.setEncoding(feed.getEncoding());

    final Channel channel = (Channel) feed;

    syndFeed.setTitle(channel.getTitle());
    syndFeed.setLink(channel.getLink());
    syndFeed.setDescription(channel.getDescription());

    final Image image = channel.getImage();
    if (image != null) {
        syndFeed.setImage(createSyndImage(image));
    }

    final List<Item> items = channel.getItems();
    if (items != null) {
        syndFeed.setEntries(createSyndEntries(items, syndFeed.isPreservingWireFeed()));
    }
}
 
Example #13
Source File: TestOpsOPML10links.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testTemp() throws Exception {
    final WireFeedInput input = new WireFeedInput();
    final WireFeed wf = input.build(TestUtil.loadFile("/opml_1.0_links.xml"));
    final WireFeedOutput output = new WireFeedOutput();

    final SyndFeedImpl sf = new SyndFeedImpl(wf);
    sf.setFeedType("rss_2.0");
    sf.setDescription("");
    sf.setLink("http://foo.com");
    sf.setFeedType("opml_1.0");
    output.output(sf.createWireFeed(), new NullWriter());
}
 
Example #14
Source File: Atom03Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: ConverterForRSS094.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected WireFeed createRealFeed(final String type, final SyndFeed syndFeed) {
    final Channel channel = (Channel) super.createRealFeed(type, syndFeed);
    final List<SyndCategory> cats = syndFeed.getCategories(); // c
    if (!cats.isEmpty()) {
        channel.setCategories(createRSSCategories(cats));
    }
    return channel;
}
 
Example #16
Source File: FeedOpsTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testWireFeedSerialization() throws Exception {
    final WireFeed feed1 = getCachedWireFeed();

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(feed1);
    oos.close();

    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream ois = new ObjectInputStream(bais);
    final WireFeed feed2 = (WireFeed) ois.readObject();
    ois.close();

    assertTrue(feed1.equals(feed2));
}
 
Example #17
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException {
    if (validate) {
        validateFeed(document);
    }
    final Element rssRoot = document.getRootElement();
    return parseFeed(rssRoot, locale);
}
 
Example #18
Source File: RSS10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {

    final Channel channel = (Channel) super.parseChannel(rssRoot, locale);

    final Element eChannel = rssRoot.getChild("channel", getRSSNamespace());
    final String uri = eChannel.getAttributeValue("about", getRDFNamespace());
    if (uri != null) {
        channel.setUri(uri);
    }

    return channel;
}
 
Example #19
Source File: Atom10Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
protected WireFeed parseFeed(final Element eFeed, final Locale locale) throws FeedException {

        String baseURI = null;
        try {
            baseURI = findBaseURI(eFeed);
        } catch (final Exception e) {
            throw new FeedException("ERROR while finding base URI of feed", e);
        }

        final Feed feed = parseFeedMetadata(baseURI, eFeed, locale);
        feed.setStyleSheet(getStyleSheet(eFeed.getDocument()));

        final String xmlBase = eFeed.getAttributeValue("base", Namespace.XML_NAMESPACE);
        if (xmlBase != null) {
            feed.setXmlBase(xmlBase);
        }

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

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

        final List<Element> foreignMarkup = extractForeignMarkup(eFeed, feed, getAtomNamespace());
        if (!foreignMarkup.isEmpty()) {
            feed.setForeignMarkup(foreignMarkup);
        }
        return feed;
    }
 
Example #20
Source File: RSS090Parser.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public WireFeed parse(final Document document, final boolean validate, final Locale locale) throws IllegalArgumentException, FeedException {

    if (validate) {
        validateFeed(document);
    }

    final Element rssRoot = document.getRootElement();
    return parseChannel(rssRoot, locale);
}
 
Example #21
Source File: Atom10Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: RSS090Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public Document generate(final WireFeed feed) throws FeedException {
    final Channel channel = (Channel) feed;
    final Element root = createRootElement(channel);
    populateFeed(channel, root);
    purgeUnusedNamespaceDeclarations(root);
    return createDocument(root);
}
 
Example #23
Source File: RSS20wNSParser.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * After we parse the feed we put "rss_2.0" in it (so converters and generators work) this
 * parser is a phantom.
 *
 */
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
    final WireFeed wFeed = super.parseChannel(rssRoot, locale);
    wFeed.setFeedType("rss_2.0");
    return wFeed;
}
 
Example #24
Source File: RSS20YahooParser.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * After we parse the feed we put "rss_2.0" in it (so converters and generators work) this
 * parser is a phantom.
 *
 */
@Override
protected WireFeed parseChannel(final Element rssRoot, final Locale locale) {
    final WireFeed wFeed = super.parseChannel(rssRoot, locale);
    wFeed.setFeedType("rss_2.0");

    return wFeed;
}
 
Example #25
Source File: TestOpsOPML10.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);
    PrintWriter w = new PrintWriter(new FileOutputStream("target/test-reports/1"));
    w.println(sFeed1.toString());
    w.close();
    w = new PrintWriter(new FileOutputStream("target/test-reports/2"));
    w.println(sFeed2.toString());
    w.close();

    assertEquals(sFeed1, sFeed2);
}
 
Example #26
Source File: TestSyndFeedRSS20.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testPreserveWireFeedComments() throws Exception {
    final WireFeed wf = this.getCachedSyndFeed(true).originalWireFeed();
    assertNotNull(wf);
    assertTrue(wf instanceof Channel);
    if (wf instanceof Channel) {
        final Channel channel = (Channel) wf;
        assertEquals("rss_2.0.channel.item[0].comments", channel.getItems().get(0).getComments());
        assertEquals("rss_2.0.channel.item[1].comments", channel.getItems().get(1).getComments());
    }
}
 
Example #27
Source File: FeedOpsTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testWireFeedSerialization() throws Exception {
    final WireFeed feed1 = getCachedWireFeed();

    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(feed1);
    oos.close();

    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream ois = new ObjectInputStream(bais);
    final WireFeed feed2 = (WireFeed) ois.readObject();
    ois.close();

    assertTrue(feed1.equals(feed2));
}
 
Example #28
Source File: FeedOpsTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testWireFeedSyndFeedConversion() throws Exception {
    final SyndFeed sFeed1 = this.getCachedSyndFeed();
    final WireFeed wFeed1 = sFeed1.createWireFeed();
    final SyndFeed sFeed2 = new SyndFeedImpl(wFeed1);

    assertTrue(sFeed1.equals(sFeed2));
}
 
Example #29
Source File: ConverterForOPML10.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Makes a deep copy/conversion of the values of a real feed into a SyndFeedImpl.
 * <p>
 * It assumes the given SyndFeedImpl has no properties set.
 * <p>
 *
 * @param feed real feed to copy/convert.
 * @param syndFeed the SyndFeedImpl that will contain the copied/converted values of the real feed.
 */
@Override
public void copyInto(final WireFeed feed, final SyndFeed syndFeed) {
    final Opml opml = (Opml) feed;
    syndFeed.setTitle(opml.getTitle());
    addOwner(opml, syndFeed);
    syndFeed.setPublishedDate(opml.getModified() != null ? opml.getModified() : opml.getCreated());
    syndFeed.setFeedType(opml.getFeedType());
    syndFeed.setModules(opml.getModules());
    syndFeed.setFeedType(getType());

    createEntries(new Stack<Integer>(), syndFeed.getEntries(), opml.getOutlines());
}
 
Example #30
Source File: OPML10Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an XML document (JDOM) for the given feed bean.
 *
 * @param feed the feed bean to generate the XML document from.
 * @return the generated XML document (JDOM).
 * @throws IllegalArgumentException thrown if the type of the given feed bean does not match with the type of the
 *             WireFeedGenerator.
 * @throws FeedException thrown if the XML Document could not be created.
 */
@Override
public Document generate(final WireFeed feed) throws IllegalArgumentException, FeedException {

    if (!(feed instanceof Opml)) {
        throw new IllegalArgumentException("Not an OPML file");
    }

    final Opml opml = (Opml) feed;
    final Document doc = new Document();
    final Element root = new Element("opml");
    root.setAttribute("version", "1.0");
    doc.addContent(root);

    final Element head = generateHead(opml);

    if (head != null) {
        root.addContent(head);
    }

    final Element body = new Element("body");
    root.addContent(body);
    super.generateFeedModules(opml.getModules(), root);
    body.addContent(generateOutlines(opml.getOutlines()));

    return doc;
}