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


Java SyndFeedInput类代码示例

本文整理汇总了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();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:27,代码来源:FeedReader.java

示例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();
        }
    }
}
 
开发者ID:juntao,项目名称:dwnewsbot,代码行数:26,代码来源:FetchAtomWorker.java

示例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());
}
 
开发者ID:rrauschenbach,项目名称:FeedExpander,代码行数:21,代码来源:FeedCreatorTest.java

示例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));
}
 
开发者ID:kkretsch,项目名称:bingesurfing,代码行数:20,代码来源:Feeder.java

示例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;
}
 
开发者ID:websphere,项目名称:PrimefacesShowcase,代码行数:19,代码来源:TwitterRSSService.java

示例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";
	}
 
开发者ID:websphere,项目名称:PrimefacesShowcase,代码行数:17,代码来源:YAHOOWeatherService.java

示例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;
}
 
开发者ID:OpenNTF,项目名称:XPagesToolkit,代码行数:23,代码来源:FeedReaderService.java

示例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;
}
 
开发者ID:OpenNTF,项目名称:XPagesToolkit,代码行数:25,代码来源:FeedReaderService.java

示例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;
}
 
开发者ID:mguilherme,项目名称:RSS-Mailer,代码行数:25,代码来源:RssReader.java

示例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;
        }

    }
 
开发者ID:gidim,项目名称:Babler,代码行数:36,代码来源:RSSScraper.java

示例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);
}
 
开发者ID:jtanza,项目名称:rufus,代码行数:16,代码来源:RufusFeed.java

示例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);
    }
}
 
开发者ID:jtanza,项目名称:rufus,代码行数:12,代码来源:FeedParser.java

示例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();
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:32,代码来源:FeedConverter.java

示例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;
}
 
开发者ID:progwml6,项目名称:FTBCurseBot,代码行数:13,代码来源:RssUtils.java

示例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;
}
 
开发者ID:dkorenci,项目名称:feedsucker,代码行数:14,代码来源:RomeFeedReader.java


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