当前位置: 首页>>代码示例>>Java>>正文


Java SyndFeedInput.build方法代码示例

本文整理汇总了Java中com.rometools.rome.io.SyndFeedInput.build方法的典型用法代码示例。如果您正苦于以下问题:Java SyndFeedInput.build方法的具体用法?Java SyndFeedInput.build怎么用?Java SyndFeedInput.build使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.rometools.rome.io.SyndFeedInput的用法示例。


在下文中一共展示了SyndFeedInput.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
public static void parse(final InputStream in) throws IOException, FeedException {
    try (final XmlReader reader = new XmlReader(in)) {
        final SyndFeedInput input = new SyndFeedInput();

        final SyndFeed feed = input.build(reader);

        final String encoding = feed.getEncoding();

        if (!TextUtils.isEmpty(encoding) &&
                !encoding.equalsIgnoreCase(StandardCharsets.UTF_8.name())) {
            throw new IOException("Unsupported XML encoding");
        }

        CurrentFeed.set(feed);
    }
}
 
开发者ID:Applications-Development,项目名称:SimpleRssReader,代码行数:17,代码来源:RomeFeedParser.java

示例2: run

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
@Scheduled(fixedRate=DateTimeConstants.MILLIS_PER_DAY)
public void run() {
    LocalDateTime lastImport = service.getLastImportDate(PublicationSource.ARXIV);
    for (String feedKey : FEEDS) {
        SyndFeedInput input = new SyndFeedInput();
        try {
            SyndFeed feed = input.build(new XmlReader(new URL(ROOT_RSS_URL + feedKey)));
            List<String> ids = new ArrayList<String>(feed.getEntries().size());
            for (SyndEntry entry : feed.getEntries()) {
                ids.add(entry.getLink().replace(URI_PREFIX, ""));
            }
            
            URL url = new URL("http://export.arxiv.org/api/query?id_list=" + joiner.join(ids) + "&max_results=100");
            try (InputStream inputStream = url.openStream()) {
                List<Publication> publications = extractPublications(inputStream, lastImport, ids.size());
                publications = publications.stream().filter(p -> p.getCreated().isAfter(lastImport)).collect(Collectors.toList());
                logger.info("Obtained publications from arxiv for category {}: {}", feedKey, publications.size());
                service.storePublication(publications);
            }
            
        } catch (IllegalArgumentException | FeedException | IOException e) {
            logger.error("Problem getting arxiv RSS feed", e);
        }
    }
}
 
开发者ID:Glamdring,项目名称:scientific-publishing,代码行数:26,代码来源:ArxivImporter.java

示例3: buildSyndFeed

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * Feedを取得する.
 * @param uri 対象URL
 * @return 取得したSyndFeed
 * @throws IOException IO例外
 * @throws FeedException Feed解析失敗
 * @throws CrawlerException Crawler共通例外
 */
protected SyndFeed buildSyndFeed(URI uri) throws IOException, FeedException, CrawlerException {
    InputStream is = null;
    try {
        is = httpget(uri);
    } catch (UnknownHostException e) {
        log.warn("http request failure url : " + uri.toString());
        throw new CrawlerException();
    }
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = null;
    if (is != null) {
        InputStreamReader sr = new InputStreamReader(is, StandardCharsets.UTF_8);
        feed = input.build(sr);
    }
    return feed;
}
 
开发者ID:codefornamie,项目名称:namie-crawler,代码行数:25,代码来源:ArticleCrawler.java

示例4: xtestParseGenerateV5

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
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);
}
 
开发者ID:rometools,项目名称:rome,代码行数:23,代码来源:SSEParserTest.java

示例5: atestParse

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
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);
            }
        }
    }
 
开发者ID:rometools,项目名称:rome,代码行数:23,代码来源:ModuleParserTest.java

示例6: testResearch2Parse

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:rometools,项目名称:rome-modules,代码行数:24,代码来源:GoogleBaseParserTest.java

示例7: testPersona2Parse

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * 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());

}
 
开发者ID:rometools,项目名称:rome,代码行数:28,代码来源:GoogleBaseParserTest.java

示例8: testNews2Parse

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * 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());

}
 
开发者ID:rometools,项目名称:rome-modules,代码行数:24,代码来源:GoogleBaseParserTest.java

示例9: testWanted2Parse

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * 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());
}
 
开发者ID:rometools,项目名称:rome,代码行数:19,代码来源:GoogleBaseParserTest.java

示例10: assertTestInputStream

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * test expected latitude and longitude values in items of test file.
 *
 * @param in testfeed
 * @param expectedLat expected latitude values
 * @param expectedLng expected longitude values
 * @throws Exception if file not found or not accessible
 */
private void assertTestInputStream(final InputStream in, final Double[] expectedLat, final Double[] expectedLng) throws Exception {
    final SyndFeedInput input = new SyndFeedInput();

    final SyndFeed feed = input.build(new XmlReader(in));

    final List<SyndEntry> entries = feed.getEntries();
    for (int i = 0; i < entries.size(); i++) {
        final SyndEntry entry = entries.get(i);
        final GeoRSSModule geoRSSModule = GeoRSSUtils.getGeoRSS(entry);
        final Position position = geoRSSModule.getPosition();
        if (expectedLat[i] == null || expectedLng[i] == null) {
            assertNull("position " + i, position);
        } else {
            assertEquals("lat " + i, expectedLat[i], position.getLatitude(), DELTA);
            assertEquals("lng " + i, expectedLng[i], position.getLongitude(), DELTA);
        }
    }
}
 
开发者ID:rometools,项目名称:rome,代码行数:27,代码来源:GeoRSSModuleTest.java

示例11: testParse

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * 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));
    }

}
 
开发者ID:rometools,项目名称:rome-modules,代码行数:20,代码来源:ContentModuleParserTest.java

示例12: getFeed

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
private SyndFeed getFeed() throws IOException, FeedException {
    if (feed == null) {
        // Only download once per instance
        SyndFeedInput input = new SyndFeedInput();
        feed = input.build(new XmlReader(download()));
    }

    return feed;
}
 
开发者ID:mapbox,项目名称:mapbox-assistant-example,代码行数:10,代码来源:BlogComponent.java

示例13: load

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
/**
 * Check a RSS flow from an URL
 *
 * @param dataProducer {@link IDataProducer} contains the data queue
 * @see WeatherProducerConnector#source
 * @see WeatherProducerConnector#METRICS_LOGGER
 */
@Override
public void load(IDataProducer dataProducer) {
    Objects.requireNonNull(dataProducer);
    while (!Thread.currentThread().isInterrupted()) {
        try {
            SyndFeedInput input = new SyndFeedInput(false, Locale.FRANCE);
            XmlReader reader = new XmlReader(url);
            SyndFeed feed = input.build(reader);
            long start = System.currentTimeMillis();
            feed.getEntries().forEach(entry -> {
                Date date = entry.getPublishedDate();
                String description = entry.getDescription().getValue();
                GeoRSSModule module = GeoRSSUtils.getGeoRSS(entry);
                if (date == null) {
                    date = Date.from(Instant.now());
                }
                if (description == null) {
                    description = "no description";
                }
                if (module != null && module.getPosition() != null) {
                    LatLong latLong = new LatLong(module.getPosition().getLatitude(), module.getPosition().getLongitude());
                    Event event = new Event(latLong, date, date, description, source);
                    dataProducer.push(event);
                    long end = System.currentTimeMillis();
                    long result = end - start;
                    METRICS_LOGGER.log("time_process_" + this.source, result);
                    LOGGER.info("Event " + event + " has been pushed");
                }
            });
        } catch (IOException | FeedException e) {
            LOGGER.error(e.getMessage());
            return;
        }
    }
}
 
开发者ID:IKB4Stream,项目名称:IKB4Stream,代码行数:43,代码来源:WeatherProducerConnector.java

示例14: readFeeds

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
public List<LinkBean> readFeeds(FeedBean feedBean){

        List<LinkBean> feeds = new ArrayList<LinkBean>();

        try {
            URL url = new URL(feedBean.getUrl());
            SyndFeedInput input = new SyndFeedInput();
            SyndFeed feed = input.build(new XmlReader(url));

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

            for(SyndEntry syndEntry : entryList){
                URL linkUrl = new URL(syndEntry.getLink());

                LinkBean linkBean = new LinkBean();
                linkBean.setTitle(syndEntry.getTitle());
                linkBean.setUrl(linkUrl);
                linkBean.setPublicationDate(syndEntry.getPublishedDate());
                linkBean.setSent(false);
                linkBean.setSubreddit(feedBean.getSubreddit());
                linkBean.setFeedId(feedBean.getId());

                feeds.add(linkBean);
            }
            return feeds;
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return feeds;
    }
 
开发者ID:vitalijzad,项目名称:java-rss-for-reddit,代码行数:31,代码来源:RSSFeedReader.java

示例15: readFeedItems

import com.rometools.rome.io.SyndFeedInput; //导入方法依赖的package包/类
public List<Link> readFeedItems(Feed feed){
    List<Link> feeds = new ArrayList<Link>();

    URL url = null;

    try {
        url = new URL(feed.getUrl());
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed syndFeed = input.build(new XmlReader(url));

        List<SyndEntry> entryList = syndFeed.getEntries();

        for(SyndEntry syndEntry : entryList){

            Link link = new Link();
            link.setTitle(syndEntry.getTitle());
            link.setUrl(syndEntry.getLink());
            link.setPublicationDate(syndEntry.getPublishedDate());
            link.setFeed(feed);

            feeds.add(link);
        }
        return feeds;
    } catch (Exception e) {
        logger.error( "URL: " + url + " message: " + e.getMessage(),e);
    }
    return feeds;
}
 
开发者ID:vitalijzad,项目名称:java-rss-for-reddit,代码行数:29,代码来源:RSSFeedReader.java


注:本文中的com.rometools.rome.io.SyndFeedInput.build方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。