예제 #1
0
  @RequestMapping("home")
  public ModelAndView welcomeHandler(HttpServletRequest req, HttpServletResponse res) {
    ModelAndView mv = new ModelAndView("home");

    HttpSession session = req.getSession();
    UserInfo ui = (UserInfo) session.getAttribute("userInfo");

    String accessToken = ui.getAccess_token();

    DocsService service = new DocsService("mayRoro");
    service.setHeader("Authorization", "OAuth " + accessToken);

    try {
      URL metafeedUrl =
          new URL(
              "https://spreadsheets.google.com/feeds/spreadsheets/private/full?title="
                  + ConstFunc.SPREADSHEET_PREFIX);
      SpreadsheetFeed feed = service.getFeed(metafeedUrl, SpreadsheetFeed.class);
      List<SpreadsheetEntry> spreadsheets = feed.getEntries();
      for (int i = 0; i < spreadsheets.size(); i++) {
        SpreadsheetEntry entry = spreadsheets.get(i);
        entry.setTitle(
            new PlainTextConstruct(
                entry.getTitle().getPlainText().substring(ConstFunc.SPREADSHEET_PREFIX.length())));
        System.out.println("Self: " + entry.getSelfLink().getHref());
      }
      mv.addObject("spreadsheets", spreadsheets);
    } catch (Exception e) {
      e.printStackTrace();
    }

    //		************* Seznam vseh map *************
    //		try {
    //			URL metafeedUrl = new URL("https://docs.google.com/feeds/default/private/full/-/folder");
    //			Feed feed = service.getFeed(metafeedUrl, Feed.class);
    //			List<Entry> spreadsheets = feed.getEntries();
    //			for (int i = 0; i < spreadsheets.size(); i++) {
    //				Entry entry = spreadsheets.get(i);
    //				System.out.println("\t" + entry.getTitle().getPlainText());
    //			}
    //			mv.addObject("spreadsheets", spreadsheets);
    //		} catch (Exception e) {
    //			e.printStackTrace();
    //		}

    return mv;
  }
예제 #2
0
  @RequestMapping("maut/{spreadsheetID}")
  public ModelAndView maut(
      HttpServletRequest req, HttpServletResponse res, @PathVariable String spreadsheetID) {
    ModelAndView mv = new ModelAndView("maut");

    HttpSession session = req.getSession();
    String accessToken = ((UserInfo) session.getAttribute("userInfo")).getAccess_token();

    DocsService service = new DocsService("mayRoro");
    service.setHeader("Authorization", "OAuth " + accessToken);

    try {
      URL spreadsheetUrl =
          new URL(
              "https://spreadsheets.google.com/feeds/spreadsheets/private/full/" + spreadsheetID);
      SpreadsheetEntry spreadsheet = service.getEntry(spreadsheetUrl, SpreadsheetEntry.class);

      System.out.println("Title: " + spreadsheet.getTitle().getPlainText());

      for (WorksheetEntry we : spreadsheet.getWorksheets()) {
        System.out.println(we.getTitle().getPlainText() + ": " + we.getId());
      }

      spreadsheet.setTitle(
          new PlainTextConstruct(
              spreadsheet
                  .getTitle()
                  .getPlainText()
                  .substring(ConstFunc.SPREADSHEET_PREFIX.length())));
      mv.addObject("spreadsheet", spreadsheet);
    } catch (Exception e) {
      e.printStackTrace();
    }

    return mv;
  }