Java Code Examples for com.sun.syndication.io.SyndFeedInput.build()

The following are Jave code examples for showing how to use build() of the com.sun.syndication.io.SyndFeedInput class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: parabuild-ci   File: FeedReader.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 2
Project: dwnewsbot   File: FetchAtomWorker.java   View Source Code Vote up 6 votes
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();
        }
    }
}
 
Example 3
Project: FeedExpander   File: FeedCreatorTest.java   View Source Code Vote up 6 votes
@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());
}
 
Example 4
Project: bingesurfing   File: Feeder.java   View Source Code Vote up 6 votes
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));
}
 
Example 5
Project: PrimefacesShowcase   File: TwitterRSSService.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: PrimefacesShowcase   File: YAHOOWeatherService.java   View Source Code Vote up 6 votes
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";
	}
 
Example 7
Project: XPagesToolkit   File: FeedReaderService.java   View Source Code Vote up 6 votes
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;
}
 
Example 8
Project: XPagesToolkit   File: FeedReaderService.java   View Source Code Vote up 6 votes
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;
}
 
Example 9
Project: Babler   File: RSSScraper.java   View Source Code Vote up 5 votes
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;
        }

    }
 
Example 10
Project: rufus   File: RufusFeed.java   View Source Code Vote up 5 votes
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);
}
 
Example 11
Project: rufus   File: FeedParser.java   View Source Code Vote up 5 votes
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);
    }
}
 
Example 12
Project: parabuild-ci   File: FeedConverter.java   View Source Code Vote up 5 votes
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();
    }
}
 
Example 13
Project: FTBCurseBot   File: RssUtils.java   View Source Code Vote up 5 votes
@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;
}
 
Example 14
Project: feedsucker   File: RomeFeedReader.java   View Source Code Vote up 5 votes
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;
}
 
Example 15
Project: Camel   File: RssUtils.java   View Source Code Vote up 5 votes
public static SyndFeed createFeed(String feedUri, ClassLoader classLoader) throws Exception {
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        InputStream in = new URL(feedUri).openStream();
        SyndFeedInput input = new SyndFeedInput();
        return input.build(new XmlReader(in));
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
}
 
Example 16
Project: Camel   File: RssUtils.java   View Source Code Vote up 5 votes
public static SyndFeed createFeed(String feedUri, String username, String password, ClassLoader classLoader) throws Exception {
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(classLoader);
        URL feedUrl = new URL(feedUri);
        HttpURLConnection httpcon = (HttpURLConnection) feedUrl.openConnection();
        String encoding = Base64.encodeBase64String(username.concat(":").concat(password).getBytes());
        httpcon.setRequestProperty("Authorization", "Basic " + encoding);
        SyndFeedInput input = new SyndFeedInput();
        return input.build(new XmlReader(httpcon));
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
}
 
Example 17
Project: applets-java-api   File: RssNewsFetcher.java   View Source Code Vote up 5 votes
@Override
public void fetchSources() {

    if (!this.sourceDao.isExisting(this.key)) {
        try {

            SyndFeedInput input = new SyndFeedInput();
            SyndFeed feed = input.build(new XmlReader(new URL(this.value)));

            Source source = new Source();

            String imageUrl = feed.getImage().getUrl(); // Return null if no image

            source.setType("rss");

            source.setKey(this.key);
            source.setName(this.key);
            source.setValue(this.value);
            source.setUrlImage(imageUrl);

            this.sourceDao.add(source);

        } catch (IOException | FeedException e) {
            e.printStackTrace();
        }
    }
}
 
Example 18
Project: joyrest   File: FeedDownloader.java   View Source Code Vote up 5 votes
@Override
@SuppressWarnings("unchecked")
public List<SyndEntry> apply(URL url) {
    try (XmlReader xmlReader = new XmlReader(url)) {
        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feed = input.build(xmlReader);
        return feed.getEntries();
    } catch (Exception e) {
        LOG.log(Level.WARNING, "An error during downloading and parsing a given feed: " + url, e);
    }
    return Collections.emptyList();
}
 
Example 19
Project: FeedExpander   File: FeedCreatorTest.java   View Source Code Vote up 5 votes
@Test
@SuppressWarnings("unchecked")
public void testCreateSuccess() throws Exception {
	String createdFeed = new String(createFeedCreator("feeds/valid_page/index.html")
			.createFeed(".headline,.article,.footer", ".headline", "a", ".author").build());
	SyndFeedInput input = new SyndFeedInput();
	SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(createdFeed.getBytes())));
	List<SyndEntry> entries = feed.getEntries();

	assertEquals("headline1", entries.get(0).getTitle());
	assertEquals("http://dummy.url", entries.get(0).getLink());
	assertEquals("Jon Doe", entries.get(0).getAuthor());

	assertEquals("headline2", entries.get(1).getTitle());
	assertEquals("http://dummy.url", entries.get(1).getLink());
	assertEquals("Anna Smith", entries.get(1).getAuthor());
	
	String content1 = entries.get(0).getDescription().getValue();
	assertTrue(content1.contains("headline1"));
	assertTrue(content1.contains("text1"));
	assertTrue(content1.contains("footer1"));
	assertTrue(content1.contains("http://dummy.url"));

	String content2 = entries.get(1).getDescription().getValue();
	assertTrue(content2.contains("headline2"));
	assertTrue(content2.contains("text2"));
	assertTrue(content2.contains("footer2"));
	assertTrue(content2.contains("http://dummy.url"));
}
 
Example 20
Project: concourseconnect-community   File: RssListViewer.java   View Source Code Vote up 5 votes
public String doView(RenderRequest request, RenderResponse response) throws Exception {
  // The JSP to show upon success
  String defaultView = VIEW_PAGE;

  // General display preferences
  request.setAttribute(TITLE, request.getPreferences().getValue(PREF_TITLE, "Review"));
  request.setAttribute(SHOW_DESCRIPTION, request.getPreferences().getValue(PREF_SHOW_DESCRIPTION, "true"));
  request.setAttribute(LIMIT, String.valueOf(Integer.parseInt(request.getPreferences().getValue(PREF_LIMIT, "10"))-1));

  // Determine the feed
  String feedValue = request.getPreferences().getValue(PREF_FEED, null);
  if (feedValue == null) {
    return null;
  }

  // Process the feed
  URL feedUrl = new URL(feedValue);
  SyndFeedInput input = new SyndFeedInput();
  SyndFeed feed = input.build(new XmlReader(feedUrl));
  request.setAttribute(RSS_FEED, feed);

  if (LOG.isDebugEnabled()) {
    LOG.debug(feed);
  }

  // Skip displaying if there are no entries
  if (feed.getEntries().size() == 0) {
    return null;
  }

  // JSP view
  return defaultView;
}
 
Example 21
Project: chitanka4kindle   File: OpdsPage.java   View Source Code Vote up 5 votes
private SyndFeed parse(String address) throws IOException {
	try {
		SyndFeedInput input = new SyndFeedInput();
		return input.build(new XmlReader(Network.getInputStream(address)));
	} catch (Exception e) {
		throw new RuntimeException("Failed parsing: " + address, e);
	}
}
 
Example 22
Project: swingx-ws   File: YahooRSS.java   View Source Code Vote up 5 votes
/**
 * Reads a feed and returns the ROME SyndFeed object that was created by
 * reading the feed. Note that this method blocks, and should be called
 * on a background thread.
 *
 * @return the feed
 * @throws RSSException if something goes wrong while accessing the RSS feed
 */
public SyndFeed readFeed() throws RSSException {
    try {
        URL feedUrl = constructUrl();
        SyndFeedInput input = new SyndFeedInput();
        return input.build(new XmlReader(feedUrl));
    } catch (Exception e) {
        throw new RSSException(e);
    }
}
 
Example 23
Project: PrimefacesShowcase   File: YAHOONewsService.java   View Source Code Vote up 5 votes
public List<NewsGroup> fetchNews() {
	List<NewsGroup> news = new ArrayList<NewsGroup>();
	try {
		for(String key : feeds.keySet()) {
			URL feedSource = new URL(feeds.get(key));
			SyndFeedInput input = new SyndFeedInput();
			SyndFeed feed = input.build(new XmlReader(feedSource));
			List<NewsEntry> entries = new ArrayList<NewsEntry>();
			
			int i = 0;
			for(Object f : feed.getEntries()) {
				SyndEntry entry = (SyndEntry) f;
                   String title = entry.getTitle();
                   title = title.length() <= 25 ? title : title.substring(0, 25);
				entries.add(new NewsEntry(i, title + "...", entry.getDescription().getValue()));
				i++;
			}
			
			news.add(new NewsGroup(key, entries)); 
		}
	
	} catch(Exception exception) {
		logger.log(Level.SEVERE, "Error in retrieving news from YAHOO: {0}", exception.getMessage());
	}
	
	return news;
}
 
Example 24
Project: betfair-horses   File: ResultsAPI.java   View Source Code Vote up 5 votes
private static SyndFeed fetchFeed(String url) throws BetfairException {
    SyndFeed feed;
    try {
        URL feedSource = new URL(url);
        SyndFeedInput input = new SyndFeedInput();
        feed = input.build(new XmlReader(feedSource));
    } catch (Exception e) {
        throw new BetfairException("Problem fetching results from URL " +
                url, e);
    }
    return feed;
}
 
Example 25
Project: griffon-swingx-ws-plugin   File: YahooRSS.java   View Source Code Vote up 5 votes
/**
 * Reads a feed and returns the ROME SyndFeed object that was created by
 * reading the feed. Note that this method blocks, and should be called
 * on a background thread.
 *
 * @return the feed
 * @throws RSSException if something goes wrong while accessing the RSS feed
 */
public SyndFeed readFeed() throws RSSException {
    try {
        URL feedUrl = constructUrl();
        SyndFeedInput input = new SyndFeedInput();
        return input.build(new XmlReader(feedUrl));
    } catch (Exception e) {
        throw new RSSException(e);
    }
}
 
Example 26
Project: GridSphere   File: RssServiceImpl.java   View Source Code Vote up 5 votes
public SyndFeed getFeed(String url) throws FeedException {
    SyndFeedInput input = new SyndFeedInput();
    SyndFeed feed = null;
    long diff = CACHE_TIME + 1;
    // check if the url is in the cachedStore
    if (cachedStore.containsKey(url)) {
        Long cachedTime = (Long) this.cachedTime.get(url);
        diff = System.currentTimeMillis() - cachedTime.longValue();
    }


    if (diff > CACHE_TIME) {
        try {
            URL rssUrl = new URL(url);
            URLConnection c = rssUrl.openConnection();
            c.setConnectTimeout(2000);
            c.setReadTimeout(2000);
            c.connect();
            InputSource src = new InputSource(c.getInputStream());
            feed = input.build(src);
        } catch (IOException e) {
            throw new FeedException("Invalid URL.");
        }
        cachedStore.put(url, feed);
        cachedTime.put(url, new Long(System.currentTimeMillis()));
    }
    return (SyndFeed) cachedStore.get(url);
}
 
Example 27
Project: Babler   File: RSSScraper.java   View Source Code Vote up 4 votes
public AbstractMap.SimpleEntry<Integer, Integer> fetchAndSave() throws Exception {

        URL url = new URL(this.url);

        SyndFeedInput input = new SyndFeedInput();
        SyndFeed feed = input.build(new XmlReader(url));


        int items = feed.getEntries().size();

        if(items > 0){
            log.info("Attempting to parse rss feed: "+ this.url );
            log.info("This Feed has "+items +" items");
        }

        List <SyndEntry> entries = feed.getEntries();

        for (SyndEntry item : entries){
            log.info("Title: " + item.getTitle());
            log.info("Link: " + item.getLink());
            SyndContentImpl contentHolder = (SyndContentImpl) item.getContents().get(0);
            String content = contentHolder.getValue();

            //content might contain html data, let's clean it up
            Document doc = Jsoup.parse(content);
            content = doc.text();
            try {
                    Result result = ld.detectLanguage(content, language);
                    if (result.languageCode.equals(language) && result.isReliable) {

                        FileSaver file = new FileSaver(content, this.language, "bs", item.getLink(), item.getUri(), String.valueOf(content.hashCode()));
                        String fileName = file.getFileName();
                        BlogPost post = new BlogPost(content,this.language,null,"bs",item.getLink(),item.getUri(),fileName);
                        if(DAO.saveEntry(post)) {
                            file.save(this.logDb);
                            numOfFiles++;
                            wrongCount = 0;
                        }

                    }

                    else{
                        log.info("Item " + item.getTitle() + "is in a diff languageCode, skipping this post  "+ result.languageCode);
                        wrongCount ++;
                        if(wrongCount > 3){
                            log.info("Already found 3 posts in the wrong languageCode, skipping this blog");
                        }
                        break;
                    }

            }
            catch(Exception e){
                log.error(e);
                break;
            }


        }
        return new AbstractMap.SimpleEntry<>(numOfFiles,wrongCount);
    }
 
Example 28
Project: AtomMatrikel   File: Downloader.java   View Source Code Vote up 4 votes
public void read() throws Exception {
    FTPClient ftpClient = new FTPClient();
    ftpClient.setBufferSize(1024 * 1024);
    ftpClient.setDefaultTimeout(1000);
    ftpClient.setControlEncoding("UTF-8");
    ftpClient.setDataTimeout(10000);
    ZipFile zipFile = new ZipFile();
    Parser parser = new Parser();
    URL feedUrl = new URL("https://download.kortforsyningen.dk/sites/default/files/feeds/MATRIKELKORT_GML.xml");
    SyndFeedInput input = new SyndFeedInput();
    System.out.println("Henter Atom feed....\n");

    SyndFeed feed = input.build(new XmlReader(feedUrl));
    System.out.println("Feed Titel: " + feed.getTitle());
    Date lastPublishedDate;
    Date currentDate;
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String fileName;
    Integer elavsKode;

    Track track = new Track();
    String lastStr = track.getLastFromDb();
    lastPublishedDate = sdf.parse(lastStr);

    System.out.println("\nSidste entry: " + lastStr + "\n");

    this.login(ftpClient);

    for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {

        System.out.println("\n--------------\n");

        currentDate = entry.getPublishedDate();

        if (currentDate.before(lastPublishedDate) || currentDate.equals(lastPublishedDate)) {
            break;
        }

        System.out.println("Published Date: " + entry.getPublishedDate() + "\n");

        // Get the Links
        for (SyndLinkImpl link : (List<SyndLinkImpl>) entry.getLinks()) {
            System.out.println("Link: " + link.getHref());
            fileName = link.getHref().split("/")[7];
            elavsKode = Integer.valueOf(fileName.split("_")[0]);
            track.storeInDb(currentDate.toString(), elavsKode);

            // Get the file
            this.c(ftpClient, fileName, zipFile);

            // Get xml stream from zip-file
            ZipInputStream zin = zipFile.getGml(fileName);

            // Parse the xml and insert in database
            parser.build(zin, elavsKode);

            // Delete the file
            File file = new File(fileName);
            file.delete();
        }


    }
    // logout the user, returned true if logout successfully
    ftpClient.disconnect();
    System.out.println("Alt hentet...");
    System.out.println("FTP forbindelse afbrydes.");


}
 
Example 29
Project: parabuild-ci   File: FeedTest.java   View Source Code Vote up 4 votes
protected SyndFeed getSyndFeed() throws Exception {
    SyndFeedInput in = new SyndFeedInput();
    return in.build(getFeedReader());
}
 
Example 30
Project: parabuild-ci   File: FeedAggregator.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    boolean ok = false;
    if (args.length>=2) {
        try {
            String outputType = args[0];

            SyndFeed aggrFeed = new SyndFeedImpl();
            aggrFeed.setFeedType(outputType);

            aggrFeed.setTitle("Aggregated Feed");
            aggrFeed.setDescription("Anonymous Aggregated Feed");
            aggrFeed.setAuthor("anonymous");
            aggrFeed.setLink("http://www.anonymous.com");

            List entries = new ArrayList();
            aggrFeed.setEntries(entries);

            for (int i=1;i<args.length;i++) {
                URL feedUrl = new URL(args[i]);
                SyndFeedInput input = new SyndFeedInput();

                SyndFeed feed = input.build(new XmlReader(feedUrl));

                entries.addAll(feed.getEntries());
            }

            SyndFeedOutput output = new SyndFeedOutput();
            output.output(aggrFeed,new PrintWriter(System.out));

            ok = true;
        }
        catch (Exception ex) {
            System.out.println("ERROR: "+ex.getMessage());
        }
    }

    if (!ok) {
        System.out.println();
        System.out.println("FeedAggregator aggregates different feeds into a single one.");
        System.out.println("The first parameter must be the feed type for the aggregated feed.");
        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 to last parameters are the URLs of feeds to aggregate.");
        System.out.println();
    }
}
 
Example 31
Project: parabuild-ci   File: RomeApplet.java   View Source Code Vote up 4 votes
private SyndFeed getRSSFeed(URL url) throws Exception {
	SyndFeed feed;
	SyndFeedInput input = new SyndFeedInput();
	feed = input.build(new InputStreamReader(url.openStream()));
	return feed;
}
 
Example 32
Project: feedsucker   File: BasicTests.java   View Source Code Vote up 4 votes
public void readAndPrintFeed(String feedURL) throws Exception {
        SyndFeedInput input = new SyndFeedInput();                
        SyndFeed feed = input.build(new XmlReader(new URL(feedURL)));
        System.out.println("FEED: " + feed.getDescription());
        System.out.println("type: "+feed.getFeedType()+"\n"+
                "copyright: "+feed.getCopyright()+"\n"+
                "author: "+feed.getAuthor()+"\n"+
                "uri: "+feed.getUri()+"\n"+
                "language: "+feed.getLanguage()+"\n"+
                "link: "+feed.getLink()+"\n");
        //System.out.println(feed);
        List entries = feed.getEntries();
        System.out.println("ENTRIES: ");
        for (Object o : entries) {
            SyndEntry e = (SyndEntry)o;
            System.out.println("FEED ENTRY:");
            System.out.println("title: "+e.getTitle()+"\n"+
                    "date published: "+e.getPublishedDate()+"\n"+
                    "author: "+e.getAuthor()+"\n"+                    
                    "link: "+e.getLink()+"\n"+
                    "uri: "+e.getUri());      
            System.out.println("- categories: ");
            List cat = e.getCategories();
            for (Object oc : cat) {
                SyndCategory c = (SyndCategory)oc;
                System.out.println("name: "+c.getName()+"\n"+
                        "taxonomy uri: "+c.getTaxonomyUri());
            }            
            
            SyndContent content = e.getDescription();
            System.out.println("content: "+content.getValue());       
            System.out.println("--- entry end ---");
//          List contents = e.getContents();            
//            System.out.println("- contents: ");
//            for (Object oc : contents) {
//                SyndContent c = (SyndContent)oc;
//                System.out.println("type: "+c.getType());
//                System.out.println("value:");
//                System.out.println(c.getValue());
//            }
        }
    }
 
Example 33
Project: DigitalMediaServer   File: Feed.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
public void parse() throws Exception {
	SyndFeedInput input = new SyndFeedInput();
	byte b[] = downloadAndSendBinary(url);
	if (b != null) {
		SyndFeed feed = input.build(new XmlReader(new ByteArrayInputStream(b)));
		name = feed.getTitle();
		if (feed.getCategories() != null && feed.getCategories().size() > 0) {
			SyndCategory category = (SyndCategory) feed.getCategories().get(0);
			tempCategory = category.getName();
		}
		List<SyndEntry> entries = feed.getEntries();
		for (SyndEntry entry : entries) {
			tempItemTitle = entry.getTitle();
			tempItemLink = entry.getLink();
			tempFeedLink = entry.getUri();
			tempItemThumbURL = null;

			ArrayList<Element> elements = (ArrayList<Element>) entry.getForeignMarkup();
			for (Element elt : elements) {
				if ("group".equals(elt.getName()) && "media".equals(elt.getNamespacePrefix())) {
					List<Content> subElts = elt.getContent();
					for (Content subelt : subElts) {
						if (subelt instanceof Element) {
							parseElement((Element) subelt, false);
						}
					}
				}
				parseElement(elt, true);
			}
			List<SyndEnclosure> enclosures = entry.getEnclosures();
			for (SyndEnclosure enc : enclosures) {
				if (StringUtils.isNotBlank(enc.getUrl())) {
					tempItemLink = enc.getUrl();
				}
			}
			manageItem();
		}
	}
	setLastModified(System.currentTimeMillis());
}
 
Example 34
Project: Camel   File: RssConverter.java   View Source Code Vote up 4 votes
@Converter
public static SyndFeed xmlToFeed(String xml) throws FeedException {
    SyndFeedInput input = new SyndFeedInput();
    return input.build(new StringReader(xml));
}
 
Example 35
Project: apex-malhar   File: RomeSyndicationOperator.java   View Source Code Vote up 4 votes
/**
 * Thread processing of the syndication feeds
 */
@Override
public void run()
{
  try {
    while (true) {
      InputStreamReader isr = null;
      try {
        isr = new InputStreamReader(getFeedInputStream());
        SyndFeedInput feedInput = new SyndFeedInput();
        SyndFeed feed = feedInput.build(isr);
        List entries = feed.getEntries();
        List<RomeFeedEntry> nfeedItems = new ArrayList<RomeFeedEntry>();
        boolean oldEntries = false;
        for (int i = 0; i < entries.size(); ++i) {
          SyndEntry syndEntry = (SyndEntry)entries.get(i);
          RomeFeedEntry romeFeedEntry = getSerializableEntry(syndEntry);
          if (!oldEntries) {
            if (!feedItems.contains(romeFeedEntry)) {
              outputPort.emit(romeFeedEntry);
            } else if (orderedUpdate) {
              oldEntries = true;
            }
          }
          nfeedItems.add(romeFeedEntry);
        }
        feedItems = nfeedItems;
      } catch (Exception e) {
        logger.error(e.getMessage());
      } finally {
        if (isr != null) {
          try {
            isr.close();
          } catch (Exception ce) {
            logger.error(ce.getMessage());
          }
        }
      }
      Thread.sleep(interval);
    }
  } catch (InterruptedException ie) {
    logger.error("Interrupted: " + ie.getMessage());
  }
}
 
Example 36
Project: Teracast   File: PodcastsService.java   View Source Code Vote up 4 votes
@GET
@Path("/add/{podcastUrl}")
@Produces(MediaType.APPLICATION_JSON)
public Response addPodcast(@PathParam("podcastUrl") String podcastUrl) throws IllegalArgumentException, FeedException, IOException {
	System.out.println("Got podcast URL: " + podcastUrl);
	
	URL url = new URL(podcastUrl);
	SyndFeedInput input = new SyndFeedInput();
	SyndFeed feed = input.build(new XmlReader(url));

	StringBuilder episodeUrls = new StringBuilder();
	for (Object entry : feed.getEntries()) {
	    if (!(entry instanceof SyndEntryImpl)) {
	        // Throw an error?
	    }
	    SyndEntryImpl episode = (SyndEntryImpl) entry;
	    /*
	    System.out.println("Episode: { "
	                + ", 'title' : " + episode.getTitle()
	                + ", 'description' : " + episode.getDescription()
	                + " }");
	    */
	    for (Object possibleEnclosure : episode.getEnclosures()) {
	        if (!(possibleEnclosure instanceof SyndEnclosure)) {
	            // Throw an error?
	        }

	        SyndEnclosure enclosure = (SyndEnclosure) possibleEnclosure;
	        /*
	        System.out.println("\tEnclosure: { " 
	                + ", 'type' : " + enclosure.getType() 
	                + ", 'length' : " + enclosure.getLength()
	                + ", 'url' : " + enclosure.getUrl()
	                + " }");
	        */
	        
	        episodeUrls.append("Episode - PubDate: " + episode.getPublishedDate() + ", URL: " + enclosure.getUrl() + "\n");
	        
	        
	    }
	}
	
	return Response.ok().entity(episodeUrls.toString()).build();
}
 
Example 37
Project: collectors   File: CollectorRssImpl.java   View Source Code Vote up 4 votes
/**
 * Retrieves the RSS feed and the items in it.
 * 
 * <p> If we are looking for new content only, we first check for a change
 * to the checksum of the feed's URLs.
 */
private void obtainFeed(String url) {
    try {
        // Read the feed with the ROME library
        SyndFeedInput input = new SyndFeedInput();
        Reader read = new XmlReader(new URL(url));
        SyndFeed feed = input.build(read);

        // Set up for applying individual configuration for each URL
        String sourceName = messageMetadata.get("sourceName");
        
        // Checksum the list of feed URLs
        String checksum = computeFeedChecksum(feed, true);
        String oldChecksum = pageMetadata.getHash(url);
        boolean isNewContent = !oldChecksum.equalsIgnoreCase(checksum);            
        
        if (!isNewContent) {
            logger.info("{} - feed SHA-1 unchanged", url);
        }
        
        boolean getPages = isNewContent || isForcedCollection();
        if (getPages) {
            logger.info("Obtaining pages from RSS feed {}", url);
            // Get the pages
            obtainFeedPages(feed, sourceName);

            // Get a timestamp
            Date timestamp = feed.getPublishedDate();
            if (timestamp == null) {
                timestamp = new Date();
            }
            
            // Revise the checksum to reflect only URLs that we've 
            // successfully fetched at some point
            checksum = computeFeedChecksum(feed, false);

            // Update the metadata
            pageMetadata.setTimestamp(url, timestamp);
            pageMetadata.setHash(url, checksum);
            pageMetadata.save();
        }
        
        clean();
    } 
    catch (IOException | FeedException e) {
        e.printStackTrace();
    }
}
 
Example 38
Project: gitblit   File: SyndicationUtils.java   View Source Code Vote up 4 votes
/**
 * Reads a Gitblit RSS feed.
 * 
 * @param url
 *            the url of the Gitblit server
 * @param parameters
 *            the list of RSS parameters
 * @param repository
 *            the repository name
 * @param username
 * @param password
 * @return a list of SyndicationModel entries
 * @throws {@link IOException}
 */
private static List<FeedEntryModel> readFeed(String url, List<String> parameters,
		String repository, String branch, String username, char[] password) throws IOException {
	// build url
	StringBuilder sb = new StringBuilder();
	sb.append(MessageFormat.format("{0}" + Constants.SYNDICATION_PATH + "{1}", url, repository));
	if (parameters.size() > 0) {
		boolean first = true;
		for (String parameter : parameters) {
			if (first) {
				sb.append('?');
				first = false;
			} else {
				sb.append('&');
			}
			sb.append(parameter);
		}
	}
	String feedUrl = sb.toString();
	URLConnection conn = ConnectionUtils.openReadConnection(feedUrl, username, password);
	InputStream is = conn.getInputStream();
	SyndFeedInput input = new SyndFeedInput();
	SyndFeed feed = null;
	try {
		feed = input.build(new XmlReader(is));
	} catch (FeedException f) {
		throw new GitBlitException(f);
	}
	is.close();
	List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
	for (Object o : feed.getEntries()) {
		SyndEntryImpl entry = (SyndEntryImpl) o;
		FeedEntryModel model = new FeedEntryModel();
		model.repository = repository;
		model.branch = branch;
		model.title = entry.getTitle();
		model.author = entry.getAuthor();
		model.published = entry.getPublishedDate();
		model.link = entry.getLink();
		model.content = entry.getDescription().getValue();
		model.contentType = entry.getDescription().getType();
		if (entry.getCategories() != null && entry.getCategories().size() > 0) {
			List<String> tags = new ArrayList<String>();
			for (Object p : entry.getCategories()) {
				SyndCategory cat = (SyndCategory) p;
				tags.add(cat.getName());
			}
			model.tags = tags;
		}
		entries.add(model);
	}
	return entries;
}
 
Example 39
Project: Daily-Email-WebApp   File: AccountServiceImpl.java   View Source Code Vote up 4 votes
private RssFeeds getRssNewsLinkForNewFeed(final String url, final RssFeeds rssFeed) throws RssFeedException {
	final Set<RssNewsLinks> rssLinks = new HashSet<RssNewsLinks>();
	try {

		final URLConnection connection = new URL(url).openConnection();
		connection.setRequestProperty("User-Agent",
				"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
		connection.connect();
		final InputStream is = connection.getInputStream();
		final InputSource source = new InputSource(is);
		final SyndFeedInput input = new SyndFeedInput();
		final SyndFeed feed = input.build(source);

		@SuppressWarnings("rawtypes")
		final Iterator iFeed = feed.getEntries().iterator();

		while (iFeed.hasNext()) {
			final RssNewsLinks link = new RssNewsLinks();
			link.setFeedId(rssFeed.getId());
			link.setRssFeed(rssFeed);
			final SyndEntry entry = (SyndEntry) iFeed.next();
			link.setTitle(entry.getTitle());
			link.setLink(entry.getLink());
			if(null != entry.getDescription()) {
				link.setDescription(entry.getDescription().getValue().replaceAll("\\<.*?>", ""));
			}
			final Date publicationDate = entry.getPublishedDate();
			final DateTime publishedDate = new DateTime(publicationDate);
			link.setPubDate(publishedDate);

			rssLinks.add(link);

		}
		rssFeed.setRssNewsLinks(rssLinks);

	} catch (final Exception ex) {
		throw new RssFeedException("The feed appears to be invalid");
	}

	return rssFeed;
}
 
Example 40
Project: IRCBlit   File: SyndicationUtils.java   View Source Code Vote up 4 votes
/**
 * Reads a Gitblit RSS feed.
 * 
 * @param url
 *            the url of the Gitblit server
 * @param parameters
 *            the list of RSS parameters
 * @param repository
 *            the repository name
 * @param username
 * @param password
 * @return a list of SyndicationModel entries
 * @throws {@link IOException}
 */
private static List<FeedEntryModel> readFeed(String url, List<String> parameters,
		String repository, String branch, String username, char[] password) throws IOException {
	// build url
	StringBuilder sb = new StringBuilder();
	sb.append(MessageFormat.format("{0}" + Constants.SYNDICATION_PATH + "{1}", url, repository));
	if (parameters.size() > 0) {
		boolean first = true;
		for (String parameter : parameters) {
			if (first) {
				sb.append('?');
				first = false;
			} else {
				sb.append('&');
			}
			sb.append(parameter);
		}
	}
	String feedUrl = sb.toString();
	URLConnection conn = ConnectionUtils.openReadConnection(feedUrl, username, password);
	InputStream is = conn.getInputStream();
	SyndFeedInput input = new SyndFeedInput();
	SyndFeed feed = null;
	try {
		feed = input.build(new XmlReader(is));
	} catch (FeedException f) {
		throw new GitBlitException(f);
	}
	is.close();
	List<FeedEntryModel> entries = new ArrayList<FeedEntryModel>();
	for (Object o : feed.getEntries()) {
		SyndEntryImpl entry = (SyndEntryImpl) o;
		FeedEntryModel model = new FeedEntryModel();
		model.repository = repository;
		model.branch = branch;
		model.title = entry.getTitle();
		model.author = entry.getAuthor();
		model.published = entry.getPublishedDate();
		model.link = entry.getLink();
		model.content = entry.getDescription().getValue();
		model.contentType = entry.getDescription().getType();
		if (entry.getCategories() != null && entry.getCategories().size() > 0) {
			List<String> tags = new ArrayList<String>();
			for (Object p : entry.getCategories()) {
				SyndCategory cat = (SyndCategory) p;
				tags.add(cat.getName());
			}
			model.tags = tags;
		}
		entries.add(model);
	}
	return entries;
}
 
Example 41
Project: fuchsia   File: CallbackServlet.java   View Source Code Vote up 4 votes
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    String hubtopic = null;
    String hubchallenge = null;
    MessageStatus stsMessage = MessageStatus.ERROR;

    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(SyndFeedInput.class.getClassLoader());

    if (request.getContentType().contains(MediaType.APPLICATION_ATOM_XML)
            || request.getContentType().contains(MediaType.APPLICATION_RSS_XML)) {

        InputStream in = request.getInputStream();

        try {
            SyndFeedInput input = new SyndFeedInput();
            SyndFeed feed = input.build(new XmlReader(in));

            List<SyndLinkImpl> linkList = feed.getLinks();

            for (SyndLinkImpl link : linkList) {

                if ("self".equals(link.getRel())) {
                    hubtopic = link.getHref();
                }
            }

            if (hubtopic == null) {
                hubtopic = feed.getUri();
            }

            topicUpdated(hubtopic, feed);
        } catch (FeedException e) {
            LOG.error("Failed in creating feed response.", e);
        } finally {
            Thread.currentThread().setContextClassLoader(cl);
        }


        stsMessage = MessageStatus.OK;
    }

    response.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

    switch (stsMessage) {
        case OK:
            response.setStatus(HttpStatus.SC_OK);
            break;
        case OK_CHALLENGE:
            response.setStatus(HttpStatus.SC_OK);
            response.getWriter().print(hubchallenge);
            break;
        default:
            response.setStatus(HttpStatus.SC_NOT_FOUND);
            break;
    }

}
 
Example 42
Project: NK-VirtualGlobe   File: FeedTest.java   View Source Code Vote up 4 votes
protected SyndFeed getSyndFeed() throws Exception {
    SyndFeedInput in = new SyndFeedInput();
    return in.build(getFeedReader());
}
 
Example 43
Project: superpipes   File: N_RSS.java   View Source Code Vote up 4 votes
@Override
@SuppressWarnings( "unchecked" )
protected void loop()
    throws Exception
{
    final URL url = new URL( getProperties().getConfigString( "url" ) );

    final int max = getProperties().getConfigInteger( "max" );

    if ( LOGGER.isTraceEnabled() )
    {
        LOGGER.trace( "[" + getNodeID() + "] read feed : " + url + " with max " + max + " elements" );
    }

    final SyndFeedInput input = new SyndFeedInput();
    final SyndFeed feed = input.build( new XmlReader( url ) );

    int count = 0;
    final List<SyndEntry> entries = feed.getEntries();
    for ( final SyndEntry entry : entries )
    {
        if ( entry.getUri() != null )
        {
            // Tags
            final Tags tags = new Tags();

            final List<SyndCategory> categories = entry.getCategories();
            if ( categories != null )
            {
                for ( final SyndCategory category : categories )
                {
                    tags.add( category.getName() );
                }
            }

            setMessage( Message.create(
                Message.KeyIndex.URI ,
                new URI( entry.getUri() ) ,
                Message.KeyIndex.TAGS ,
                tags
            ) );

            // Title
            if ( entry.getTitle() != null )
            {
                getMessage().setProperty( Message.KeyIndex.TITLE ,
                                          HTMLhelper.cleanHTML( entry.getTitle() ) );
            }

            // Description
            if ( entry.getDescription() != null )
            {
                getMessage().setProperty( Message.KeyIndex.DESCRIPTION ,
                                          HTMLhelper.cleanHTML( entry.getDescription().getValue() ) );
            }

            // Author
            if ( entry.getAuthor() != null )
            {
                getMessage().setProperty( Message.KeyIndex.AUTHOR ,
                                          entry.getAuthor() );
            }

            // Published date
            if ( entry.getPublishedDate() != null )
            {
                getMessage().setProperty( Message.KeyIndex.PUBLISHED_DATE ,
                                          new DateTime( entry.getPublishedDate() ) );
            }

            sendMessage();
        }

        ++count;

        if ( count >= max )
        {
            break;
        }
    }
}