在Domino应用程序中集成Google的Web API服务
simpleSearch代理
下面让我们开始这个例子,在一个名为 GoogleSe.nsf 的新数据库中创建一个名为 simpleSearch 的 Notes 代理。您可以从 Sandbox下载这个数据库。这个数据库包含 simpleSearch 代理和 goSearch 代理,以及本文后将要讨论的表单和视图。这个应用程序是在 Windows 2000 上生成的,不过作为一个 Java 应用程序,它可以在任何平台上运行。在 Lotus Domino 中运行 Google API 不需要任何特殊的代理设置。当该 API 被调用时,它们将使用 Domino 所具有的任何配置。
首先复制开发者工具箱中的 GoogleAPIDemo.java 的以下代码行(注意 clientKey 是在您注册到 Google 之后,通过发送给您的许可密钥来初始化的):
清单 3. simpleAgent 代码
...
String clientKey = "4B0KufpQFHJxhAxzua0tR11ElLNrHRJ6";
String directive = "search";
String directiveArg = "Lotus Domino";
// Report the arguments received
System.out.println("Parameters:");
System.out.println("Client key = " + clientKey);
System.out.println("Directive = " + directive);
System.out.println("Args = " + directiveArg);
// Create a Google Search object, set our authorization key
GoogleSearch s = new GoogleSearch();
s.setKey(clientKey);
// Depending on user input, do search or cache query,
then print out result
try {
if (directive.equalsIgnoreCase("search")) {
s.setQueryString(directiveArg);
pw.println("about to begin doSearch...");
GoogleSearchResult r = s.doSearch();
pw.println("doSearch ok");
System.out.println("Google Search Results:");
System.out.println("======================");
System.out.println(r.toString());
...
|
在 Domino Designer 中创建 simpleSearch 并粘贴进上述代码。然后执行该代理。(本例中的搜索字符串被初始化为“Lotus Domino”。)要查看这个查询的结果,请在 simpleSearch 完成运行之后打开一个 Java Debug Console(Java 调试控制台)。您应该会看到类似如下的结果:
图 1. simpleSearch 结果
我们的 simpleSearch 代理提供了一种查看搜索结果的快速方式,它显示估计找到的 720,000 项结果中的前 10 项结果。例如,第一项包含以下内容:
清单 4. 搜索结果样例
URL = "http://www.lotus.com/"
Title = "IBM
Lotus software"
Snippet = "
... and societal demands
Domino Web Access demo upgraded to 6.5
All you've come to expect -- Lotusphere 2004 Basex Excellence Award goes to
IBM
Lotus Workplace
... "
Directory Category = {SE="", FVN="Top/Computers/Software/Operating_Systems/
Mainframe/IBM/Software"}
Directory Title = "
Lotus Software"
Summary = "IBM subsidiary best known for multi-platform Notes and
Domino
messaging groupware supports z/OS-based..."
Cached Size = "20k"
Related information present = true
Host Name = ""
|
如果从本地运行该代理,请确保 Googleapi.jar 文件位于 Notes 程序目录中并且被指派给了本地 Notes.ini 文件中的 JavaUserClasses(JavaUserClasses 具有 256 个字符的限制,因此如果向它添加 Googleapi.jar 超出了这个限制,Domino 将无法识别它)。