コード例 #1
0
  @RequestMapping(value = "/ViewRSSFeeds", method = RequestMethod.POST)
  public String prrssfeeds(
      ModelMap model,
      HttpServletRequest request,
      @ModelAttribute("CompanyName") CompanyReports CompanyName,
      BindingResult result)
      throws Exception {

    com.mkyong.common.Service.RssFeedManager rssFeedManager =
        new com.mkyong.common.Service.RssFeedManager();

    String url = "http://news.google.com/news?q=" + CompanyName.getCompanyName() + "&output=rss";
    com.mkyong.common.Service.RssFeed rssFeed = rssFeedManager.processRssURL(url);
    if (rssFeed == null) return "error";

    model.addAttribute("rssFeed", rssFeed);
    return "RssFeeds";
  }
コード例 #2
0
  @RequestMapping(value = "/StockPrices", method = RequestMethod.POST)
  public String pr(
      ModelMap model,
      HttpServletRequest request,
      @Valid stocksearchhelper StockSearchHelper,
      BindingResult result) {

    /*if(result.hasErrors())
    {
    	model.addAttribute("se","Please Check the Values Entered");
    	model.addAttribute("StockSearchHelper",new stocksearchhelper());
    	model.addAttribute("CompanyName",new CompanyReports());
    	 List<stock> x=stockServiceInterface.liststock("NASDAQ");
    		List<stock> y=stockServiceInterface.liststock("NASDAQCOMPOSITE");
    		List<stock> z=stockServiceInterface.liststock("DOWJONES");
    		List<stock> a=stockServiceInterface.liststock("GOLD");
    		List<stock> b=stockServiceInterface.liststock("SANDP");
    		List<stock> c=stockServiceInterface.liststock("OIL");
    		model.addAttribute("NASDAQ",x.get(0).getPrice());
    		model.addAttribute("NASDAQCOMPOSITE",y.get(0).getPrice());
    		model.addAttribute("DOWJONES",z.get(0).getPrice());
    		model.addAttribute("GOLD",a.get(0).getPrice());
    		model.addAttribute("SANDP",b.get(0).getPrice());
    		model.addAttribute("OIL",c.get(0).getPrice());
    		List<TopPerformers> opds1=	  topPerformerServiceInterface.liststock();
    		model.addAttribute("first",opds1.get(0).getTickerCode());
    		model.addAttribute("second",opds1.get(1).getTickerCode());
    		model.addAttribute("third",opds1.get(2).getTickerCode());
    		model.addAttribute("fourth",opds1.get(3).getTickerCode());
    	return "ClientHome";
    }*/
    /*	else
    {*/
    long currentTime = (new Date()).getTime();
    // long

    String symbol = StockSearchHelper.getName();
    try {

      URL yahoofin =
          new URL(
              "http://finance.yahoo.com/d/quotes.csv?s=" + symbol + "&f=sl1d1t1c1ohgvjkm4&e=.csv");
      URLConnection yc = yahoofin.openConnection();
      BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
      String inputLine;
      while ((inputLine = in.readLine()) != null) {
        String[] yahooStockInfo = inputLine.split(",");
        StockBean stockInfo = new StockBean();
        stockInfo.setTicker(yahooStockInfo[0].replaceAll("\"", ""));
        stockInfo.setPrice(Float.valueOf(yahooStockInfo[1]));
        stockInfo.setChange(Float.valueOf(yahooStockInfo[4]));
        //  91011
        stockInfo.setWeekLow(String.valueOf(yahooStockInfo[9]));
        stockInfo.setWeekHigh(String.valueOf(yahooStockInfo[10]));
        stockInfo.setMA(String.valueOf(yahooStockInfo[11]));

        stockInfo.setChartUrlSmall("http://ichart.finance.yahoo.com/t?s=" + stockInfo.getTicker());
        stockInfo.setChartUrlLarge("http://chart.finance.yahoo.com/w?s=" + stockInfo.getTicker());
        stockInfo.setLastUpdated(currentTime);
        // stocks.put(symbol, stockInfo);
        model.addAttribute("stocksdata", stockInfo);

        com.mkyong.common.Service.RssFeedManager rssFeedManager =
            new com.mkyong.common.Service.RssFeedManager();

        String url = "http://news.google.com/news?q=" + symbol + "&output=rss";
        com.mkyong.common.Service.RssFeed rssFeed = rssFeedManager.processRssURL(url);
        if (rssFeed == null) return "error";

        model.addAttribute("rssFeed", rssFeed);

        break;
      }
      in.close();

    } catch (Exception ex) {

    }
    return "displayshares";
    // }

  }