2010-08-24 45 views
2

我想复制一个文件这里提到:使用gdata将Java客户端发送到Google文档列表API。

http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#CopyingDocs

我使用的是最新的Java GDATA库,它没有一个很好的包装方法来做到这一点,我是一个福利局到java gdata lib。

我已经有了一个认证的DocsService,如果这很有用的话。

奖励积分如果将其包装到一个采用两个字符串的方法中,一个是源名称,另一个是副本名称。

回答

1

好,我做到了....

只是让大家看到... this.dService是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"); 
     } 

} 
+0

感谢马克发布您的解决方案,这正是我一直在寻找的东西,我处于需要复制电子表格的相同情况。很有帮助! – Brummo 2011-01-01 23:44:06