内容


IBM Lotus Quickr 8.1.1 中针对 wiki 和博客内容的 RESTful 服务简介

Lotus Quickr 是团队协作软件,旨在转变共享文档和 Web 内容的方式,帮助用户高效地跨团队协作和工作。它提供一组公共 API 来访问 Lotus Quickr 中的内容以及构建适合于客户需求的解决方案。

在 8.1.1 之前的 Lotus Quickr 版本中,公共 API 只支持与文档相关的服务。在版本 8.1.1 中,Lotus Quickr 增强了基于 Representational State Transfer (REST) 的服务,提供特性来让用户通过基于 REST 的服务获取、创建、更新和删除 wiki 和博客内容。用户也可以对 wiki 和博客内容的评论执行协同操作。

为了帮助解释 wiki 和博客内容基于 REST 的服务,我们首先介绍受支持的 URL 模式、HTTP 方法和请求参数。此外,还会提供一些示例请求和响应,介绍 wiki 和博客内容及评论的创建、阅读、更新和删除 (CRUD) 操作。

最后,对于列出博客库中的博客条目、创建博客条目和评论博客条目,我们将给出生动的示例代码,帮助您进一步理解这些基于 REST 的服务。

先决条件

为了从本文得到最大的收获,应该了解以下内容:

  • Lotus Quickr
  • REST 服务
  • Atom 联合格式
  • IBM WebSphere® Portal 和 IBM Lotus Web Content Management 的基本知识
  • Java™ 编程

Wiki 和博客内容

本节我们讨论 servlet 上下文以及针对 wiki 和博客的所有受支持的服务,包括 servlet 上下文的 URL 模式、受支持的 HTTP 方法和请求参数。还会列出针对每种服务的示例请求和响应。

Servlet 上下文

跟 Lotus Quickr 文档 REST 服务不同,wiki 和博客 REST 服务的 servlet 上下文是 webcontent/rest,而不是 dm/atom,描述如下:

  • 所有服务的完整路径应该是这样的:<protocol>://<host>:<port>/webcontent/rest/<url-pattern>。例如,如果协议是 HTTP,服务器是 lwptsthink43.cn.example.com,端口是 10038,那么对于该服务,它的完整路径应该是:

    http://lwptsthink43.cn.example.com:10038/webcontent/rest/introspection
  • 该服务返回一个服务文档,其中包含库和提要的链接。
  • 该服务上只支持 GET 方法。
  • 该 GET 方法需要认证,不支持匿名访问。
  • 额外的参数和 HTTP 头都不受支持。

下面是一个示例请求和一个示例响应(参见清单 1)。

示例请求:GET /webcontent/rest/introspection HTTP/1.1

清单 1. 示例响应
 <?xml version="1.0" encoding="UTF-8"?> 
 <service xmlns="http://purl.org/atom/app#" 
 xmlns:atom="http://www.w3.org/2005/Atom"> 
  <workspace> 
    <atom:title type="text">MediaLibrary Documents</atom:title> 
    <collection 
    href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/libraries/feed"> 
      <atom:title type="text">All Libraries</atom:title> 
      <accept>application/*,image/*,*/*</accept> 
    </collection> 
    <collection href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/libraries/ 
    feed?type=wiki"> 
      <atom:title type="text">All wiki libraries</atom:title> 
      <accept>application/*,image/*,*/*</accept> 
    </collection> 
    <collection href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/libraries/ 
    feed?type=blog"> 
      <atom:title type="text">All blog libraries</atom:title> 
      <accept>application/*,image/*,*/*</accept> 
    </collection> 
  </workspace> 
 </service>

<host>:<port>/libraries/feed

该服务描述如下:

  • 它返回 Lotus Web Content Management 中组件库的一个提要。
  • 该服务上只支持 GET 方法。
  • 该 GET 方法需要认证,不支持匿名访问。

表 1 中列出了受支持的参数。

表 1. <host>:<port>/libraries/feed 受支持的参数
参数是否必需说明
type wiki, blog, all可选将库列表限制为指定的类型
placeId空间 id 可选将列表限制为指定空间中包含的组件库
page1, 2, 3,等等可选指定将检索的页面(假定恒定的页面大小)
pagesize10, 20,等等可选指定包含在页面请求中的条目数
sKpublished, created, modified可选对响应进行分类的关键字
sOdsc, asc可选对响应进行分类的顺序
aclsfalse, true可选指定是否在每个库中返回已认证用户的许可

在上表中:

  • 任何参数的默认值都以粗体显示。
  • placeId 参数中的每个空间可以包含很多 wiki 或博客库;如果用户指定了空间 ID,那么只会返回该空间中的库。
  • 如果 acls 参数设置为 true,那么会返回当前用户在每个资源上的许可。许可包括 View、Edit、Delete 和 AddChild。
  • Manager 角色具有所有许可;Editor 角色具有 View、Edit 和 AddChild 许可;Contributor 角色具有 View 和 AddChild 许可;Reader 角色只具有 View 许可。

下面是一个示例请求和一个示例响应(参见清单 2)。

示例请求:GET /webcontent/rest/libraries/feed?acls=true HTTP/1.1

清单 2. 示例响应
 <?xml version="1.0" encoding="UTF-8"?> 
 <feed xmlns="http://www.w3.org/2005/Atom"> 
  <id>urn:lsid:ibm.com:td:libraries</id> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/libraries/ 
  feed" rel="self"></link> 
  <category term="library" scheme="tag:ibm.com,2006:td/type" l 
  abel="library"></category> 
  <title type="text">All Libraries</title> 
  <generator uri="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/" 
  version="1.0">Teamspace Web Content</generator> 
  <updated>2008-11-26T07:29:05.422Z</updated> 
  <entry xmlns:td="urn:ibm.com/td"> 
    <id>urn:lsid:ibm.com:td:7a1cd3004be710acb161f18ffc876575</id> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7a1cd3004be710acb161f18ffc876575/entry" rel="self"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/lotus/poc/? 
    uri=wcm%3aa93444004be710aeb181f18ffc876575" rel="alternate"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7a1cd3004be710acb161f18ffc876575/entry" rel="edit"></link> 
    <category term="library" scheme="tag:ibm.com,2006:td/type" 
    label="library"></category> 
    <category term="wiki" scheme="tag:ibm.com,2006:td/type" 
    label="wiki"></category> 
    <title type="text">Wiki</title> 
    <summary type="text">Allows the creation of wiki pages with user content by 
    teamspace members.</summary> 
    <td:label>7a1bd3804be710aab160f18ffc876575</td:label> 
    <published>2008-11-12T05:57:50.078Z</published> 
    <updated>2008-11-25T09:13:58.875Z</updated> 
    <td:modified>2008-11-12T05:57:50.078Z</td:modified> 
    <td:created>2008-11-12T05:57:50.078Z</td:created> 
 <content type="application/atom+xml" src="//lwptsthink43.cn.ibm.com:10038/ 
 webcontent/rest/library/7a1cd3004be710acb161f18ffc876575/feed"></content> 
 <td:permissions>Delete,Edit,AddChild,View</td:permissions> 
  </entry> 
  <entry xmlns:td="urn:ibm.com/td"> 
    <id>urn:lsid:ibm.com:td:daf4dd004be710a5b135f18ffc876575</id> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    daf4dd004be710a5b135f18ffc876575/entry" rel="self"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/lotus/poc/?uri= 
    wcm%3a7e93bc804be710a9b15bf18ffc876575" rel="alternate"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    daf4dd004be710a5b135f18ffc876575/entry" rel="edit"></link> 
    <category term="library" scheme="tag:ibm.com,2006:td/type" 
    label="library"></category> 
    <category term="blog" scheme="tag:ibm.com,2006:td/type" 
    label="blog"></category> 
    <title type="text">Blog</title> 
    <summary type="text">Allows the posting of blog entries and comments by 
    teamspace members.</summary> 
    <td:label>b6006a004be710a5b134f18ffc876575</td:label> 
    <published>2008-11-12T05:57:47.234Z</published> 
    <updated>2008-11-25T09:13:59.703Z</updated> 
    <td:modified>2008-11-12T05:57:47.234Z</td:modified> 
    <td:created>2008-11-12T05:57:47.234Z</td:created> 
 <content type="application/atom+xml" src="//lwptsthink43.cn.ibm.com:10038/ 
 webcontent/rest/library/daf4dd004be710a5b135f18ffc876575/feed"></content> 
 <td:permissions>AddChild,View</td:permissions> 
  </entry> 
 </feed>

/library/{library-id}/entry

该服务返回用户指定库的条目,并且该服务上只支持 GET 方法。

表 2 显示了受支持的参数。

表 2. library/{library-id}/entry 受支持的参数
参数是否必需说明
aclsfalse, true可选指定是否在每个库上返回已认证用户的许可

下面是示例请求和示例响应(参见清单 3)。

示例请求:GET /webcontent/rest/library/7a1cd3004be710acb161f18ffc876575/entry?acls=true HTTP/1.1

清单 3. 示例响应
 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td"> 
  <id>urn:lsid:ibm.com:td:7a1cd3004be710acb161f18ffc876575</id> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7a1cd3004be710acb161f18ffc876575/entry" rel="self" /> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/lotus/poc/?uri= 
  wcm%3aa93444004be710aeb181f18ffc876575" rel="alternate" /> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7a1cd3004be710acb161f18ffc876575/entry" rel="edit" /> 
  <category term="library" scheme="tag:ibm.com,2006:td/type" label="library" /> 
  <category term="wiki" scheme="tag:ibm.com,2006:td/type" label="wiki" /> 
  <title type="text">Wiki</title> 
  <summary type="text">Allows the creation of wiki pages with user content by 
  teamspace members.</summary> 
  <td:label>7a1bd3804be710aab160f18ffc876575</td:label> 
  <published>2008-11-12T05:57:50.078Z</published> 
  <updated>2008-11-25T09:13:58.875Z</updated> 
  <td:modified>2008-11-12T05:57:50.078Z</td:modified> 
  <td:created>2008-11-12T05:57:50.078Z</td:created> 
  <content type="application/atom+xml" src="//lwptsthink43.cn.ibm.com:10038/ 
  webcontent/rest/library/7a1cd3004be710acb161f18ffc876575/feed" /> 
  <td:permissions>Delete,Edit,AddChild,View</td:permissions> 
  </entry>

/library/{library-id}/feed

对于该服务:

  • GET 和 POST 方法都受支持。
  • POST 在指定的库中创建一个新文档(即 wiki 页面或博客帖子)。
  • GET 返回指定库中文档的提要。

表 3 中的参数只对 GET 方法受支持;POST 方法不支持任何参数。

表 3. GET 方法受支持的参数
参数是否必需说明
inlinefalse, true可选当 inline=true 时,条目包含实际的内容,而不是包含带有内容链接的 src 属性
page1, 2, 3,等等可选指定将检索的页面(假定恒定的页面大小)
pagesize10, 20,等等可选指定包含在页面请求中的条目数
sKtitle, updated, published, created, modified可选对响应进行分类的关键字
sOdsc, asc可选对响应进行分类的顺序
aclsfalse, true可选指定是否对每个文档返回已认证用户的许可

当 inline 参数设置为 true 时,条目的 <content> 元素是 wiki 页面或博客条目的实际内容(要了解详细的信息,请参见示例响应)。如果它设置为 false,那么条目的 <content> 元素类似于:

 <content src=http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/
 7a1cd3004be710acb161f18ffc876575/document/a93444004be710aeb181f18ffc876575/
 media  type="text/html">
 </content>

下面是示例请求和响应(参见清单 4):

对于 GET 方法

示例请求:

GET /webcontent/rest/library/7a1cd3004be710acb161f18ffc876575/feed?inline=true HTTP/1.1
清单 4. 示例响应
 <?xml version="1.0" encoding="UTF-8"?> 
 <feed xmlns="http://www.w3.org/2005/Atom"> 
  <id>urn:lsid:ibm.com:td:7a1cd3004be710acb161f18ffc876575</id> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7a1cd3004be710acb161f18ffc876575/feed" rel="self"></link> 
  <category term="library" scheme="tag:ibm.com,2006:td/type" 
  label="library"></category> 
  <title type="text">Wiki</title> 
  <generator uri="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7a1cd3004be710acb161f18ffc876575/" version="1.0">Teamspace 
  Web Content</generator> 
  <updated>2008-11-10T03:40:23.469Z</updated> 
  <collection href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7a1cd3004be710acb161f18ffc876575/feed" xmlns="http://purl.org/atom/app#"> 
    <atom:title type="text" xmlns:atom="http://www.w3.org/2005/Atom"> 
    Wiki</atom:title> 
    <accept>text/html,application/atom+xml</accept> 
  </collection> 
  <entry xmlns:td="urn:ibm.com/td"> 
    <id>urn:lsid:ibm.com:td:a93444004be710aeb181f18ffc876575</id> 
    <title type="text">Welcome to your new Wiki</title> 
    <published>2007-01-30T21:17:44.220Z</published> 
    <updated>2008-11-10T03:40:23.469Z</updated> 
    <td:modified>2008-11-10T03:40:23.469Z</td:modified> 
    <td:created>2007-01-30T21:17:44.220Z</td:created> 
    <summary type="text">Use the Team Wiki to communicate thoughts 
    about project.</summary> 
    <td:uuid>a93444004be710aeb181f18ffc876575</td:uuid> 
    <author> 
      <name>wpsadmin g wpsadmin sn</name> 
      <email>wpsadmin@cn.ibm.com</email> 
      <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts 
      %2Cc%3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
    </author> 
    <link href="/lotus/poc/?uri=wcm%3aa93444004be710aeb181f18ffc876575" rel="alternate"> 
    </link> 
    <content type="html">Use the Team Wiki to communicate thoughts about project, 
    ideas, and to share information. You can start a thought in the wiki and then watch 
    as team members respond. Team Wiki is a good place to brainstorm with the team. 
    <br> Click "Edit Page" to get started.<br> Tip: Use the wiki instead 
    of email. Because questions and answers are often hidden in personal email, post a 
    blog to generate quick responses that are visible to the team.<p style="margin: 
    0px;"></p></content> 
    <category scheme="tag:ibm.com,2006:td/" label="document" 
    term="document"></category> 
    <category scheme="tag:ibm.com,2006:td/" label="page" 
    term="page"></category> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7a1cd3004be710acb161f18ffc876575/document/a93444004be710aeb181f18ffc876575/ 
    entry" rel="self"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7a1cd3004be710acb161f18ffc876575/document/a93444004be710aeb181f18ffc876575/ 
    entry" rel="edit"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7a1cd3004be710acb161f18ffc876575/document/a93444004be710aeb181f18ffc876575/feed" 
    rel="replies"></link> 
  </entry> 
 </feed>

对于 POST 方法

下面是示例请求和响应(分别参见清单 5 和清单 6)。

清单 5. 示例请求
 POST /webcontent/rest/library/7a1cd3004be710acb161f18ffc876575/feed?inline=true HTTP/1.1 
 Host: lwptsthink43.cn.ibm.com 
 Content-Type: application/msword 
 Content-Length: nnnn 
 Authorization: Basic ... 
 <entry xmlns="http://www.w3.org/2005/Atom"> 
   <content type="html"><p><b> </b>&nbsp;&nbsp; 
   Programmatically created entry.</p> 
   </content> 
   <title type="text">Test Entry Title 
   </title> 
   <summary type="text">Summary for Test Entry Ttile 
   </summary> 
 </entry>
清单 6. 示例响应
 HTTP/1.1 200 OK 
 Date: Fri, 13 Apr 2007 17:17:11 GMT 
 Content-Length: nnn 
 Content-Type: application/atom+xml; charset="utf-8"
 Location: http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
 6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/entry 
 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td"> 
  <id>urn:lsid:ibm.com:td:6df9c6004c127f26bc10fdaa37d7846a</id> 
  <title type="text">Test Entry Title </title> 
  <published>2008-11-26T09:32:39.484Z</published> 
  <updated>2008-11-26T09:32:39.984Z</updated> 
  <td:modified>2008-11-26T09:32:39.984Z</td:modified> 
  <td:created>2008-11-26T09:32:39.484Z</td:created> 
  <summary type="text">Summary for Test Entry Title</summary> 
  <td:uuid>6df9c6004c127f26bc10fdaa37d7846a</td:uuid> 
  <author> 
    <name>wpsadmin g wpsadmin sn</name> 
    <email>wpsadmin@cn.ibm.com</email> 
    <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts%2Cc 
    %3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
  </author> 
  <link href="/lotus/poc/?uri=wcm%3a6df9c6004c127f26bc10fdaa37d7846a" 
  rel="alternate"></link> 
  <content type="text/html" src="//lwptsthink43.cn.ibm.com:10038/webcontent/ 
  rest/library/6b1fc9804a9207249ceadc23ebd19157/document/ 
  6df9c6004c127f26bc10fdaa37d7846a/media"></content> 
  <category scheme="tag:ibm.com,2006:td/" label="document" 
  term="document"></category> 
  <category scheme="tag:ibm.com,2006:td/" label="page" 
  term="page"></category> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/entry" 
  rel="self"></link> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/entry" 
  rel="edit"></link> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/feed" 
  rel="replies"></link> 
 </entry>

/library/{library-id}/document/{document-id}/entry

对于该服务,GET、PUT 和 DELETE 方法都受支持,其中:

  • GET 返回一个针对指定文档的条目。
  • PUT 更新指定的文档。
  • DELETE 删除指定的文档。

表 4 中的参数只对 GET 方法受支持;PUT 和 DELETE 方法不支持任何参数。

表 4. GET 方法受支持的参数
参数是否必需说明
aclsfalse, true可选指定是否在每个库中返回已认证用户的许可

对于 GET 方法

下面是示例请求和响应(参见清单 7)。

示例请求:

 GET /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/
 document/886a62804c128889bc18fdaa37d7846a/entry HTTP/1.1
清单 7. 示例响应
 <?xml version="1.0" encoding="UTF-8" ?> 
 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td"> 
  <id>urn:lsid:ibm.com:td:886a62804c128889bc18fdaa37d7846a</id> 
  <title type="text">Test Entry Title</title> 
  <published>2008-11-26T09:49:51.609Z</published> 
  <updated>2008-11-26T09:49:51.609Z</updated> 
  <td:modified>2008-11-26T09:49:51.609Z</td:modified> 
  <td:created>2008-11-26T09:49:51.609Z</td:created> 
  <summary type="text">Programmatically created entry summary</summary> 
  <td:uuid>886a62804c128889bc18fdaa37d7846a</td:uuid> 
 <author> 
  <name>wpsadmin g wpsadmin sn</name> 
  <email>wpsadmin@cn.ibm.com</email> 
  <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts%2Cc%3Dus 
  %2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
  </author> 
  <link href="/lotus/poc/?uri=wcm%3a886a62804c128889bc18fdaa37d7846a" rel="alternate" /> 
 <content 
   type="text/html" src="//lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
	   7e0bad004a9206d69c88dc23ebd19157/document/886a62804c128889bc18fdaa37d7846a/ 
	   media" /> 
  <category scheme="tag:ibm.com,2006:td/" label="document" term="document" /> 
 <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
 7e0bad004a9206d69c88dc23ebd19157/document/886a62804c128889bc18fdaa37d7846a/entry" 
 rel="self" /> 
 <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
 7e0bad004a9206d69c88dc23ebd19157/document/886a62804c128889bc18fdaa37d7846a/entry" 
 rel="edit" /> 
 <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
 7e0bad004a9206d69c88dc23ebd19157/document/886a62804c128889bc18fdaa37d7846a/feed" 
 rel="replies" /> 
 </entry>

对于 PUT 方法

下面是示例请求和响应(分别参见清单 8 和清单 9)。

清单 8. 示例请求
 PUT /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/ 
 document/886a62804c128889bc18fdaa37d7846a/entry HTTP/1.1 
 Host: lwptsthink43.cn.ibm.com 
 Content-Length: nnnn 
 Authorization: Basic ... 
 <entry xmlns="http://www.w3.org/2005/Atom"> 
   <content type="html"><p><b> </b>&nbsp;&nbsp; 
   Programmatically Updated entry.</p> 
   </content> 
   <title type="text">Test Entry Title-Updated 
   </title> 
   <summary type="text">Summary for Test Entry Ttile-Updated 
   </summary> 
 </entry>
清单 9. 示例响应
 HTTP/1.1 200 OK 
 Date: Fri, 13 Apr 2007 17:17:11 GMT 
 Content-Length: nnn 
 Content-Type: application/atom+xml; charset="utf-8"
 Location: http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
 6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/entry 
 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td"> 
  <id>urn:lsid:ibm.com:td:6df9c6004c127f26bc10fdaa37d7846a</id> 
  <title type="text">Test Entry Title-Updated </title> 
  <published>2008-11-26T09:32:39.484Z</published> 
  <updated>2008-11-26T09:32:39.984Z</updated> 
  <td:modified>2008-11-26T09:32:39.984Z</td:modified> 
  <td:created>2008-11-26T09:32:39.484Z</td:created> 
  <summary type="text">Summary for Test Entry Title-Updated </summary> 
  <td:uuid>6df9c6004c127f26bc10fdaa37d7846a</td:uuid> 
  <author> 
    <name>wpsadmin g wpsadmin sn</name> 
    <email>wpsadmin@cn.ibm.com</email> 
    <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts%2Cc 
    %3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
  </author> 
  <link href="/lotus/poc/?uri=wcm%3a6df9c6004c127f26bc10fdaa37d7846a" rel="alternate"> 
   </link> 
  <content type="text/html" src="//lwptsthink43.cn.ibm.com:10038/webcontent/ 
     rest/library/6b1fc9804a9207249ceadc23ebd19157/ 
     document/6df9c6004c127f26bc10fdaa37d7846a/media"></content> 
  <category scheme="tag:ibm.com,2006:td/" label="document" 
  term="document"></category> 
  <category scheme="tag:ibm.com,2006:td/" label="page" 
  term="page"></category> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/entry" 
  rel="self"></link> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/entry" 
  rel="edit"></link> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/6df9c6004c127f26bc10fdaa37d7846a/feed" 
  rel="replies"></link> 
 </entry>

对于 DELETE 方法

下面是示例请求和响应。

示例请求:

 Delete /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/
 document/886a62804c128889bc18fdaa37d7846a/entry HTTP/1.1 
 Host: lwptsthink43.cn.ibm.com
 Authorization: Basic ...

示例响应:

HTTP/1.1 200 OK
Date: Fri, 13 Apr 2008 17:17:11 GMT

/library/{library-id}/document/{document-id}/feed

在该服务中,GET 和 POST 方法都是受支持的,其中:

  • POST 为指定的文档创建一个新的评论。
  • GET 针对指定文档的评论返回一个提要。

表 5 中的参数只对 GET 方法受支持;POST 方法不支持任何参数。

表 5. GET 方法受支持的参数
参数是否必需说明
inlinefalse, true可选当 inline=true 时,条目包含实际的内容,而不是包含带有内容链接的 src 属性
page1, 2, 3,等等可选指定将检索的页面(假定恒定的页面大小)
pagesize10, 20,等等可选指定包含在页面请求中的条目数
sKtitle, updated, published可选对响应进行分类的关键字
sOdsc, asc可选对响应进行分类的顺序
aclsfalse, true可选指定是否在每个评论上返回已认证用户的许可

对于 GET 方法

下面是示例请求和响应(参见清单 10)。

示例请求:

 GET /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/document/
 886a62804c128889bc18fdaa37d7846a/feed HTTP/1.1
清单 10. 示例响应
 <?xml version="1.0" encoding="UTF-8"?> 
 <feed xmlns="http://www.w3.org/2005/Atom"> 
  <id>urn:lsid:ibm.com:td:886a62804c128889bc18fdaa37d7846a</id> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7e0bad004a9206d69c88dc23ebd19157/document/886a62804c128889bc18fdaa37d7846a/feed" 
  rel="self"></link> 
  <category term="comment" scheme="tag:ibm.com,2006:td/type" 
  label="comment"></category> 
  <title type="text">Test Entry</title> 
  <generator uri="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7e0bad004a9206d69c88dc23ebd19157/" 
  version="1.0">Teamspace Web Content</generator> 
  <updated>2008-11-27T01:31:02.906Z</updated> 
  <collection href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7e0bad004a9206d69c88dc23ebd19157/document/886a62804c128889bc18fdaa37d7846a/feed" 
  xmlns="http://purl.org/atom/app#"> 
    <atom:title type="text" xmlns:atom="http://www.w3.org/2005/Atom"> 
    Test Entry</atom:title> 
    <accept>text/html,application/atom+xml</accept> 
  </collection> 
  <entry xmlns:td="urn:ibm.com/td"> 
    <id>urn:lsid:ibm.com:td:fb73a7804c148a23bc28fdaa37d7846a</id> 
    <title type="text">wpsadmin g wpsadmin sn Today at 9:31 AM</title> 
    <published>2008-11-27T01:31:02.906Z</published> 
    <updated>2008-11-27T01:31:02.906Z</updated> 
    <td:modified>2008-11-27T01:31:02.906Z</td:modified> 
    <td:created>2008-11-27T01:31:02.906Z</td:created> 
    <summary type="text">test again</summary> 
    <td:uuid>fb73a7804c148a23bc28fdaa37d7846a</td:uuid> 
    <author> 
      <name>wpsadmin g wpsadmin sn</name> 
      <email>wpsadmin@cn.ibm.com</email> 
      <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts%2Cc 
      %3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
    </author> 
    <link href="/lotus/poc/?uri=wcm%3afb73a7804c148a23bc28fdaa37d7846a" 
    rel="alternate"></link> 
    <content type="text/html" src="//lwptsthink43.cn.ibm.com:10038/ 
 webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/document/ 
 1c1cef804c1488b4bc1afdaa37d7846a/comment/fb73a7804c148a23bc28fdaa37d7846a/ 
 media"></content> 
    <category scheme="tag:ibm.com,2006:td/" label="comment" 
    term="comment"></category> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7e0bad004a9206d69c88dc23ebd19157/document/1c1cef804c1488b4bc1afdaa37d7846a/ 
    comment/fb73a7804c148a23bc28fdaa37d7846a/entry" rel="self"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7e0bad004a9206d69c88dc23ebd19157/document/1c1cef804c1488b4bc1afdaa37d7846a/ 
    comment/fb73a7804c148a23bc28fdaa37d7846a/entry" rel="edit"></link> 
  </entry> 
  <entry xmlns:td="urn:ibm.com/td"> 
    <id>urn:lsid:ibm.com:td:d23708004c1488b9bc26fdaa37d7846a</id> 
    <title type="text">wpsadmin g wpsadmin sn Today at 9:28 AM</title> 
    <published>2008-11-27T01:28:28.344Z</published> 
    <updated>2008-11-27T01:28:28.344Z</updated> 
    <td:modified>2008-11-27T01:28:28.344Z</td:modified> 
    <td:created>2008-11-27T01:28:28.344Z</td:created> 
    <summary type="text">test</summary> 
    <td:uuid>d23708004c1488b9bc26fdaa37d7846a</td:uuid> 
    <author> 
      <name>wpsadmin g wpsadmin sn</name> 
      <email>wpsadmin@cn.ibm.com</email> 
      <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts 
      %2Cc%3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
    </author> 
    <link href="/lotus/poc/?uri=wcm%3ad23708004c1488b9bc26fdaa37d7846a" 
    rel="alternate"></link> 
    <content type="text/html" src="//lwptsthink43.cn.ibm.com:10038/webcontent/ 
    rest/library/7e0bad004a9206d69c88dc23ebd19157/document/ 
    1c1cef804c1488b4bc1afdaa37d7846a/comment/d23708004c1488b9bc26fdaa37d7846a/ 
    media"></content> 
    <category scheme="tag:ibm.com,2006:td/" label="comment" 
    term="comment"></category> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7e0bad004a9206d69c88dc23ebd19157/document/1c1cef804c1488b4bc1afdaa37d7846a/ 
    comment/d23708004c1488b9bc26fdaa37d7846a/entry" rel="self"></link> 
    <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
    7e0bad004a9206d69c88dc23ebd19157/document/1c1cef804c1488b4bc1afdaa37d7846a/ 
    comment/d23708004c1488b9bc26fdaa37d7846a/entry" rel="edit"></link> 
  </entry> 
 </feed>

对于 POST 方法

下面是示例请求和响应(分别参见清单 11 和清单 12)。

清单 11. 示例请求
 POST /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/ 
 document/886a62804c128889bc18fdaa37d7846a/feed HTTP/1.1 
 Host: lwptsthink43.cn.ibm.com 
 Content-Type: application/msword 
 Content-Length: nnnn 
 Authorization: Basic ... 
 <entry xmlns="http://www.w3.org/2005/Atom"> 
   <content type="html"><p><b> </b> 
   &nbsp;&nbsp;Programmatically created entry.</p> 
   </content> 
   <title type="text">Test Entry Title 
   </title> 
   <category scheme="tag:ibgm.com,2006:td/type" term="comment"> 
   </category> 
 </entry>
清单 12. 示例响应
 HTTP/1.1 200 OK 
 Date: Fri, 13 Apr 2008 17:17:11 GMT 
 Content-Length: nnn 
 Content-Type: application/atom+xml; charset="utf-8"
 Location: http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
 6b1fc9804a9207249ceadc23ebd19157/document/096d53804c148da9bc34fdaa37d7846a/ 
 comment/096d53804c148da9bc33fdaa37d7846a/entry 
 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td"> 
  <id>urn:lsid:ibm.com:td:096d53804c148da9bc33fdaa37d7846a</id> 
  <title type="text">wpsadmin g wpsadmin sn Today at 9:37 AM</title> 
  <published>2008-11-27T01:37:30.500Z</published> 
  <updated>2008-11-27T01:37:30.672Z</updated> 
  <td:modified>2008-11-27T01:37:30.672Z</td:modified> 
  <td:created>2008-11-27T01:37:30.500Z</td:created> 
  <summary type="text">Thu Nov 27 09:42:45 CST 2008  
  Programmatically created comment.</summary> 
  <td:uuid>096d53804c148da9bc33fdaa37d7846a</td:uuid> 
  <author> 
    <name>wpsadmin g wpsadmin sn</name> 
    <email>wpsadmin@cn.ibm.com</email> 
    <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts%2Cc 
    %3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
  </author> 
  <link href="/lotus/poc/?uri=wcm%3a096d53804c148da9bc33fdaa37d7846a" 
  rel="alternate"></link> 
  < contenttype="text/html" src="//lwptsthink43.cn.ibm.com:10038/webcontent/ 
 rest/library/6b1fc9804a9207249ceadc23ebd19157/document/096d53804c148da9bc34fdaa37d7846a/ 
 comment/096d53804c148da9bc33fdaa37d7846a/media"></content> 
  <category scheme="tag:ibm.com,2006:td/" label="comment" 
  term="comment"></category> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/096d53804c148da9bc34fdaa37d7846a/comment/ 
  096d53804c148da9bc33fdaa37d7846a/entry" rel="self"></link> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/096d53804c148da9bc34fdaa37d7846a/ 
  comment/096d53804c148da9bc33fdaa37d7846a/entry" rel="edit"></link> 
 </entry>

/library/{library-id}/document/{document-id}/comment/comment-id}/entry

GET、PUT 和 DELETE 方法对该服务是受支持的,其中:

  • GET 返回一个针对指定评论的条目。
  • PUT 更新指定的评论。
  • DELETE 删除指定的评论。

表 6 中的参数只在执行 GET 方法时受支持;PUT 和 DELETE 方法不支持任何参数。

表 6. GET 方法受支持的参数
参数是否必需说明
aclsfalse, true可选指定是否对每个库返回已认证用户的许可

对于 GET 方法

下面是示例请求和响应(参见清单 13)。

示例请求:

GET /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/document/
40dc74004c149271bc3cfdaa37d7846a/comment/55eeec804c1492ddbc44fdaa37d7846a/entry HTTP/1.1
清单 13. 示例响应
 <?xml version="1.0" encoding="UTF-8" ?> 
 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td"> 
  <id>urn:lsid:ibm.com:td:55eeec804c1492ddbc44fdaa37d7846a</id> 
  <title type="text">wpsadmin g wpsadmin sn Today at 9:47 AM</title> 
  <published>2008-11-27T01:47:02.109Z</published> 
  <updated>2008-11-27T01:47:02.109Z</updated> 
  <td:modified>2008-11-27T01:47:02.109Z</td:modified> 
  <td:created>2008-11-27T01:47:02.109Z</td:created> 
  <summary type="text">this is the first comment</summary> 
  <td:uuid>55eeec804c1492ddbc44fdaa37d7846a</td:uuid> 
  <author> 
    <name>wpsadmin g wpsadmin sn</name> 
    <email>wpsadmin@cn.ibm.com</email> 
   <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts%2Cc 
   %3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
 </author> 
   <link href="/lotus/poc/?uri=wcm%3a55eeec804c1492ddbc44fdaa37d7846a" rel="alternate" /> 
  <content 
    type="text/html" src="//lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7e0bad004a9206d69c88dc23ebd19157/document/766a77004c1492dcbc3efdaa37d7846a/comment/ 
  55eeec804c1492ddbc44fdaa37d7846a/media" /> 
   <category scheme="tag:ibm.com,2006:td/" label="comment" term="comment" /> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7e0bad004a9206d69c88dc23ebd19157/document/766a77004c1492dcbc3efdaa37d7846a/comment/ 
  55eeec804c1492ddbc44fdaa37d7846a/entry" rel="self" /> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  7e0bad004a9206d69c88dc23ebd19157/document/766a77004c1492dcbc3efdaa37d7846a/ 
  comment/55eeec804c1492ddbc44fdaa37d7846a/entry" rel="edit" /> 
 </entry>

对于 PUT 方法

下面是示例请求和响应(分别参见清单 14 和清单 15)。

清单 14. 示例请求
 PUT /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/document/ 
 40dc74004c149271bc3cfdaa37d7846a/comment/55eeec804c1492ddbc44fdaa37d7846a/entry HTTP/1.1 
 Host: lwptsthink43.cn.ibm.com 
 Content-Length: nnnn 
 Authorization: Basic ... 
 <entry xmlns="http://www.w3.org/2005/Atom"> 
   <content type="html"><p><b> </b> 
   &nbsp;&nbsp;Programmatically Updated entry.</p> 
   </content> 
   <title type="text">Test Entry Title-Updated 
   </title> 
   <summary type="text">Summary for Test Entry Ttile-Updated 
   </summary> 
 </entry>
清单 15. 示例响应
 HTTP/1.1 200 OK 
 Date: Fri, 13 Apr 2007 17:17:11 GMT 
 Content-Length: nnn 
 Content-Type: application/atom+xml; charset="utf-8"
 Location: http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
 6b1fc9804a9207249ceadc23ebd19157/document/014241804c149b27bc52fdaa37d7846a/entry 
 <entry xmlns="http://www.w3.org/2005/Atom" xmlns:td="urn:ibm.com/td"> 
  <id>urn:lsid:ibm.com:td:014241804c149b27bc52fdaa37d7846a</id> 
  <title type="text">API_Automation_Test:Test Entry - Thu Nov 27 10:07:28 
  CST 2008</title> 
  <published>2008-11-27T02:02:13.375Z</published> 
  <updated>2008-11-27T02:02:13.812Z</updated> 
  <td:modified>2008-11-27T02:02:13.812Z</td:modified> 
  <td:created>2008-11-27T02:02:13.375Z</td:created> 
  <summary type="text">Summary for: API_Automation_Test:Test Entry - 
  Thu Nov 27 10:07:28 CST 2008</summary> 
  <td:uuid>014241804c149b27bc52fdaa37d7846a</td:uuid> 
  <author> 
    <name>wpsadmin g wpsadmin sn</name> 
    <email>wpsadmin@cn.ibm.com</email> 
    <uri>uid%3Dwpsadmin%2Ccn%3Dusers%2Cl%3Dwestford%2Cst%3Dmassachusetts%2Cc 
    %3Dus%2Cou%3Dlotus%2Co%3Dsoftware+group%2Cdc%3Dibm%2Cdc%3Dcom</uri> 
  </author> 
  <link href="/lotus/poc/?uri=wcm%3a014241804c149b27bc52fdaa37d7846a" 
  rel="alternate"></link> 
  <content type="text/html" src="//lwptsthink43.cn.ibm.com:10038/webcontent/ 
  rest/library/6b1fc9804a9207249ceadc23ebd19157/document/ 
  014241804c149b27bc52fdaa37d7846a/media"></content> 
  <category scheme="tag:ibm.com,2006:td/" label="document" 
  term="document"></category> 
  <category scheme="tag:ibm.com,2006:td/" label="page" 
  term="page"></category> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/014241804c149b27bc52fdaa37d7846a/entry" 
  rel="self"></link> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/014241804c149b27bc52fdaa37d7846a/entry" 
  rel="edit"></link> 
  <link href="http://lwptsthink43.cn.ibm.com:10038/webcontent/rest/library/ 
  6b1fc9804a9207249ceadc23ebd19157/document/014241804c149b27bc52fdaa37d7846a/feed" 
  rel="replies"></link> 
 </entry>

对于 DELETE 方法

下面是示例请求和响应。

示例请求:

Delete /webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/document/ 40dc74004c149271bc3cfdaa37d7846a/comment/55eeec804c1492ddbc44fdaa37d7846a/entry HTTP/1.1 Host: lwptsthink43.cn.ibm.com Authorization: Basic ...

示例响应:

HTTP/1.1 200 OK
Date: Fri, 13 Apr 2007 17:17:11 GMT

实际的服务

本节我们将介绍实际的例子,即如何列出博客库中的博客条目,如何创建博客条目,以及如何为博客条目添加评论。

整个例子中,使用了 Apache Abdera 来进行 Atom 发布和响应解析。要了解更多详细信息,请参见 developerWorks® 文章 “认识 Atom 发布协议,第 3 部分 : Apache Abdera 项目简介”。

列出博客库中的博客条目

如前所述,要得到博客库中的博客条目,发送一个 Getting 请求到以下 URL:
https://localhost:10038/webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/feed
如清单 16 中的代码片段所示。

清单 16. Getting 请求
 public void getLibraryFeed() throws Exception 
  { 
    String url = “https://localhost:10038/webcontent/rest/ 
 library/7e0bad004a9206d69c88dc23ebd19157/feed”; 
	 //create an abdera client 
	 CommonsClient client = new CommonsClient(); 
 Credentials creds = new UsernamePasswordCredentials(“mshani”, “password”); 
    client.addCredentials(url, null, null, creds); 
 client.usePreemptiveAuthentication(true); 

 //Send the Getting request 
    ClientRespone response = client.get(url); 
    Element blogElement = response.getDocument().getRoot(); 
    releaseResponse(); 
    Feed blogFeed = (Feed) blogElement; 
    List list = blogFeed.getEntries(); 
    Iterator iter = list.iterator(); 
    while (iter.hasNext()) 
 { 
  //Every entry means a blog entry 
      Entry entry = iter.next(); 
      //Get the blog entry ’ s infromation 
	  String title = entry.getTitle(); 
	  String summary = entry.getSummary(); 
      String author = entry.getAuthor().getName(); 
	  //Render the blog entry ’ s title, summary and name to the User Interface. 
      ………… 
      …………
    } 
  }

因此,一个博客条目被添加到博客库(参见图 1)。

图 1. 添加到博客库的博客条目
添加到博客库的博客条目
添加到博客库的博客条目

创建新的博客条目

要创建新的博客条目,发送一个 HTTP POST 请求到以下库提要 URL 中:
http://localhost:10038/webcontent/rest/library/7e0bad004a9206d69c88dc23ebd19157/feed
如清单 17 中的代码片段所示。

清单 17. HTTP POST 请求
 public String createBlogEntry() throws Exception 
  { 
     String url = “https://localhost:10038/webcontent/rest/ 
 library/7e0bad004a9206d69c88dc23ebd19157/feed”; 
	 //create an abdera client 
	 CommonsClient client = new CommonsClient(); 
 Credentials creds = new UsernamePasswordCredentials(“mshani”, “password”); 
    client.addCredentials(url, null, null, creds); 
 client.usePreemptiveAuthentication(true); 

 //Create an posted abdera entry 
	 Entry blogEntry = Abdera.getNewFactory.newEntry(); 
    //set the blog entry title    
    blogEntry.setTitle("IntroDucing REST based services for wiki and blog content"); 
 String summary = "<p><b>Learn how to create web content using REST based 
 services</b></p>”; 
 //set the blog entry summary 
 blogEntry.setContentAsHtml(summary); 

 //Send the POST request 
    ClientRespone response = client.post(url, blogEntry); 
    Element blogElement = response.getDocument().getRoot(); 
    releaseResponse(); 
 Entry entry = (Entry) blogElement; 
 QName QNAME_UUID = new QName("urn:ibm.com/td", ”uuid”, “td”); 
 String blogEntryUUID = entry.getSimpleExtension(QNAME_UUID); 
    
    return  blogEntryUUID; 
  }

因此,成功创建了一个新的博客条目(参见图 2)。

图 2. 新的博客条目
新的博客条目
新的博客条目

为博客条目添加评论

要为博客条目添加评论,我们需要在博客条目提要中张贴一个评论条目。张贴的 URL 应该类似于:

http://localost:10038/webcontent/rest/library/12c41d804d2f16e9af42efa98d8a5f1c/
document/704e15004d2f7c5baf76efa98d8a5f1c/feed

代码片段应该类似于清单 18 中所示的代码。

清单 18. 在博客提要中张贴评论条目
 public String createBlogEntry() throws Exception 
  { 
     String url = “http://localost:10038/webcontent/rest/library/ 
     12c41d804d2f16e9af42efa98d8a5f1c/document/704e15004d2f7c5baf76efa98d8a5f1c/feed”; 
	 //create an abdera client 
	 CommonsClient client = new CommonsClient(); 
 Credentials creds = new UsernamePasswordCredentials(“mshani”, “password”); 
    client.addCredentials(url, null, null, creds); 
 client.usePreemptiveAuthentication(true); 

 //Create an posted abdera entry 
	 Entry commentEntry = Abdera.getNewFactory.newEntry(); 
    //set the comment entry title    
    String summary = "<p><b>This is a good article which is 
    worthy to read</b></p>”; 
 //set the blog entry summary 
 commentEntry.setContentAsHtml(summary); 
 //Set the entry category 
	 Category category = factory.newCategory(); 
    category.setScheme("tag:ibgm.com,2006:td/type"); 
    category.setTerm("comment"); 
 commentEntry.addCategory(category); 

 //Send the POST request 
    ClientRespone response = client.post(url, commentEntry); 
    Element commentElement = response.getDocument().getRoot(); 
    releaseResponse(); 
 Entry entry = (Entry) commentElement; 
 QName QNAME_UUID = new QName("urn:ibm.com/td", ”uuid”, “td”); 
 String commentUUID = entry.getSimpleExtension(QNAME_UUID); 
    
    return  commentUUID; 
  }

因此,创建了一个博客条目的评论,如图 3 所示。

图 3. 博客条目的评论
博客条目的评论
博客条目的评论

本节中我们展示了实际的例子,即如何列出博客库中的博客条目,如何创建博客条目,以及如何评论博客条目。其他操作(例如,更新或删除博客条目,或者更新或删除博客条目的评论)的过程与我们介绍的这三个操作非常类似。

结束语

Lotus Quickr 的针对 wiki 和博客内容的基于 REST 的服务,提供一种方便、健壮的方式访问 Lotus Quickr for WebSphere Portal 中的 Web 内容。用户可以获得所有的 wiki 和博客库的信息,可以创建、更新和删除指定的 wiki 页面或博客条目,并且可以 CRUD 指定的评论。

在这些服务的帮助下,用户可以定制自己的个性化 Web 内容展示。此外,这些服务还与 Lotus Quickr 基于 REST 的文档服务的格式一致,很容易理解和使用。


相关主题

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=10
Zone=Lotus, WebSphere
ArticleID=428282
ArticleTitle=IBM Lotus Quickr 8.1.1 中针对 wiki 和博客内容的 RESTful 服务简介
publish-date=09142009