Java Code Examples for com.rometools.rome.io.SyndFeedInput#build()

The following examples show how to use com.rometools.rome.io.SyndFeedInput#build() . 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: PodloveSimpleChapterParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testParseRss() throws Exception {

        log.debug("testParseRss");

        final SyndFeedInput input = new SyndFeedInput();
        final SyndFeed feed = input.build(new XmlReader(new File(getTestFile("psc/rss.xml")).toURI().toURL()));
        final SyndEntry entry = feed.getEntries().get(0);
        final PodloveSimpleChapterModule simpleChapters = (PodloveSimpleChapterModule) entry.getModule(PodloveSimpleChapterModule.URI);

        assertNotNull(simpleChapters);
        for (SimpleChapter c : simpleChapters.getChapters()) {
            assertEquals("00:00:00.000", c.getStart());
            assertEquals("Lorem Ipsum", c.getTitle());
            assertEquals("http://example.org", c.getHref());
            assertEquals("http://example.org/cover", c.getImage());
        }
    }
 
Example 2
Source File: PodloveSimpleChapterGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testGenerateRss() throws Exception {

        log.debug("testGenerateRss");

        final SyndFeedInput input = new SyndFeedInput();
        final SyndFeed feed = input.build(new XmlReader(new File(getTestFile("psc/rss.xml")).toURI().toURL()));
        final SyndEntry entry = feed.getEntries().get(0);
        entry.getModule(PodloveSimpleChapterModule.URI);
        final SyndFeedOutput output = new SyndFeedOutput();
        final StringWriter writer = new StringWriter();
        output.output(feed, writer);

        final String xml = writer.toString();
        log.debug("{}", writer);

        assertTrue(xml.contains("xmlns:psc=\"http://podlove.org/simple-chapters\""));
        assertTrue(xml.contains("<psc:chapters version=\"1.2\">"));
        assertTrue(xml.contains("<psc:chapter start=\"00:00:00.000\" title=\"Lorem Ipsum\" href=\"http://example.org\" image=\"http://example.org/cover\" />"));
    }
 
Example 3
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testResearch2Parse() throws Exception {
    LOG.debug("testResearch2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/research2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final ScholarlyArticle module = (ScholarlyArticle) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image1.jpg", module.getImageLinks()[0].toString());
    cal.set(2005, 11, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "Economy", "Tsunami" }, module.getLabels());
    cal.set(2005, 1, 25);
    Assert.assertEquals("PubDate", cal.getTime(), module.getPublishDate());
    this.assertEquals("Authors", new String[] { "James Smith" }, module.getAuthors());
    Assert.assertEquals("Pub Name", "Tsunami and the Economy", module.getPublicationName());
    Assert.assertEquals("Pub Vol", "III", module.getPublicationVolume());
    Assert.assertEquals("Pages", new Integer(5), module.getPages());
}
 
Example 4
Source File: ContentModuleGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of generate method, of class com.totsp.xml.syndication.content.ContentModuleGenerator.
 */
public void testGenerate() throws Exception {

    LOG.debug("testGenerate");

    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build(new XmlReader(new File(getTestFile("xml/test-rdf.xml")).toURI().toURL()));
    final SyndEntry entry = feed.getEntries().get(0);
    entry.getModule(ContentModule.URI);
    final SyndFeedOutput output = new SyndFeedOutput();
    final StringWriter writer = new StringWriter();
    output.output(feed, writer);

    LOG.debug("{}", writer);

}
 
Example 5
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testPersona2Parse() throws Exception {
    LOG.debug("testPerson2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/personals2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final Person module = (Person) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image1.jpg", module.getImageLinks()[0].toString());
    cal.set(2005, 11, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "Personals", "m4w" }, module.getLabels());
    this.assertEquals("Ethnicity", new String[] { "South Asian" }, module.getEthnicities());
    Assert.assertEquals("Gender", GenderEnumeration.MALE, module.getGender());
    Assert.assertEquals("Sexual Orientation", "straight", module.getSexualOrientation());
    this.assertEquals("Interested In", new String[] { "Single Women" }, module.getInterestedIn());
    Assert.assertEquals("Marital Status", "single", module.getMaritalStatus());
    Assert.assertEquals("Occupation", "Sales", module.getOccupation());
    Assert.assertEquals("Employer", "Google, Inc.", module.getEmployer());
    Assert.assertEquals("Age", new Integer(23), module.getAge());
    Assert.assertEquals("Location", "Anytown, 12345, USA", module.getLocation());

}
 
Example 6
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testWanted2Parse() throws Exception {
    LOG.debug("testVehicle2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/wanted2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final Wanted module = (Wanted) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image1.jpg", module.getImageLinks()[0].toString());
    cal.set(2005, 11, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "Wanted", "Truck" }, module.getLabels());
    Assert.assertEquals("Location", "123 Main Street, Anytown, CA, 12345, USA", module.getLocation());
}
 
Example 7
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testNews2Parse() throws Exception {
    LOG.debug("testNews2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/news2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final Article module = (Article) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image1.jpg", module.getImageLinks()[0].toString());
    cal.set(2007, 2, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "news", "old" }, module.getLabels());
    Assert.assertEquals("Source", "Journal", module.getNewsSource());
    cal.set(1961, 3, 12, 0, 0, 0);
    Assert.assertEquals("Pub Date", cal.getTime(), module.getPublishDate());
    this.assertEquals("Authors", new String[] { "James Smith" }, module.getAuthors());
    Assert.assertEquals("Pages", new Integer(1), module.getPages());

}
 
Example 8
Source File: PodloveSimpleChapterGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testGenerateAtom() throws Exception {

        log.debug("testGenerateAtom");

        final SyndFeedInput input = new SyndFeedInput();
        final SyndFeed feed = input.build(new XmlReader(new File(getTestFile("psc/atom.xml")).toURI().toURL()));
        final SyndEntry entry = feed.getEntries().get(0);
        entry.getModule(PodloveSimpleChapterModule.URI);
        final SyndFeedOutput output = new SyndFeedOutput();
        final StringWriter writer = new StringWriter();
        output.output(feed, writer);

        final String xml = writer.toString();
        log.debug("{}", writer);

        assertTrue(xml.contains("xmlns:psc=\"http://podlove.org/simple-chapters\""));
        assertTrue(xml.contains("<psc:chapters version=\"1.2\">"));
        assertTrue(xml.contains("<psc:chapter start=\"00:00:00.000\" title=\"Lorem Ipsum\" href=\"http://example.org\" image=\"http://example.org/cover\" />"));
    }
 
Example 9
Source File: GeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of generate method, of class com.rometools.rome.feed.module.photocast.io.Generator.
 */
public void testGenerate() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();

    final SyndFeed feed = input.build(new File(super.getTestFile("index.rss")));
    final List<SyndEntry> entries = feed.getEntries();
    for (int i = 0; i < entries.size(); i++) {
        LOG.debug("{}", entries.get(i).getModule(PhotocastModule.URI));
    }
    final SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, new File("target/index.rss"));
    final SyndFeed feed2 = input.build(new File("target/index.rss"));
    final List<SyndEntry> entries2 = feed2.getEntries();
    for (int i = 0; i < entries.size(); i++) {
        assertEquals("Module test", entries.get(i).getModule(PhotocastModule.URI), entries2.get(i).getModule(PhotocastModule.URI));
    }
}
 
Example 10
Source File: CustomTagGeneratorTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testGenerate() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();

    final SyndFeed feed = input.build(new File(super.getTestFile("xml/custom-tags-example.xml")));
    final SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, new File("target/custom-tags-example.xml"));
    final SyndFeed feed2 = input.build(new File("target/custom-tags-example.xml"));

    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final CustomTags customTags = (CustomTags) entry.getModule(CustomTags.URI);

    final List<SyndEntry> entries2 = feed2.getEntries();
    final SyndEntry entry2 = entries2.get(0);
    final CustomTags customTags2 = (CustomTags) entry2.getModule(CustomTags.URI);

    final Iterator<CustomTag> it = customTags.getValues().iterator();
    final Iterator<CustomTag> it2 = customTags2.getValues().iterator();
    while (it.hasNext()) {
        final CustomTag tag = it.next();
        final CustomTag tag2 = it2.next();
        LOG.debug("tag1: {}", tag);
        LOG.debug("tag2: {}", tag2);
        Assert.assertEquals(tag, tag2);
    }
}
 
Example 11
Source File: SSEParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void xtestParseGenerateV5() throws Exception {
    final URL feedURL = new File(getTestFile("xml/v/v5.xml")).toURI().toURL();
    // parse the document for comparison
    final SAXBuilder builder = new SAXBuilder();
    final Document directlyBuilt = builder.build(feedURL);

    // generate the feed back into a document
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed inputFeed = input.build(new XmlReader(feedURL));

    final SyndFeedOutput output = new SyndFeedOutput();
    final Document parsedAndGenerated = output.outputJDom(inputFeed);

    // XMLOutputter outputter = new XMLOutputter();
    // outputter.setFormat(Format.getPrettyFormat());
    // outputter.output(directlyBuilt, new
    // FileOutputStream("c:\\cygwin\\tmp\\sync-direct.xml"));
    // outputter.output(parsedAndGenerated, new
    // FileOutputStream("c:\\cygwin\\tmp\\sync-pg.xml"));

    assertDocumentsEqual(directlyBuilt, parsedAndGenerated);
}
 
Example 12
Source File: WeatherModuleParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testQuickParse() throws Exception {
    LOG.debug("testParse");
    final SyndFeedInput input = new SyndFeedInput();
    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;
        }

        final SyndFeed feed = input.build(testFiles[h]);
        final List<SyndEntry> entries = feed.getEntries();
        for (int i = 0; i < entries.size(); i++) {
            final SyndEntry entry = entries.get(i);
            LOG.debug("{}", entry.getModules().size());
            for (int j = 0; j < entry.getModules().size(); j++) {
                LOG.debug("{}", entry.getModules().get(j).getClass());
                if (entry.getModules().get(j) instanceof YWeatherModule) {
                    final YWeatherModule base = (YWeatherModule) entry.getModules().get(j);
                    assertTrue(((YWeatherEntryModule) base).getForecasts().length > 0);
                    LOG.debug(testFiles[h].getName());

                    final YWeatherEntryModule module2 = new YWeatherModuleImpl();
                    module2.copyFrom(base);
                    assertEquals(((YWeatherEntryModule) base).getForecasts().length, module2.getForecasts().length);

                }
            }
        }
    }
}
 
Example 13
Source File: GoogleBaseGeneratorTest.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.GoogleBaseGenerator.
 */
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(testFiles[h].getName());
        final SyndFeed feed = input.build(testFiles[h]);
        try {
            output.output(feed, new File("target/" + testFiles[h].getName()));
        } catch (final Exception e) {
            throw new RuntimeException(testFiles[h].getAbsolutePath(), e);
        }
        final SyndFeed feed2 = input.build(new File("target/" + testFiles[h].getName()));
        for (int i = 0; i < feed.getEntries().size(); i++) {
            final SyndEntry entry = feed.getEntries().get(i);
            final SyndEntry entry2 = feed2.getEntries().get(i);
            final GoogleBase base = (GoogleBase) entry.getModule(GoogleBase.URI);
            final GoogleBase base2 = (GoogleBase) entry2.getModule(GoogleBase.URI);
            Assert.assertEquals(testFiles[h].getName(), base, base2);
        }
    }

}
 
Example 14
Source File: RssBot.java    From symphony-java-sample-bots with Apache License 2.0 5 votes vote down vote up
private void sendRssFeeds() throws MessagesException, IOException, FeedException {
    sendMessage("Fetching " + feedUrl);
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(feedUrl));
    List<SyndEntry> entries = feed.getEntries();
    sendMessage("Found " + feed.getEntries().size() + " items in the feed; printing the first " + limit);

    for (int i = 0; i < limit; i++) {
        SyndEntry entry = entries.get(i);
        sendMessage(entry.getTitle() + "-" + entry.getLink());
    }
}
 
Example 15
Source File: ITunesGeneratorTest.java    From rome with Apache License 2.0 5 votes vote down vote up
private void testFile(final String filename) throws Exception {
    final File feed = new File(getTestFile(filename));
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL()));

    final SyndFeedOutput output = new SyndFeedOutput();
    final File outfeed = new File(feed.getAbsolutePath() + ".output");
    output.output(syndfeed, outfeed);

    final SyndFeed syndCheck = input.build(new XmlReader(outfeed.toURI().toURL()));
    LOG.debug(syndCheck.getModule(AbstractITunesObject.URI).toString());
    assertEquals("Feed Level: ", syndfeed.getModule(AbstractITunesObject.URI).toString(), syndCheck.getModule(AbstractITunesObject.URI).toString());

    final List<SyndEntry> syndEntries = syndfeed.getEntries();
    final List<SyndEntry> syndChecks = syndCheck.getEntries();

    for (int i = 0; i < syndEntries.size(); i++) {
        final SyndEntry entry = syndEntries.get(i);
        final SyndEntry check = syndChecks.get(i);
        LOG.debug("Original: " + entry.getModule(AbstractITunesObject.URI));
        LOG.debug("Check:    " + check.getModule(AbstractITunesObject.URI));
        LOG.debug(entry.getModule(AbstractITunesObject.URI).toString());
        LOG.debug("-----------------------------------------");
        LOG.debug(check.getModule(AbstractITunesObject.URI).toString());
        assertEquals("Entry Level: ", entry.getModule(AbstractITunesObject.URI).toString(), check.getModule(AbstractITunesObject.URI).toString());
    }
}
 
Example 16
Source File: GoogleTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public static void testGoogleVideo() throws Exception {
    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build(new InputStreamReader(new URL("http://video.google.com/videofeed?type=top100new&num=20&output=rss").openStream()));
    for (final Object element : feed.getEntries()) {
        final SyndEntry entry = (SyndEntry) element;
        final MediaEntryModule m = (MediaEntryModule) entry.getModule(MediaModule.URI);
        System.out.print(m);
    }
}
 
Example 17
Source File: CCModuleGeneratorTest.java    From rome with Apache License 2.0 5 votes vote down vote up
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(testFiles[h].getName());
        final SyndFeed feed = input.build(testFiles[h]);
        // if( !feed.getFeedType().equals("rss_1.0"))
        {
            feed.setFeedType("rss_2.0");
            if (feed.getDescription() == null) {
                feed.setDescription("test file");
            }
            output.output(feed, new File("target/" + testFiles[h].getName()));
            final SyndFeed feed2 = input.build(new File("target/" + testFiles[h].getName()));
            for (int i = 0; i < feed.getEntries().size(); i++) {
                // FIXME
                // final SyndEntry entry = feed.getEntries().get(i);
                final SyndEntry entry2 = feed2.getEntries().get(i);
                // / FIXME
                // final CreativeCommons base = (CreativeCommons)
                // entry.getModule(CreativeCommons.URI);
                final CreativeCommons base2 = (CreativeCommons) entry2.getModule(CreativeCommons.URI);
                LOG.debug("{}", base2);
                // FIXME
                // if( base != null)
                // this.assertEquals( testFiles[h].getName(), base.getLicenses(),
                // base2.getLicenses() );
            }
        }
    }

}
 
Example 18
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 4 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testHousing2Parse() throws Exception {
    LOG.debug("testHousing2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/housing2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    SyndEntry entry = entries.get(0);
    Housing module = (Housing) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image1.jpg", module.getImageLinks()[0].toString());
    cal.set(2007, 11, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "Housing", "New House", "Sale" }, module.getLabels());
    Assert.assertEquals("Currency", CurrencyEnumeration.USD, module.getCurrency());
    Assert.assertEquals("Price", 350000, module.getPrice().getValue(), 0);
    Assert.assertEquals("PriceUnit", null, module.getPrice().getUnits());
    Assert.assertEquals("PriceType", PriceTypeEnumeration.STARTING, module.getPriceType());
    this.assertEquals("Payment Accepted", new PaymentTypeEnumeration[] { PaymentTypeEnumeration.CASH, PaymentTypeEnumeration.CHECK,
            PaymentTypeEnumeration.VISA }, module.getPaymentAccepted());
    Assert.assertEquals("Payment Notes", "1000 deposit", module.getPaymentNotes());
    Assert.assertEquals("Listing Type", new Boolean(true), module.getListingType());
    this.assertEquals("PropertyTypes", new String[] { "Townhouse" }, module.getPropertyTypes());
    Assert.assertEquals("Location", "123 Main St, Anytown, CA, 12345, USA", module.getLocation());
    Assert.assertEquals("Bedrooms", new Integer(3), module.getBedrooms());
    Assert.assertEquals("Bathrooms", new Float(3), module.getBathrooms());
    Assert.assertEquals("Area", 1300, module.getArea().getValue());
    Assert.assertEquals("Area Units", null, module.getArea().getUnits());
    Assert.assertEquals("School District", "Union School District", module.getSchoolDistrict());
    Assert.assertEquals("HOA Dues", new Float(120), module.getHoaDues());
    Assert.assertEquals("Year", "2005", module.getYear().toString());
    this.assertEquals("Agents", new String[] { "Sue Smith" }, module.getAgents());
    Assert.assertEquals("Tax Region", "California", module.getTaxRegion());
    Assert.assertEquals("Tax Percentage", new Float(8.25), module.getTaxPercent());

    entry = entries.get(1);
    module = (Housing) entry.getModule(GoogleBase.URI);
    Assert.assertEquals("Image Link", "http://www.providers-website.com/image2.jpg", module.getImageLinks()[0].toString());
    cal.set(2008, 11, 20, 0, 0, 0);
    Assert.assertEquals("Expiration Date", cal.getTime(), module.getExpirationDate());
    this.assertEquals("Labels", new String[] { "Housing", "rent", "lease" }, module.getLabels());
    Assert.assertEquals("Currency", CurrencyEnumeration.USD, module.getCurrency());
    Assert.assertEquals("Price", 1400, module.getPrice().getValue(), 0);
    Assert.assertEquals("PriceUnit", null, module.getPrice().getUnits());
    Assert.assertEquals("PriceType", PriceTypeEnumeration.STARTING, module.getPriceType());
    this.assertEquals("Payment Accepted", new PaymentTypeEnumeration[] { PaymentTypeEnumeration.CHECK }, module.getPaymentAccepted());
    Assert.assertEquals("Payment Notes", "1000 deposit", module.getPaymentNotes());
    Assert.assertEquals("Listing Type", new Boolean(false), module.getListingType());
    this.assertEquals("PropertyTypes", new String[] { "apartment" }, module.getPropertyTypes());
    Assert.assertEquals("Location", "123 Main St, Anytown, CA, 12345, USA", module.getLocation());
    Assert.assertEquals("Bedrooms", new Integer(2), module.getBedrooms());
    Assert.assertEquals("Bathrooms", new Float(2), module.getBathrooms());
    Assert.assertEquals("Area", 1100, module.getArea().getValue());
    Assert.assertEquals("Area Units", null, module.getArea().getUnits());
    Assert.assertEquals("School District", "Union School District", module.getSchoolDistrict());
    Assert.assertEquals("HOA Dues", null, module.getHoaDues());
    Assert.assertEquals("Year", "2004", module.getYear().toString());
    this.assertEquals("Agents", new String[] { "Sue Smith" }, module.getAgents());
    Assert.assertEquals("Tax Region", null, module.getTaxRegion());
    Assert.assertEquals("Tax Percentage", null, module.getTaxPercent());
}
 
Example 19
Source File: FeedParserBolt.java    From storm-crawler with Apache License 2.0 4 votes vote down vote up
private List<Outlink> parseFeed(String url, byte[] content,
        Metadata parentMetadata) throws Exception {
    List<Outlink> links = new ArrayList<>();

    SyndFeed feed = null;
    try (ByteArrayInputStream is = new ByteArrayInputStream(content)) {
        SyndFeedInput input = new SyndFeedInput();
        feed = input.build(new InputSource(is));
    }

    URL sURL = new URL(url);

    List<SyndEntry> entries = feed.getEntries();
    for (SyndEntry entry : entries) {
        String targetURL = entry.getLink();
        // targetURL can be null?!?
        // e.g. feed does not use links but guid
        if (StringUtils.isBlank(targetURL)) {
            targetURL = entry.getUri();
            if (StringUtils.isBlank(targetURL)) {
                continue;
            }
        }
        Outlink newLink = filterOutlink(sURL, targetURL, parentMetadata);
        if (newLink == null)
            continue;

        String title = entry.getTitle();
        if (StringUtils.isNotBlank(title)) {
            newLink.getMetadata().setValue("feed.title", title.trim());
        }

        Date publishedDate = entry.getPublishedDate();
        if (publishedDate != null) {
            // filter based on the published date
            if (filterHoursSincePub != -1) {
                Calendar rightNow = Calendar.getInstance();
                rightNow.add(Calendar.HOUR, -filterHoursSincePub);
                if (publishedDate.before(rightNow.getTime())) {
                    LOG.info(
                            "{} has a published date {} which is more than {} hours old",
                            targetURL, publishedDate.toString(),
                            filterHoursSincePub);
                    continue;
                }
            }
            newLink.getMetadata().setValue("feed.publishedDate",
                    publishedDate.toString());
        }

        SyndContent description = entry.getDescription();
        if (description != null
                && StringUtils.isNotBlank(description.getValue())) {
            newLink.getMetadata().setValue("feed.description",
                    description.getValue());
        }

        links.add(newLink);
    }

    return links;
}
 
Example 20
Source File: FeedTest.java    From rome with Apache License 2.0 4 votes vote down vote up
protected SyndFeed getSyndFeed() throws Exception {
    final SyndFeedInput in = new SyndFeedInput();
    return in.build(getFeedReader());
}