2

ここで述べたように、ドキュメントをコピーしたい:

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

私は最新のJava Gdata Libraryを使用していますが、これには適切なラッパーメソッドがありません.Java gdata libの初心者です。

役に立つ場合は、認証済みの DocsService を既に取得しています。

1 つがソース名で、もう 1 つがコピー名である 2 つの文字列を取るメソッドにそれをラップすると、ボーナス ポイントが得られます。

4

1 に答える 1

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

}
于 2010-08-24T12:59:44.690 に答える