com.rometools.rome.feed.synd.SyndEntry Java Examples

The following examples show how to use com.rometools.rome.feed.synd.SyndEntry. 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: 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 #2
Source File: ITunesParserTest.java    From rome with Apache License 2.0 6 votes vote down vote up
/**
 * Test of parse method, of class com.rometools.modules.itunes.io.ITunesParser.
 */
public void testParseItem() throws Exception {
    File feed = new File(getTestFile("xml/leshow.xml"));
    final SyndFeedInput input = new SyndFeedInput();
    SyndFeed syndfeed = input.build(new XmlReader(feed.toURI().toURL()));

    SyndEntry entry = syndfeed.getEntries().get(0);

    EntryInformationImpl entryInfo = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);
    assertEquals(true, entryInfo.getClosedCaptioned());
    assertEquals(Integer.valueOf(2), entryInfo.getOrder());
    assertEquals("http://example.org/image.png", entryInfo.getImage().toString());
    assertFalse(entryInfo.getExplicit());
    assertEquals("test-itunes-title", entryInfo.getTitle());

    SyndEntry entry1 = syndfeed.getEntries().get(1);
    EntryInformationImpl entryInfo1 = (EntryInformationImpl) entry1.getModule(AbstractITunesObject.URI);
    assertTrue(entryInfo1.getExplicit());

    SyndEntry entry2 = syndfeed.getEntries().get(2);
    EntryInformationImpl entryInfo2 = (EntryInformationImpl) entry2.getModule(AbstractITunesObject.URI);
    assertFalse(entryInfo2.getExplicit());
    assertNull(entryInfo2.getExplicitNullable());
}
 
Example #3
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 #4
Source File: MCRRSSFeedImporter.java    From mycore with GNU General Public License v3.0 6 votes vote down vote up
private MCRObject handleFeedEntry(SyndEntry entry, String projectID)
    throws MCRPersistenceException, MCRAccessException {
    String publicationID = getPublicationID(entry);
    if (publicationID == null) {
        return null;
    }

    if (isAlreadyStored(publicationID)) {
        LOGGER.info("publication with ID {} already existing, will not import.", publicationID);
        return null;
    }

    LOGGER.info("publication with ID {} does not exist yet, retrieving data...", publicationID);
    Element publicationXML = retrieveAndConvertPublication(publicationID);
    if (shouldIgnore(publicationXML)) {
        LOGGER.info("publication will be ignored, do not store.");
        return null;
    }

    MCRObject obj = buildMCRObject(publicationXML, projectID);
    MCRMetadataManager.create(obj);
    return obj;
}
 
Example #5
Source File: ThreadingModuleTest.java    From rome with Apache License 2.0 6 votes vote down vote up
public void testReadMainSpec() throws IOException, FeedException {
    final SyndFeed feed = getSyndFeed("thr/threading-main.xml");
    List<SyndEntry> entries = feed.getEntries();
    SyndEntry parentEntry = entries.get(0);
    assertEquals("should be the parent entry", "My original entry", parentEntry.getTitle());
    assertNull(parentEntry.getModule(ThreadingModule.URI));

    SyndEntry replyEntry = entries.get(1);
    assertEquals("should be the reply entry", "A response to the original", replyEntry.getTitle());
    Module module = replyEntry.getModule(ThreadingModule.URI);
    assertNotNull(module);
    ThreadingModule threadingModule = (ThreadingModule) module;
    assertEquals("tag:example.org,2005:1", threadingModule.getRef());
    assertEquals("application/xhtml+xml", threadingModule.getType());
    assertEquals("http://www.example.org/entries/1", threadingModule.getHref());
    assertNull(threadingModule.getSource());
}
 
Example #6
Source File: Entry.java    From commafeed with Apache License 2.0 6 votes vote down vote up
public SyndEntry asRss() {
	SyndEntry entry = new SyndEntryImpl();

	entry.setUri(getGuid());
	entry.setTitle(getTitle());
	entry.setAuthor(getAuthor());

	SyndContentImpl content = new SyndContentImpl();
	content.setValue(getContent());
	entry.setContents(Arrays.<SyndContent> asList(content));

	if (getEnclosureUrl() != null) {
		SyndEnclosureImpl enclosure = new SyndEnclosureImpl();
		enclosure.setType(getEnclosureType());
		enclosure.setUrl(getEnclosureUrl());
		entry.setEnclosures(Arrays.<SyndEnclosure> asList(enclosure));
	}

	entry.setLink(getUrl());
	entry.setPublishedDate(getDate());
	return entry;
}
 
Example #7
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 #8
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 #9
Source File: ConverterForRSS092.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected Item createRSSItem(final SyndEntry sEntry) {

    final Item item = super.createRSSItem(sEntry);

    final List<SyndCategory> sCats = sEntry.getCategories(); // c
    if (!sCats.isEmpty()) {
        item.setCategories(createRSSCategories(sCats));
    }

    final List<SyndEnclosure> sEnclosures = sEntry.getEnclosures();
    if (!sEnclosures.isEmpty()) {
        item.setEnclosures(createEnclosures(sEnclosures));
    }

    return item;

}
 
Example #10
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 #11
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 #12
Source File: ContentBuilder.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Populate a content.
 *
 * @param content The content to polulate
 * @param feedItem The feedItem that contains the informations
 * @param apsAggregatorItem The ApsAggregatorItem that contains informations
 * about categories
 * @param aggregatorConfig The object tha handles the mapping informations
 * @throws ApsSystemException if an error occurs
 */
public void populateContentFromMapping(Content content, SyndEntry feedItem, ApsAggregatorItem apsAggregatorItem, AggregatorConfig aggregatorConfig) throws ApsSystemException {
    //set descrizione contenuto
    this.setContentDescr(content, feedItem, aggregatorConfig);
    //set gruppi;
    this.setContentGroups(content, aggregatorConfig);
    //setta le categorie
    this.setContentCategories(content, apsAggregatorItem);
    List<Element> mappingElements = aggregatorConfig.getAttributes();
    Iterator<Element> mappingElementsIt = mappingElements.iterator();
    while (mappingElementsIt.hasNext()) {
        Element mappingElement = mappingElementsIt.next();
        this.applyAttributeMapping(mappingElement, feedItem, content);
    }
    this.setAggregatorItemParams(content, apsAggregatorItem, feedItem, aggregatorConfig);
}
 
Example #13
Source File: RssManager.java    From entando-components with GNU Lesser General Public License v3.0 6 votes vote down vote up
private List<SyndEntry> getEntries(List<String> contentsId, String lang, String feedLink, HttpServletRequest req,
		HttpServletResponse resp) throws ApsSystemException {
	List<SyndEntry> entries = new ArrayList<SyndEntry>();
	Iterator<String> idIterator = contentsId.iterator();
	while (idIterator.hasNext()) {
		String id = (String) idIterator.next();
		ContentRecordVO currentContent = this.getContentManager().loadContentVO(id);
		RssContentMapping mapping = (RssContentMapping) this.getContentMapping().get(currentContent.getTypeCode());
		if (null == mapping) {
			_logger.error("Null content mapping by existed channel for content type {}", currentContent.getTypeCode());
			continue;
		}
		entries.add(this.createEntry(currentContent, lang, feedLink, req, resp));
	}
	return entries;
}
 
Example #14
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected Item createRSSItem(final SyndEntry sEntry) {

    final Item item = super.createRSSItem(sEntry);

    item.setComments(sEntry.getComments());

    final SyndContent sContent = sEntry.getDescription();

    if (sContent != null) {
        item.setDescription(createItemDescription(sContent));
    }

    final List<SyndContent> contents = sEntry.getContents();

    if (Lists.isNotEmpty(contents)) {
        final SyndContent syndContent = contents.get(0);
        final Content cont = new Content();
        cont.setValue(syndContent.getValue());
        cont.setType(syndContent.getType());
        item.setContent(cont);
    }

    return item;
}
 
Example #15
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 #16
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 #17
Source File: ContentModuleParserTest.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.content.ContentModuleParser.
 * It will test through the whole ROME framework.
 */
public void testParse() throws Exception {

    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);
    final ContentModule module = (ContentModule) entry.getModule(ContentModule.URI);
    final List<ContentItem> items = module.getContentItems();

    for (int i = 0; i < items.size(); i++) {
        // FIXME
        // final ContentItem item = ContentModuleImplTest.contentItems.get(i);
        // assertEquals (item , items.get(i));
    }

}
 
Example #18
Source File: ConverterForRSS10.java    From rome with Apache License 2.0 6 votes vote down vote up
@Override
protected Item createRSSItem(final SyndEntry sEntry) {

    final Item item = super.createRSSItem(sEntry);

    final SyndContent desc = sEntry.getDescription();
    if (desc != null) {
        item.setDescription(createItemDescription(desc));
    }

    final List<SyndContent> contents = sEntry.getContents();
    if (Lists.isNotEmpty(contents)) {
        item.setContent(createItemContent(contents.get(0)));
    }

    final String uri = sEntry.getUri();
    if (uri != null) {
        item.setUri(uri);
    }

    return item;
}
 
Example #19
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 entry 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 SyndEntry entry) {
    final GeoRSSModule simple = (GeoRSSModule) entry.getModule(GeoRSSModule.GEORSS_GEORSS_URI);
    final GeoRSSModule w3cGeo = (GeoRSSModule) entry.getModule(GeoRSSModule.GEORSS_W3CGEO_URI);
    final GeoRSSModule gml = (GeoRSSModule) entry.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 #20
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 #21
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testService2Parse() throws Exception {
    LOG.debug("testService2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/services2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final Service module = (Service) 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[] { "Food delivery" }, module.getLabels());
    cal.set(2005, 2, 24);
    Assert.assertEquals("Currency", CurrencyEnumeration.USD, module.getCurrency());
    Assert.assertEquals("Price", 15, module.getPrice().getValue(), 0);
    Assert.assertEquals("PriceType", PriceTypeEnumeration.STARTING, module.getPriceType());
    this.assertEquals("Payment Accepted", new PaymentTypeEnumeration[] { PaymentTypeEnumeration.VISA, PaymentTypeEnumeration.MASTERCARD },
            module.getPaymentAccepted());
    Assert.assertEquals("Payment Notes", "minimum payment on credit cards:45", module.getPaymentNotes());
    Assert.assertEquals("Service Type", "delivery", module.getServiceType());
    Assert.assertEquals("Location", "Anytown, CA, USA", module.getLocation());
    Assert.assertEquals("DeliveryRad", 20, module.getDeliveryRadius().getValue(), 0);
    Assert.assertEquals("Delivery Notes", "will deliver between 9am -5pm", module.getDeliveryNotes());

}
 
Example #22
Source File: ConverterForRSS091Userland.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected SyndEntry createSyndEntry(final Item item, final boolean preserveWireItem) {

    final SyndEntry syndEntry = super.createSyndEntry(item, preserveWireItem);

    final Description desc = item.getDescription();

    syndEntry.setComments(item.getComments());

    // DublinCoreTest will be failed without this row
    // I don't have better solution
    if (syndEntry.getPublishedDate() == null)
        syndEntry.setPublishedDate(item.getPubDate());

    if (desc != null) {
        final SyndContent descContent = new SyndContentImpl();
        descContent.setType(desc.getType());
        descContent.setValue(desc.getValue());
        syndEntry.setDescription(descContent);
    }

    final Content cont = item.getContent();

    if (cont != null) {
        final SyndContent content = new SyndContentImpl();
        content.setType(cont.getType());
        content.setValue(cont.getValue());

        final List<SyndContent> syndContents = new ArrayList<SyndContent>();
        syndContents.add(content);
        syndEntry.setContents(syndContents);
    }

    return syndEntry;
}
 
Example #23
Source File: ThreadingModuleTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testGenerate() throws IOException, FeedException {
    final SyndFeed feed = getSyndFeed("thr/threading-main.xml");
    List<SyndEntry> entries = feed.getEntries();

    // create a new "root" entry that the next entry will reference to
    SyndEntry newRootEntry = new SyndEntryImpl();
    newRootEntry.setTitle("New, 2nd root entry");
    newRootEntry.setUri("tag:example.org,2005:2");
    newRootEntry.setLink("http://www.example.org/entries/2");
    entries.add(newRootEntry);

    // create a new reply entry that will reference the new root entry
    SyndEntry newReplyEntry = new SyndEntryImpl();
    newReplyEntry.setTitle("New test reply entry");
    newReplyEntry.setUri("tag:example.org,2005:2,1");

    ThreadingModule threadingModule = new ThreadingModuleImpl();
    threadingModule.setRef("tag:example.org,2005:2");
    threadingModule.setType("application/xhtml+xml");
    threadingModule.setHref("http://www.example.org/entries/2");
    threadingModule.setSource("http://example.org/entries/2");

    newReplyEntry.getModules().add(threadingModule);
    entries.add(newReplyEntry);

    File outputFile = new File("target/threading-testGenerate.xml");
    final SyndFeedOutput output = new SyndFeedOutput();
    output.output(feed, outputFile);

    // read back in and validate
    final SyndFeed generatedFeed = getSyndFeed(outputFile);
    SyndEntry generatedReplyEntry = generatedFeed.getEntries().get(3);
    assertNotNull(generatedReplyEntry);
    ThreadingModule generatedReplyThreadingModule = (ThreadingModule) generatedReplyEntry.getModule(ThreadingModule.URI);
    assertEquals("tag:example.org,2005:2", generatedReplyThreadingModule.getRef());
    assertEquals("application/xhtml+xml", generatedReplyThreadingModule.getType());
    assertEquals("http://www.example.org/entries/2", generatedReplyThreadingModule.getHref());
    assertEquals("http://example.org/entries/2", generatedReplyThreadingModule.getSource());
}
 
Example #24
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 #25
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 #26
Source File: GoogleBaseParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
/**
 * Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
 */
public void testJobs2Parse() throws Exception {
    LOG.debug("testJobs2Parse");
    final SyndFeedInput input = new SyndFeedInput();
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    final SyndFeed feed = input.build(new File(super.getTestFile("xml/jobs2.xml")));
    final List<SyndEntry> entries = feed.getEntries();
    final SyndEntry entry = entries.get(0);
    final Job module = (Job) 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[] { "Coordinator", "Google", "Online Support" }, module.getLabels());
    this.assertEquals("Industriy", new String[] { "Internet" }, module.getJobIndustries());
    Assert.assertEquals("Employer", "Google, Inc", module.getEmployer());
    this.assertEquals("Job Function", new String[] { "Google Coordinator" }, module.getJobFunctions());
    LOG.debug("{}", new Object[] { module.getJobTypes() });
    this.assertEquals("Job Type", new String[] { "full-time" }, module.getJobTypes());
    Assert.assertEquals("Currency", CurrencyEnumeration.USD, module.getCurrency());
    Assert.assertEquals("Salary", new Float(40000), module.getSalary());
    Assert.assertEquals("Salary Type", PriceTypeEnumeration.STARTING, module.getSalaryType());
    Assert.assertEquals("Education", "BS", module.getEducation());
    Assert.assertEquals("Immigration", "Permanent Resident", module.getImmigrationStatus());
    Assert.assertEquals("Location", "1600 Amphitheatre Parkway, Mountain View, CA, 94043, USA", module.getLocation());

}
 
Example #27
Source File: ITunesParserTest.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testDuration() throws Exception {
    SyndFeed feed = new SyndFeedInput().build(new XmlReader(getClass().getResource("duration.xml")));
    SyndEntry entry = feed.getEntries().get(0);
    EntryInformationImpl module = (EntryInformationImpl) entry.getModule(AbstractITunesObject.URI);

    assertEquals(1000, module.getDuration().getMilliseconds());
}
 
Example #28
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 #29
Source File: TestSyndFeedAtom10b.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testXmlBaseConformance() throws Exception {
    final SyndFeed feed = getSyndFeed(false);
    final List<SyndEntry> entries = feed.getEntries();
    for (int index = 0; index < entries.size(); index++) {
        final SyndEntry entry = entries.get(index);
        assertEquals("Incorrect URI: " + entry.getLink() + " in entry [" + entry.getTitle() + "]", "http://example.org/tests/base/result.html",
                entry.getLink());
    }
}
 
Example #30
Source File: ConverterForOPML10.java    From rome with Apache License 2.0 5 votes vote down vote up
protected void createEntries(final Stack<Integer> context, final List<SyndEntry> allEntries, final List<Outline> outlines) {
    final List<Outline> so = Collections.synchronizedList(outlines);

    for (int i = 0; i < so.size(); i++) {
        createEntry(context, allEntries, so.get(i));
    }
}