コード例 #1
0
  public List<WorksheetEntry> copyDocument(
      DocumentListEntry documentListEntry,
      String newDocumentTitle,
      DocumentListEntry destinationFolderEntry)
      throws IOException, ServiceException {

    documentListEntry.setTitle(new PlainTextConstruct(newDocumentTitle));

    URL url = new URL("https://docs.google.com/feeds/default/private/full/");

    DocumentListEntry newDoc = docsService.insert(url, documentListEntry);

    String destFolder = ((MediaContent) destinationFolderEntry.getContent()).getUri();
    URL newUrl = new URL(destFolder);

    // Convert DocumentListEntry to SpreadsheetEntry
    DocumentListEntry newDocumentListEntry = docsService.insert(newUrl, newDoc);
    String spreadsheetURL =
        "https://spreadsheets.google.com/feeds/spreadsheets/" + newDocumentListEntry.getDocId();

    SpreadsheetEntry spreadsheetEntry =
        spreadsheetService.getEntry(new URL(spreadsheetURL), SpreadsheetEntry.class);

    return spreadsheetEntry.getWorksheets();
  }
コード例 #2
0
  public com.google.gdata.data.docs.SpreadsheetEntry createSpreadsheet(
      String _title,
      DocumentListEntry _destinationFolderEntry,
      String _defaultWorksheetName,
      int _rows,
      int _columns)
      throws IOException, ServiceException {
    com.google.gdata.data.docs.SpreadsheetEntry newEntry =
        new com.google.gdata.data.docs.SpreadsheetEntry();
    newEntry.setTitle(new PlainTextConstruct(_title));

    String destFolder = ((MediaContent) _destinationFolderEntry.getContent()).getUri();
    URL destinationURL = new URL(destFolder);

    com.google.gdata.data.docs.SpreadsheetEntry newSpreadsheetEntry =
        docsService.insert(destinationURL, newEntry);
    // convert from Docs API Spreadsheet to Spreadsheet API Spreadsheet
    WorksheetEntry worksheet =
        getSpreadsheetEntryFromDocumentListEntry(newSpreadsheetEntry).getDefaultWorksheet();
    worksheet.setTitle(new PlainTextConstruct(_defaultWorksheetName));
    worksheet.setRowCount(_rows);
    worksheet.setColCount(_columns);
    worksheet.update();

    return newSpreadsheetEntry;
  }
コード例 #3
0
  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;
  }
コード例 #4
0
  public void shareResource(String roleString, String email, DocumentListEntry documentListEntry)
      throws IOException {
    AclRole role = new AclRole(roleString);
    AclScope scope = new AclScope(AclScope.Type.USER, email);

    AclEntry aclEntry = new AclEntry();
    aclEntry.setRole(role);
    aclEntry.setScope(scope);

    try {
      docsService.insert(new URL(documentListEntry.getAclFeedLink().getHref()), aclEntry);
    } catch (ServiceException se) {
      logger.info("Unable to share resource or resource already shared.");
    }
  }