本文整理汇总了Java中com.rometools.rome.feed.synd.SyndFeed类的典型用法代码示例。如果您正苦于以下问题:Java SyndFeed类的具体用法?Java SyndFeed怎么用?Java SyndFeed使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyndFeed类属于com.rometools.rome.feed.synd包,在下文中一共展示了SyndFeed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RSSSubscription
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
public RSSSubscription(URL url, String id, ArrayList<String> subscriber, long lastDate, long lastCheck) {
SyndFeed feed = RSSUtil.getElements(url);
if (feed != null) {
feedURL = url;
ID = id;
title = feed.getTitle();
//Assume the first element is the newest and get the date
this.lastDate = lastDate == -1 ? feed.getEntries().get(0).getPublishedDate().getTime() : lastDate;
this.lastCheck = lastCheck == -1 ? System.currentTimeMillis() : lastCheck;
subscribers = subscriber;
System.out.println("Successfully added RSS: " + url.toString());
} else {
System.out.println("Unable to add RSS: " + url.toString());
}
}
示例2: validateLink
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
private void validateLink(final SyndFeed feed, final String source) {
for (final SyndLink l : feed.getLinks()) {
if ("self".equalsIgnoreCase(l.getRel())) {
try {
final URI u = new URI(l.getHref());
final URI t = new URI(source);
if (!u.equals(t)) {
throw new HttpStatusCodeException(400, "Feed self link does not match the subscribed URI.", null);
}
break;
} catch (final URISyntaxException ex) {
LOG.error(null, ex);
}
}
}
}
示例3: createFeed
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
@Override
public Feed createFeed(String url, SyndFeed syndFeed) {
String title = syndFeed.getTitle();
if (title == null) title = "RSS";
title = StringUtils.truncateUtf8(title, MAX_AUTHOR_NAME_LENGTH);
KeyPair keyPair = cryptoComponent.generateSignatureKeyPair();
LocalAuthor localAuthor = authorFactory
.createLocalAuthor(title,
keyPair.getPublic().getEncoded(),
keyPair.getPrivate().getEncoded());
Blog blog = blogFactory.createFeedBlog(localAuthor);
long added = clock.currentTimeMillis();
return new Feed(url, blog, localAuthor, added);
}
示例4: parse
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的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);
}
}
示例5: importPublications
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
public void importPublications(String projectID) throws Exception {
LOGGER.info("Getting new publications from {} RSS feed...", sourceSystemID);
SyndFeed feed = retrieveFeed();
List<MCRObject> importedObjects = new ArrayList<>();
for (SyndEntry entry : feed.getEntries()) {
MCRObject importedObject = handleFeedEntry(entry, projectID);
if (importedObject != null) {
importedObjects.add(importedObject);
}
}
int numPublicationsImported = importedObjects.size();
LOGGER.info("imported {} publications.", numPublicationsImported);
if ((numPublicationsImported > 0) && (xsl2BuildNotificationMail != null)) {
sendNotificationMail(importedObjects);
}
}
示例6: run
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的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);
}
}
}
示例7: buildSyndFeed
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的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;
}
示例8: getLatestEntry
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
/**
* Returns the most recent entry or null, if no entries are found.
*/
private SyndEntry getLatestEntry(SyndFeed feed) {
List<SyndEntry> allEntries = feed.getEntries();
SyndEntry lastEntry = null;
if (allEntries.size() >= 1) {
/*
* The entries are stored in the SyndFeed object in the following order -
* the newest entry has index 0. The order is determined from the time the entry was posted, not the
* published time of the entry.
*/
lastEntry = allEntries.get(0);
} else {
logger.debug("No entries found");
}
return lastEntry;
}
示例9: update
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
public void update() {
if (feedURL == null) {
System.out.println("ERROR - URL for id " + ID + " was not found, removing feed.");
throw new NullPointerException("URL is null");
}
SyndFeed feed = RSSUtil.getElements(feedURL);
lastCheck = System.currentTimeMillis();
//Check if there is anything new to add
if (feed.getEntries().get(0).getPublishedDate().getTime() > lastDate) {
SyndEntry[] entries = RSSUtil.getNewEntries(feed.getEntries(), lastDate);
ArrayUtils.reverse(entries);
notifySubscribers(entries);
//Update time
lastDate = feed.getEntries().get(0).getPublishedDate().getTime();
}
}
示例10: sendUpdateNotificationAsyncronously
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
/**
* Asynchronously sends a notification for a feed located at "topic". The feed MUST contain
* rel="hub".
*
* @param topic URL for the feed
* @param feed The feed itself
* @param callback A callback invoked when the notification completes.
* @throws NotificationException Any failure
*/
public void sendUpdateNotificationAsyncronously(final String topic, final SyndFeed feed, final AsyncNotificationCallback callback) {
final Runnable r = new Runnable() {
@Override
public void run() {
try {
sendUpdateNotification(topic, feed);
callback.onSuccess();
} catch (final Throwable t) {
callback.onFailure(t);
}
}
};
if (executor != null) {
executor.execute(r);
} else {
new Thread(r).start();
}
}
示例11: testProduceAndReadSimple
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
/**
* @throws Exception if file not found or not accessible
*/
public void testProduceAndReadSimple() throws Exception {
final SyndFeed feed = createFeed();
final GeoRSSModule geoRSSModule = new SimpleModuleImpl();
final double latitude = 47.0;
final double longitude = 9.0;
final Position position = new Position();
position.setLatitude(latitude);
position.setLongitude(longitude);
geoRSSModule.setPosition(position);
final SyndEntry entry = feed.getEntries().get(0);
entry.getModules().add(geoRSSModule);
final SyndFeedOutput output = new SyndFeedOutput();
final StringWriter stringWriter = new StringWriter();
output.output(feed, stringWriter);
final InputStream in = new ByteArrayInputStream(stringWriter.toString().getBytes("UTF8"));
final Double[] lat = { latitude };
final Double[] lng = { longitude };
assertTestInputStream(in, lat, lng);
}
示例12: testNews2Parse
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的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());
}
示例13: testPersona2Parse
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的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());
}
示例14: testGenerate
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的package包/类
/**
* 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));
}
}
示例15: testReview2Parse
import com.rometools.rome.feed.synd.SyndFeed; //导入依赖的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());
}