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 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(); }