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: 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 #2
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 #3
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 #4
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 #5
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 #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 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 #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 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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
Source File: FeedReader.java    From reactor-workshop with GNU General Public License v3.0 5 votes vote down vote up
public List<SyndEntry> fetch(URL url) throws IOException, FeedException, ParserConfigurationException, SAXException {
    final String feedBody = get(url);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    ByteArrayInputStream is = new ByteArrayInputStream(applyAtomNamespaceFix(feedBody).getBytes(UTF_8));
    Document doc = builder.parse(is);
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(doc);
    return feed.getEntries();
}
 
Example #22
Source File: CsdbReleasesSD2IEC.java    From petscii-bbs with Mozilla Public License 2.0 5 votes vote down vote up
private static List<NewsFeed> getFeeds(String urlString) throws IOException, FeedException {
    URL url = new URL(urlString);
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(url));
    List<CsdbReleasesSD2IEC.NewsFeed> result = new LinkedList<>();
    List<SyndEntry> entries = feed.getEntries();
    for (SyndEntry e : entries)
        result.add(new CsdbReleasesSD2IEC.NewsFeed(
                e.getPublishedDate(),
                e.getTitle().replaceAll("(?is) by .*?$", EMPTY),
                e.getDescription().getValue(),
                e.getUri()));
    return result;
}
 
Example #23
Source File: TelevideoRai.java    From petscii-bbs with Mozilla Public License 2.0 5 votes vote down vote up
public static List<NewsFeed> getFeeds(String urlString) throws IOException, FeedException {
    URL url = new URL(urlString);
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(url));
    List<NewsFeed> result = new LinkedList<>();
    List<SyndEntry> entries = feed.getEntries();
    for (SyndEntry e : entries)
        result.add(new NewsFeed(e.getPublishedDate(), e.getTitle(), e.getDescription().getValue(), e.getUri()));
    return result;
}
 
Example #24
Source File: CsdbReleases.java    From petscii-bbs with Mozilla Public License 2.0 5 votes vote down vote up
private static List<NewsFeed> getFeeds(String urlString) throws IOException, FeedException {
    URL url = new URL(urlString);
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = input.build(new XmlReader(url));
    List<CsdbReleases.NewsFeed> result = new LinkedList<>();
    List<SyndEntry> entries = feed.getEntries();
    for (SyndEntry e : entries)
        result.add(new CsdbReleases.NewsFeed(
                e.getPublishedDate(),
                e.getTitle().replaceAll("(?is) by .*?$", EMPTY),
                e.getDescription().getValue(),
                e.getUri()));
    return result;
}
 
Example #25
Source File: TestSyndFeedRSS092.java    From rome with Apache License 2.0 5 votes vote down vote up
@Override
protected void testItem(final int i) throws Exception {
    super.testItem(i);
    final List<SyndEntry> items = this.getCachedSyndFeed().getEntries();
    final SyndEntry entry = items.get(i);

    assertProperty(entry.getTitle(), "channel.item[" + i + "].title");
    assertProperty(entry.getLink(), "channel.item[" + i + "].link");
    assertProperty(entry.getDescription().getValue(), "channel.item[" + i + "].description");
    testCategories(entry.getCategories(), "channel.item[" + i + "]");
    testEnclosures(entry.getEnclosures(), "channel.item[" + i + "]");
}
 
Example #26
Source File: CallbackController.java    From JuniperBot with GNU General Public License v3.0 5 votes vote down vote up
@RequestMapping(value = "/youtube/callback/publish", method = RequestMethod.POST)
public void youTubeCallback(
        @AtomFeed SyndFeed feed,
        @RequestParam("secret") String secret) {
    if (!Objects.equals(apiProperties.getYouTube().getPubSubSecret(), secret)) {
        throw new AccessDeniedException();
    }
    taskExecutor.execute(() -> {
        if (CollectionUtils.isEmpty(feed.getEntries())) {
            log.warn("Empty YouTube callback");
            return;
        }
        SyndEntry entry = feed.getEntries().get(0);
        String channelId = FeedUtils.getForeignValue(entry, "channelId");
        String videoId = FeedUtils.getForeignValue(entry, "videoId");
        if (StringUtils.isEmpty(channelId)) {
            log.warn("No channelId found in YouTube callback");
            return;
        }
        if (StringUtils.isEmpty(videoId)) {
            log.warn("No videoId found in YouTube callback");
            return;
        }
        if (youTubeRateLimiter.tryAcquire(channelId)) {
            log.info("Notify YouTube Video[channelId={}, videoId={}]", channelId, videoId);
            youTubeService.notifyVideo(channelId, videoId);
        }
    });
}
 
Example #27
Source File: MCRRSSFeedImporter.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
private String getPublicationID(SyndEntry entry) {
    String link = entry.getLink();
    if (link == null) {
        LOGGER.warn("no link found in feed entry");
        return null;
    }
    link = link.trim();
    Matcher m = pattern2findID.matcher(link);
    if (m.matches()) {
        return m.group(1);
    } else {
        LOGGER.warn("no publication ID found in link {}", link);
        return null;
    }
}
 
Example #28
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 #29
Source File: CategoryUpdater.java    From SimpleNews with Apache License 2.0 5 votes vote down vote up
@Override
public List<Entry> call() throws Exception {
    List<Entry> feedEntries = new ArrayList<>();
    try {
        SyndFeed syndFeed = input.build(new XmlReader(new URL(mFeed.getXmlUrl())));
        String title = syndFeed.getTitle();
        if (mFeed.getTitle() == null) {
            mFeed.setTitle(title);
            databaseHandler.updateFeed(mFeed);
        }
        for (SyndEntry item : syndFeed.getEntries()) {
            Entry entry = Utilities.getEntryFromRSSItem(item, mFeed.getId(), title, category.getId());
            if (entry == null) {
                continue;
            }
            if (deprecatedTime == null || (entry.getDate() != null && entry.getDate() > deprecatedTime)) {
                feedEntries.add(entry);
            }
        }
    } catch (Exception e) {
        Log.e("CategoryUpdater", "XmlReader could not read feed", e);
        return null;
    }
    databaseHandler.removeEntries(category.getId(), mFeed.getId(), null);
    databaseHandler.addEntries(category.getId(), mFeed.getId(), feedEntries);
    getPartResult(feedEntries);
    return feedEntries;
}
 
Example #30
Source File: TestSyndFeedAtom10.java    From rome with Apache License 2.0 5 votes vote down vote up
public void testPreservedWireItems() throws Exception {
    final SyndEntry syndEntry1 = this.getCachedSyndFeed(true).getEntries().get(0);
    final Object o = syndEntry1.getWireEntry();
    assertNotNull(o);
    assertTrue(o instanceof Entry);
    if (o instanceof Entry) {
        final Entry entry = (Entry) o;
        assertEquals("atom_1.0.feed.entry[0].rights", entry.getRights());
    }
}