當前位置: 首頁>>代碼示例>>Java>>正文


Java XmlReader類代碼示例

本文整理匯總了Java中com.sun.syndication.io.XmlReader的典型用法代碼示例。如果您正苦於以下問題:Java XmlReader類的具體用法?Java XmlReader怎麽用?Java XmlReader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


XmlReader類屬於com.sun.syndication.io包,在下文中一共展示了XmlReader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import com.sun.syndication.io.XmlReader; //導入依賴的package包/類
public static void main(String[] args) {
    boolean ok = false;
    if (args.length==1) {
        try {
            URL feedUrl = new URL(args[0]);
            WireFeedInput input = new WireFeedInput();

            WireFeed 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("WireFeedReader 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,代碼來源:WireFeedReader.java

示例2: main

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例3: execute

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例4: testCreateNullHeadlineAndLink

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例5: read

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例6: getTweets

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例7: getConditions

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例8: getAllEntriesFromURL

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例9: getFeedFromURL

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例10: getFeed

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例11: getAllPostsFromFeed

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例12: generate

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例13: validate

import com.sun.syndication.io.XmlReader; //導入依賴的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

示例14: _testRawNoBomInvalid

import com.sun.syndication.io.XmlReader; //導入依賴的package包/類
protected void _testRawNoBomInvalid(String encoding) throws Exception {
   InputStream is = getXmlStream("no-bom","xml-prolog-encoding",encoding,encoding);
   try {
       XmlReader xmlReader = new XmlReader(is,false);
       fail("It should have failed");
   }
   catch (IOException ex) {
       assertTrue(ex.getMessage().indexOf("Invalid encoding,")>-1);
   }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:11,代碼來源:TestXmlReader.java

示例15: _testRawBomValid

import com.sun.syndication.io.XmlReader; //導入依賴的package包/類
protected void _testRawBomValid(String encoding) throws Exception {
    InputStream is = getXmlStream(encoding+"-bom","xml-prolog-encoding",encoding,encoding);
    XmlReader xmlReader = new XmlReader(is,false);
    if (!encoding.equals("UTF-16")) {
        assertEquals(xmlReader.getEncoding(),encoding);
    }
    else {
        assertEquals(xmlReader.getEncoding().substring(0,encoding.length()),encoding);
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:11,代碼來源:TestXmlReader.java


注:本文中的com.sun.syndication.io.XmlReader類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。