我想复制这里提到的文件:
http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#CopyingDocs
我正在使用最新的Java Gdata Library,它没有很好的包装器方法,而且我是java gdata lib的新手。
我已经有一个经过身份验证的DocsService,如果它有用的话。
奖励积分如果你把它包装成一个带两个字符串的方法,一个是源名,另一个是副本名。
答案 0 :(得分:1)
好的,我做到了....
这样每个人都可以看到... this.Service是一个DocsService,已经过身份验证。
// This method returns the Resource ID to be used to make the copy
public String loadDocsSpreadsheetEntryId(String sourceName) {
String resourceId = null;
try {
Logger.info("Loading feed URL");
URL url = new URL("https://docs.google.com/feeds/default/private/full" );
DocumentQuery query = new DocumentQuery(url);
query.setTitleQuery(sourceName);
query.setTitleExact(true);
Logger.info("Loaded feed URL");
DocumentListFeed dfeed = this.dService.getFeed(query, DocumentListFeed.class);
Logger.info("got feed");
for (DocumentListEntry entry : dfeed.getEntries()) {
Logger.info(entry.getTitle().getPlainText());
if(entry.getTitle().getPlainText().equalsIgnoreCase(sourceName))
{
Logger.info("found doc");
resourceId = entry.getResourceId();
}
}
} catch(Exception e) {
logException(e, "Loading Source Spreadsheet to copy");
}
return resourceId;
}
public void createSpreadsheetFrom(String destination, String source) {
try {
URL entryUrl = new URL("http://docs.google.com/feeds/default/private/full");
Map<String, String> parameters = new HashMap<String, String>();
String resourceID = loadDocsSpreadsheetEntryId(source);
Logger.info("Resource id %s", resourceID);
DocumentListEntry newEntry = new DocumentListEntry();
newEntry.setId(resourceID);
newEntry.setTitle(new PlainTextConstruct(destination));
this.dService.insert(entryUrl, newEntry);
} catch(Exception e) {
logException(e, "Copying Spreadsheet");
}
}