Java Code Examples for com.rometools.rome.feed.synd.SyndFeed#getModule()

The following examples show how to use com.rometools.rome.feed.synd.SyndFeed#getModule() . 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: GeoRSSUtils.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * This convenience method checks whether there is any geoRss Element and will return it (georss
 * simple or W3GGeo).
 *
 * @param feed the element in the feed which might have a georss element
 * @return a georssmodule or null if none is present
 */
public static GeoRSSModule getGeoRSS(final SyndFeed feed) {
    final GeoRSSModule simple = (GeoRSSModule) feed.getModule(GeoRSSModule.GEORSS_GEORSS_URI);
    final GeoRSSModule w3cGeo = (GeoRSSModule) feed.getModule(GeoRSSModule.GEORSS_W3CGEO_URI);
    final GeoRSSModule gml = (GeoRSSModule) feed.getModule(GeoRSSModule.GEORSS_GML_URI);

    if (gml != null) {
        return gml;
    }
    if (simple != null) {
        return simple;
    }
    if (w3cGeo != null) {
        return w3cGeo;
    }

    return null;
    /*
     * if (geoRSSModule == null && w3cGeo != null) { geoRSSModule = w3cGeo; } else if
     * (geoRSSModule == null && gml != null) { geoRSSModule = gml; } else if (geoRSSModule !=
     * null && w3cGeo != null) { // sanity check if
     * (!geoRSSModule.getGeometry().equals(w3cGeo.getGeometry())) { throw new
     * Error("geometry of simple and w3c do not match"); } } return geoRSSModule;
     */
}
 
Example 2
Source File: OpenSearchModuleTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testEndToEnd() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();
    final File test = new File(super.getTestFile("os"));
    final File[] files = test.listFiles();
    for (int j = 0; j < files.length; j++) {
        if (!files[j].getName().endsWith(".xml")) {
            continue;
        }
        final SyndFeed feed = input.build(files[j]);
        final Module m = feed.getModule(OpenSearchModule.URI);
        final SyndFeedOutput output = new SyndFeedOutput();
        final File outfile = new File("target/" + files[j].getName());
        output.output(feed, outfile);
        final SyndFeed feed2 = input.build(outfile);
        assertEquals(m, feed2.getModule(OpenSearchModule.URI));
    }
}
 
Example 3
Source File: ModuleParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void atestParse() throws Exception {

        final SyndFeedInput input = new SyndFeedInput();
        final File testDir = new File(super.getTestFile("test/xml"));
        final File[] testFiles = testDir.listFiles();
        for (int h = 0; h < testFiles.length; h++) {
            if (!testFiles[h].getName().endsWith(".xml")) {
                continue;
            }
            LOG.debug(testFiles[h].getName());
            final SyndFeed feed = input.build(testFiles[h]);
            final List<SyndEntry> entries = feed.getEntries();
            final CreativeCommons fMod = (CreativeCommons) feed.getModule(CreativeCommons.URI);
            LOG.debug("{}", fMod);
            for (int i = 0; i < entries.size(); i++) {
                final SyndEntry entry = entries.get(i);
                final CreativeCommons eMod = (CreativeCommons) entry.getModule(CreativeCommons.URI);
                LOG.debug("\nEntry:");
                LOG.debug("{}", eMod);
            }
        }
    }
 
Example 4
Source File: ModuleParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.rometools.rome.feed.module.sle.io.ModuleParser.
 */
public void testParse() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build(new File(super.getTestFile("data/bookexample.xml")));
    final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);

    assertEquals("list", sle.getTreatAs());
    final Group[] groups = sle.getGroupFields();
    assertEquals("genre", groups[0].getElement());
    assertEquals("Genre", groups[0].getLabel());
    final Sort[] sorts = sle.getSortFields();
    assertEquals("Relevance", sorts[0].getLabel());
    assertTrue(sorts[0].getDefaultOrder());
    assertEquals(sorts[1].getNamespace(), Namespace.getNamespace("http://www.example.com/book"));
    assertEquals(sorts[1].getDataType(), Sort.DATE_TYPE);
    assertEquals(sorts[1].getElement(), "firstedition");
    final SyndEntry entry = feed.getEntries().get(0);
    final SleEntry sleEntry = (SleEntry) entry.getModule(SleEntry.URI);
    LOG.debug("{}", sleEntry);
    LOG.debug("getGroupByElement");
    LOG.debug("{}", sleEntry.getGroupByElement(groups[0]));
    LOG.debug("getSortByElement");
    LOG.debug("{}", sleEntry.getSortByElement(sorts[0]));
}
 
Example 5
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testExplicitnessTrue() throws Exception {
    ArrayList<String> xmlFiles = new ArrayList<String>();
    xmlFiles.add("explicitness-capital-yes.xml");
    xmlFiles.add("explicitness-yes.xml");

    for (String xml : xmlFiles) {
        SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource(xml)));
        FeedInformationImpl module = (FeedInformationImpl) feed.getModule(AbstractITunesObject.URI);

        assertTrue(module.getExplicitNullable());
    }
}
 
Example 6
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testExplicitnessFalse() throws Exception {
    ArrayList<String> xmlFiles = new ArrayList<String>();
    xmlFiles.add("explicitness-no.xml");
    xmlFiles.add("explicitness-clean.xml");

    for (String xml : xmlFiles) {
        SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource(xml)));
        FeedInformationImpl module = (FeedInformationImpl) feed.getModule(AbstractITunesObject.URI);

        assertFalse(module.getExplicitNullable());
    }
}
 
Example 7
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testParseNonHttpUris() throws Exception {
    File feed = new File(getTestFile("itunes/no-http-uris.xml"));
    final SyndFeedInput input = new SyndFeedInput();
    SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL()));

    final FeedInformationImpl feedInfo = (FeedInformationImpl) syndfeed.getModule(AbstractITunesObject.URI);

    assertEquals(URI.create("file://some-location/1.jpg"), feedInfo.getImageUri());

    SyndEntry entry = syndfeed.getEntries().get(0);
    EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

    assertEquals(URI.create("gs://some-location/2.jpg"), module.getImageUri());
}
 
Example 8
Source File: AtomLinkTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void test() throws Exception {

        final File testdata = new File(super.getTestFile("atom/atom.xml"));
        final SyndFeed feed = new SyndFeedInput().build(testdata);

        final AtomLinkModule atomLinkModule = (AtomLinkModule) feed.getModule(AtomLinkModule.URI);
        List<Link> links = atomLinkModule.getLinks();
        for (int i = 0; i < links.size(); i++) {
            Link link = links.get(i);
            assertEquals(href[i], link.getHref());
            assertEquals(rel[i], link.getRel());
            assertEquals(type[i], link.getType());
        }

    }
 
Example 9
Source File: WeatherGeneratorTest.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Test of generate method, of class com.totsp.xml.syndication.base.io.SlashGenerator.
 *
 * @throws Exception on error
 */
public void testGenerate() throws Exception {
    LOG.debug("testGenerate");
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeedOutput output = new SyndFeedOutput();
    final File testDir = new File(super.getTestFile("xml"));
    final File[] testFiles = testDir.listFiles();
    for (int h = 0; h < testFiles.length; h++) {
        if (!testFiles[h].getName().endsWith(".xml")) {
            continue;
        }
        LOG.debug("processing" + testFiles[h]);
        final SyndFeed feed = input.build(testFiles[h]);
        output.output(feed, new File("target/" + testFiles[h].getName()));
        final SyndFeed feed2 = input.build(new File("target/" + testFiles[h].getName()));
        final YWeatherModule weather = (YWeatherModule) feed.getModule(YWeatherModule.URI);
        final YWeatherModule weather2 = (YWeatherModule) feed2.getModule(YWeatherModule.URI);
        Assert.assertEquals(testFiles[h].getName(), weather, weather2);
        for (int i = 0; i < feed.getEntries().size(); i++) {
            final SyndEntry entry = feed.getEntries().get(i);
            final SyndEntry entry2 = feed2.getEntries().get(i);
            final YWeatherModule weatherEntry = (YWeatherModule) entry.getModule(YWeatherModule.URI);
            final YWeatherModule weatherEntry2 = (YWeatherModule) entry2.getModule(YWeatherModule.URI);
            assertEquals(testFiles[h].getName(), weatherEntry, weatherEntry2);
        }
    }

}
 
Example 10
Source File: GroupAndSortTest.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Test of sort method, of class com.rometools.rome.feed.module.sle.GroupAndSort.
 */
public void testSort2() throws Exception {

    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build(new File(super.getTestFile("data/YahooTopSongs.xml")));
    final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);

    final List<Extendable> entries = new ArrayList<Extendable>(feed.getEntries());
    final List<Extendable> sortedEntries = SleUtility.sort(entries, sle.getSortFields()[0], true);
    for (int i = 0; i < sortedEntries.size(); i++) {
        final SyndEntry entry = (SyndEntry) sortedEntries.get(i);
        LOG.debug(entry.getTitle());
    }

}
 
Example 11
Source File: GroupAndSortTest.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Test of sort method, of class com.rometools.rome.feed.module.sle.GroupAndSort.
 */
public void testSort() throws Exception {

    final File testdata = new File(super.getTestFile("data/bookexample.xml"));
    final SyndFeed feed = new SyndFeedInput().build(testdata);

    List<SyndEntry> entries = feed.getEntries();

    final SimpleListExtension extention = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);
    final Sort[] sortFields = extention.getSortFields();

    final Sort sortByDate = sortFields[1];
    final Sort sortByTitle = sortFields[2];

    // sort by date ascending
    List<SyndEntry> sortedEntries = SleUtility.sort(entries, sortByDate, true);
    SyndEntry entry = sortedEntries.get(0);
    assertEquals("Great Journeys of the Past", entry.getTitle());

    // sort by date descending
    sortedEntries = SleUtility.sort(entries, sortByDate, false);
    entry = sortedEntries.get(0);
    assertEquals("Horror Stories, vol 16", entry.getTitle());

    // sort by date ascending
    sortedEntries = SleUtility.sort(entries, sortByDate, true);

    // update first entry and reinitialize
    entry = sortedEntries.get(0);
    entry.setTitle("ZZZZZ");
    SleUtility.initializeForSorting(feed);
    entries = feed.getEntries();

    // sort by title desc
    sortedEntries = SleUtility.sort(entries, sortByTitle, false);
    entry = sortedEntries.get(0);
    assertEquals("ZZZZZ", entry.getTitle());

    // sort by title asc
    sortedEntries = SleUtility.sort(entries, sortByTitle, true);
    entry = sortedEntries.get(0);
    assertEquals("Horror Stories, vol 16", entry.getTitle());

}
 
Example 12
Source File: GroupAndSortTest.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Test of sortAndGroup method, of class com.rometools.rome.feed.module.sle.GroupAndSort.
 */
public void testSortAndGroup() throws Exception {

    final File testdata = new File(super.getTestFile("data/bookexample.xml"));
    final SyndFeed feed = new SyndFeedInput().build(testdata);

    final List<SyndEntry> feedEntries = feed.getEntries();
    final List<Extendable> entries = new ArrayList<Extendable>(feedEntries);

    final SimpleListExtension sle = (SimpleListExtension) feed.getModule(SimpleListExtension.URI);
    final Sort[] sortFields = sle.getSortFields();

    final Sort sortByTitle = sortFields[2];

    final List<Extendable> sortedEntries = SleUtility.sortAndGroup(entries, sle.getGroupFields(), sortByTitle, true);
    final SyndEntry entry = (SyndEntry) sortedEntries.get(0);
    assertEquals("Horror Stories, vol 16", entry.getTitle());

}