什么是 GDATA 扩展配置文件?

发布于 2024-08-12 02:19:53 字数 646 浏览 5 评论 0原文

我想使用 SpreadsheetEntry 继承的类 BaseEntry 的 [generateAtom(..,..)][1] 方法获取 GoogleDocs 电子表格的原子格式的 XML。但我不明白该方法中的第二个参数ExtensionProfile。它是什么?如果我只想获取原子格式的 XML,调用这个方法是否足够?

XmlWriter x = new XmlWriter();
spreadSheetEntry.generateAtom(x,new ExtensionProfile());

[1]:http://code.google.com/apis/gdata/javadoc/com/google/gdata/data/BaseEntry.html#generateAtom(com.google.gdata.util.common. xml.XmlWriter、com.google.gdata.data.ExtensionProfile)

I want to get the XML in atom format of a GoogleDocs spreadsheet using the [generateAtom(..,..)][1] method of the class BaseEntry which a SpreadsheetEntry inherits. But I don't understand the the second parameter in the method, ExtensionProfile. What is it and will this method call suffice if I just want to get the XML in atom format?

XmlWriter x = new XmlWriter();
spreadSheetEntry.generateAtom(x,new ExtensionProfile());

[1]: http://code.google.com/apis/gdata/javadoc/com/google/gdata/data/BaseEntry.html#generateAtom(com.google.gdata.util.common.xml.XmlWriter, com.google.gdata.data.ExtensionProfile)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

苏辞 2024-08-19 02:19:53

来自 ExtensionProfile 的 JavaDoc

配置文件是一组允许的
每种类型的扩展以及
附加属性。

通常,如果您有服务,则可以使用 Service.getExtensionProfile()

From the JavaDoc for ExtensionProfile:

A profile is a set of allowed
extensions for each type together with
additional properties.

Usually if you've got a service, you can ask that for its extension profile using Service.getExtensionProfile().

深海夜未眠 2024-08-19 02:19:53

详细阐述 Jon Skeet 的答案,您需要实例化这样的服务:

String developer_key = "mySecretDeveloperKey";
String client_id = "myApplicationsClientId";
YouTubeService service = new YouTubeService(client_id, developer_key);

然后您可以使用扩展配置文件写入文件您的服务:

static void write_video_entry(VideoEntry video_entry) {
    try {
        String cache_file_path = Layout.get_cache_file_path(video_entry);
        File cache_file = new File(cache_file_path);
        Writer writer = new FileWriter(cache_file);
        XmlWriter xml_writer = new XmlWriter(writer);
        ExtensionProfile extension_profile = service.getExtensionProfile();
        video_entry.generateAtom(xml_writer, extension_profile);
        xml_writer.close();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

类似地,您可以使用服务的扩展配置文件读取文件:

static VideoFeed read_video_feed(File cache_file_file) {
    VideoFeed video_feed = new VideoFeed();
    try {
        InputStream input_stream = new FileInputStream(cache_file_file);
        ExtensionProfile extension_profile = service.getExtensionProfile();
        try {
            video_feed.parseAtom(extension_profile, input_stream);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        input_stream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return video_feed;
}

Elaborating Jon Skeet's answer, you need to instanciate a service like this:

String developer_key = "mySecretDeveloperKey";
String client_id = "myApplicationsClientId";
YouTubeService service = new YouTubeService(client_id, developer_key);

Then you can write to a file using the extension profile of your service:

static void write_video_entry(VideoEntry video_entry) {
    try {
        String cache_file_path = Layout.get_cache_file_path(video_entry);
        File cache_file = new File(cache_file_path);
        Writer writer = new FileWriter(cache_file);
        XmlWriter xml_writer = new XmlWriter(writer);
        ExtensionProfile extension_profile = service.getExtensionProfile();
        video_entry.generateAtom(xml_writer, extension_profile);
        xml_writer.close();
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Analogously, you can read a file using the extension profile of your service:

static VideoFeed read_video_feed(File cache_file_file) {
    VideoFeed video_feed = new VideoFeed();
    try {
        InputStream input_stream = new FileInputStream(cache_file_file);
        ExtensionProfile extension_profile = service.getExtensionProfile();
        try {
            video_feed.parseAtom(extension_profile, input_stream);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        input_stream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return video_feed;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文