public DocumentListEntry createFolder(String folderName, String roleString, List<String> emails)
      throws IOException, ServiceException {
    logger.info("\n\nFolder Exists? " + folderName);
    boolean folderFound = false;

    URL feedUri = new URL("https://docs.google.com/feeds/default/private/full/-/folder");
    DocumentListFeed feed = docsService.getFeed(feedUri, DocumentListFeed.class);
    DocumentListEntry folderEntry = new DocumentListEntry();

    for (DocumentListEntry entry : feed.getEntries()) {
      if (folderName.equalsIgnoreCase(entry.getTitle().getPlainText())) {
        folderFound = true;
        folderEntry = entry;
        break;
      }
    }

    if (!folderFound) {
      logger.info("\n\nCreating folder " + folderName);
      DocumentListEntry newEntry = new FolderEntry();
      newEntry.setTitle(new PlainTextConstruct(folderName));
      URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full/");
      folderEntry = docsService.insert(feedUrl, newEntry);

      shareResource(roleString, emails, folderEntry);
    }

    return folderEntry;
  }
  public DocumentListEntry getDocument(URL folderFeedUri, String documentName)
      throws IOException, ServiceException {
    DocumentQuery query = new DocumentQuery(folderFeedUri);
    query.setTitleQuery(documentName);
    query.setTitleExact(true);
    query.setMaxResults(1);
    DocumentListFeed feed = docsService.getFeed(query, DocumentListFeed.class);
    DocumentListEntry doc = null;
    if (!feed.getEntries().isEmpty()) {
      doc = feed.getEntries().get(0);
    }

    return doc;
  }
Beispiel #3
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;
  }
  public String getFolderURI(String _folderName) throws IOException, ServiceException {

    URL feedUri = new URL("https://docs.google.com/feeds/default/private/full/-/folder");
    DocumentListFeed feed = docsService.getFeed(feedUri, DocumentListFeed.class);
    DocumentListEntry folderEntry = new DocumentListEntry();

    for (DocumentListEntry entry : feed.getEntries()) {
      if (_folderName.equalsIgnoreCase(entry.getTitle().getPlainText())) {
        folderEntry = entry;
        break;
      }
    }
    String folderURIString = null;

    if (folderEntry.getContent() != null) {
      folderURIString = getDocumentFeedUri(folderEntry);
    }

    return folderURIString;
  }
 public DocumentListFeed getDocsFeedForFolder(String _folderResourceId)
     throws IOException, ServiceException {
   URL url = new URL(_folderResourceId);
   logger.info("folder url: " + url);
   return docsService.getFeed(url, DocumentListFeed.class);
 }