本文整理汇总了Java中com.sun.syndication.io.SyndFeedInput类的典型用法代码示例。如果您正苦于以下问题:Java SyndFeedInput类的具体用法?Java SyndFeedInput怎么用?Java SyndFeedInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SyndFeedInput类属于com.sun.syndication.io包,在下文中一共展示了SyndFeedInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public static void main(String[] args) {
boolean ok = false;
if (args.length==1) {
try {
URL feedUrl = new URL(args[0]);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
System.out.println(feed);
ok = true;
}
catch (Exception ex) {
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}
}
if (!ok) {
System.out.println();
System.out.println("FeedReader reads and prints any RSS/Atom feed type.");
System.out.println("The first parameter must be the URL of the feed to read.");
System.out.println();
}
}
示例2: execute
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public void execute(JobExecutionContext context) throws JobExecutionException {
log.info("Start FetchAtomWorker job");
EntityManagerFactory emf = (EntityManagerFactory) context.getMergedJobDataMap().get("emf");
DataManager dm = new DataManager (emf);
ServletContext scontext = (ServletContext) context.getMergedJobDataMap().get("scontext");
Iterator it = dm.feeds.entrySet().iterator();
while (it.hasNext()) {
Map.Entry <String, String[]> pair = (Map.Entry)it.next();
System.out.println(pair.getKey() + " = " + pair.getValue());
try {
URL feedUrl = new URL(pair.getValue()[1]);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {
dm.saveNewsItem(entry, pair.getKey());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
示例3: testCreateNullHeadlineAndLink
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void testCreateNullHeadlineAndLink() throws Exception {
String createdFeed = new String(createFeedCreator("feeds/valid_page/index.html")
.createFeed(".headline,.article,.footer", null, null, null)
.setTitle("Title")
.build());
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(createdFeed.getBytes())));
assertEquals("Title", feed.getTitle());
List<SyndEntry> entries = feed.getEntries();
assertEquals(null, entries.get(0).getTitle());
assertEquals(null, entries.get(0).getLink());
assertEquals(EMPTY, entries.get(0).getAuthor());
assertEquals(null, entries.get(1).getTitle());
assertEquals(null, entries.get(1).getLink());
assertEquals(EMPTY, entries.get(1).getAuthor());
}
示例4: read
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public void read() {
try {
URL source = new URL(Defaults.FEEDURL);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(source));
@SuppressWarnings("unchecked")
List<SyndEntry> entries = feed.getEntries();
urls = new ArrayList<String>();
for(SyndEntry entry : entries) {
String sURL = entry.getLink();
urls.add(sURL);
} // for
} catch (IllegalArgumentException | FeedException | IOException e) {
e.printStackTrace();
}
long seed = System.nanoTime();
Collections.shuffle(urls, new Random(seed));
}
示例5: getTweets
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public List<String> getTweets(String username) {
List<String> tweets = new ArrayList<String>();
try {
URL feedSource = new URL("http://api.twitter.com/1/statuses/user_timeline.rss?count=100&screen_name=" + username);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedSource));
for(Object f : feed.getEntries()) {
SyndEntry entry = (SyndEntry) f;
tweets.add(entry.getTitle().substring(username.length() + 2));
}
}catch(Exception e) {
logger.severe(e.getMessage());
}
return tweets;
}
示例6: getConditions
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public String getConditions(String city, String unit) {
try {
URL feedSource = new URL("http://weather.yahooapis.com/forecastrss?p=" + city + "&u=" + unit);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedSource));
String value = ((SyndEntry) feed.getEntries().get(0)).getDescription().getValue();
return value.split("<a href")[0]; //Remove links
} catch (Exception e) {
logger.severe(e.getMessage());
}
return "Unable to retrieve conditions";
}
示例7: getAllEntriesFromURL
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public List<RSSEntry> getAllEntriesFromURL(String strURL) {
List<RSSEntry> lstRC = new ArrayList<RSSEntry>();
if (!StringUtil.isEmpty(strURL)) {
Thread currentThread = Thread.currentThread();
ClassLoader clCurrent = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(XPTRSSActivator.class.getClassLoader());
URL feedUrl = new URL(strURL);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
lstRC = processFeed2List(feed);
} catch (Exception e) {
LoggerFactory.logError(getClass(), "getAllEntriesFromURL", e);
} finally {
currentThread.setContextClassLoader(clCurrent);
}
}
return lstRC;
}
示例8: getFeedFromURL
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public RSSFeed getFeedFromURL(String strURL) {
RSSFeed rssFeed = new RSSFeed();
rssFeed.setURL(strURL);
Thread currentThread = Thread.currentThread();
ClassLoader clCurrent = currentThread.getContextClassLoader();
try {
currentThread.setContextClassLoader(XPTRSSActivator.class.getClassLoader());
URL feedUrl = new URL(strURL);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
rssFeed.setAuthor(feed.getAuthor());
rssFeed.setDescription(feed.getDescription());
rssFeed.setTitle(feed.getTitle());
if (feed.getImage() != null) {
rssFeed.setImageURL(feed.getImage().getUrl());
}
rssFeed.setEntries(processFeed2List(feed));
} catch (Exception e) {
LoggerFactory.logError(getClass(), "getFeedFromURL", e);
} finally {
currentThread.setContextClassLoader(clCurrent);
}
return rssFeed;
}
示例9: getFeed
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
/**
* Retrieve the last available feed item, null if it's already in memory.
* @return the last available feed item
*/
public FeedItem getFeed() {
FeedItem feedItem = null;
try {
reader = new XmlReader(url);
SyndFeed feed = new SyndFeedInput().build(reader);
SyndEntry newEntry = ((SyndEntry)feed.getEntries().get(0));
if(lastEntry == null || newEntry.getPublishedDate().after(lastEntry.getPublishedDate())) {
log.info("Retrieving new feed.");
lastEntry = newEntry;
feedItem = populateFeedItem(lastEntry);
}
} catch (IllegalArgumentException | FeedException | IOException e) {
log.error("There's a problem trying to read feed", e.getMessage());
}
return feedItem;
}
示例10: getAllPostsFromFeed
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public static List getAllPostsFromFeed(String urlToGet, String source) throws IOException, FeedException {
ArrayList<BlogPost> posts = new ArrayList<BlogPost>();
URL url = new URL(urlToGet);
SyndFeedInput input = new SyndFeedInput();
try {
SyndFeed feed = input.build(new XmlReader(url));
int items = feed.getEntries().size();
if (items > 0) {
log.info("Attempting to parse rss feed: " + urlToGet);
log.info("This Feed has " + items + " items");
List<SyndEntry> entries = feed.getEntries();
for (SyndEntry item : entries) {
if (item.getContents().size() > 0) {
SyndContentImpl contentHolder = (SyndContentImpl) item.getContents().get(0);
String content = contentHolder.getValue();
if (content != null && !content.isEmpty()) {
BlogPost post = new BlogPost(content, null, null, source, item.getLink(), item.getUri(), null);
posts.add(post);
}
}
}
}
return posts;
}
catch(Exception ex){
log.error(ex);
return posts;
}
}
示例11: generate
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public static RufusFeed generate(Source source) {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null;
URL url = source.getUrl();
try {
feed = input.build(new XmlReader(url));
} catch (Exception e) {
logger.debug("Could not build SyndFeedInput for {}", url, e);
}
if (CollectionUtils.isEmpty(source.getTags())) {
source.setTags(Collections.emptyList()); //never null!
}
return new RufusFeed(source, feed);
}
示例12: validate
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
private static FeedResponse validate(String feedRequestUrl) {
try {
URL url = new URL(feedRequestUrl);
SyndFeedInput input = new SyndFeedInput();
input.build(new XmlReader(url)); //ensure request is a valid rss feed
return FeedResponse.valid(feedRequestUrl);
} catch (Exception e) {
logger.debug("could not parse feed request {}, reason {}", feedRequestUrl, e.getMessage());
return FeedResponse.invalid(e.getMessage(), feedRequestUrl);
}
}
示例13: main
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public static void main(String[] args) {
boolean ok = false;
if (args.length==2) {
try {
String outputType = args[0];
URL feedUrl = new URL(args[1]);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
feed.setFeedType(outputType);
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed,new PrintWriter(System.out));
ok = true;
}
catch (Exception ex) {
System.out.println("ERROR: "+ex.getMessage());
}
}
if (!ok) {
System.out.println();
System.out.println("Converter converts between syndication feeds types.");
System.out.println("The first parameter must be the feed type to convert to.");
System.out.println(" [valid values are: rss_0.9, rss_0.91, rss_0.92, rss_0.93, ]");
System.out.println(" [ rss_0.94, rss_1.0, rss_2.0 & atom_0.3 ]");
System.out.println("The second parameter must be the URL of the feed to convert.");
System.out.println();
}
}
示例14: getFeed
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
@Nullable
public static SyndFeed getFeed (String url) {
try {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(new URL(url)));
return feed;
} catch (FeedException | IOException e) {
e.printStackTrace();
//TODO implement this
}
return null;
}
示例15: createFeed
import com.sun.syndication.io.SyndFeedInput; //导入依赖的package包/类
public SyndFeed createFeed(String feedUrl) throws IOException, FeedException {
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null; urlConn = null;
if (userAgent == null) { // use default user agend
feed = input.build(new XmlReader(new URL(feedUrl)));
}
else { // setup user agend explicitly
urlConn = new URL(feedUrl).openConnection();
urlConn.setRequestProperty("User-Agent", userAgent);
feed = input.build(new XmlReader(urlConn));
}
return feed;
}