本文整理汇总了Java中com.rometools.rome.io.SyndFeedInput类的典型用法代码示例。如果您正苦于以下问题:Java SyndFeedInput类的具体用法?Java SyndFeedInput怎么用?Java SyndFeedInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyndFeedInput类属于com.rometools.rome.io包,在下文中一共展示了SyndFeedInput类的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);
}
}
示例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);
}
}
}
示例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;
}
示例4: testGenerate
import com.rometools.rome.io.SyndFeedInput; //导入依赖的package包/类
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);
}
}
示例5: 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());
}
示例6: 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());
}
示例7: 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());
}
示例8: testReview2Parse
import com.rometools.rome.io.SyndFeedInput; //导入依赖的package包/类
/**
* Test of parse method, of class com.totsp.xml.syndication.base.io.GoogleBaseParser.
*/
public void testReview2Parse() throws Exception {
LOG.debug("testReview2Parse");
final SyndFeedInput input = new SyndFeedInput();
final Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0);
final SyndFeed feed = input.build(new File(super.getTestFile("xml/reviews2.xml")));
final List<SyndEntry> entries = feed.getEntries();
final SyndEntry entry = entries.get(0);
final Review module = (Review) 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[] { "Review", "Earth", "Google" }, module.getLabels());
cal.set(2005, 2, 24);
Assert.assertEquals("PubDate", cal.getTime(), module.getPublishDate());
this.assertEquals("Authors", new String[] { "Jimmy Smith" }, module.getAuthors());
Assert.assertEquals("Name of Item Rev", "Google Earth", module.getNameOfItemBeingReviewed());
Assert.assertEquals("Type", "Product", module.getReviewType());
Assert.assertEquals("Rever Type", "editorial", module.getReviewerType());
Assert.assertEquals("Rating", new Float(5), module.getRating());
Assert.assertEquals("URL of Item", new URL("http://earth.google.com/"), module.getUrlOfItemBeingReviewed());
}
示例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());
}
示例10: testEndToEnd
import com.rometools.rome.io.SyndFeedInput; //导入依赖的package包/类
public void testEndToEnd() throws Exception {
final SyndFeedInput input = new SyndFeedInput();
final File test = new File(super.getTestFile("os"));
final File[] files = test.listFiles();
for (int j = 0; j < files.length; j++) {
if (!files[j].getName().endsWith(".xml")) {
continue;
}
final SyndFeed feed = input.build(files[j]);
final Module m = feed.getModule(OpenSearchModule.URI);
final SyndFeedOutput output = new SyndFeedOutput();
final File outfile = new File("target/" + files[j].getName());
output.output(feed, outfile);
final SyndFeed feed2 = input.build(outfile);
assertEquals(m, feed2.getModule(OpenSearchModule.URI));
}
}
示例11: 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);
}
}
}
示例12: 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));
}
}
示例13: testGenerate
import com.rometools.rome.io.SyndFeedInput; //导入依赖的package包/类
/**
* 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);
}
示例14: 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);
}
}
}
示例15: 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);
}