跳到导航
dev2dev.bea.com.cn
首页 资源中心 dev2dev学堂 在线技术论坛 专家Blog User Group CodeShare
dev2dev 首页 > 资源中心 > 专家Blog > 专家Blog文章
CM API 9.2——释放CM的能量

时间:2006-12-15
作者:Suchin Rengan
浏览次数:
本文关键字:WebLogic Portal 9.2Content ManagementCM释放CM的能量WebLogic PortalVCR操作VCR
文章工具
推荐给朋友 推荐给朋友
打印文章 打印文章

  WebLogic Portal 9.2极大地改进了Content Management(CM)功能。一些新的CM功能包括:

  • 内容链接——能够链接内容,用于创建内容关系。
  • 内容工作流

  在这里您可以找到一组完整的WebLogic Portal功能。在这里,您还可以找到有用的代码示例。我认为对于尝试开发包含BEA Vitual Content Repository(VCR)的门户解决方案的人来说,它可能会很有用。如果您使用的是WebLogic 8.1门户,那么门户库已经进行了改动(某些库已经过期,通过API访问库的方法也已经变化)。

  让我们了解一下与您可能遇到的操作相关的常见库:

  • 搜索内容
  • 创建、更新和删除内容——有版本和无版本的
  • 获取链接内容
  • 管理库类型
  • 管理库

  所有的VCR操作都是通过访问ContentManagerFactory来完成的。ContentManagerFactory是一个工厂类,用于提供到各种API的引用,以便让我们能够执行上述操作。一些CM操作需要正确的证书,这些证书封装在HttpServletRequest对象中。ContentContext封装了请求,并提供一个上下文让用户在其中执行内容访问。只要提供一个HttpServletRequest对象给ContentContext类的构造器,即可创建这个类的一个实例。

  搜索内容

  内容搜索是一项在内容库上执行的常见操作。下面给出一个搜索内容节点的简单例子。ISearchManager是高级接口类,用于提供对低级搜索操作的访问。

// Get access to ISearchManager ISearchManager searchManager = ContentManagerFactory.getSearchManager(); //Create a ContentContext ContentContext ctx = new ContentContext(request);

  接下来,我们需要创建一个Search对象。对于那些使用过WebLogic Portal 8.1 CM API的人来说,这项操作可能十分熟悉。下面给出了一个快速的例子:

//Create a CM search expression
// query is a CM query e.g. "cm_objectclass == 'artist_profile'"
// artist_profile is a type in the CM repository
Expression exp = ExpressionHelper.parse(query);
Search search = new Search();
search.setExpression(exp);

  在进行实际的搜索之前,我还要介绍您必须熟悉的另一个类。它就是 ISortableFilterablePagedList,名字很长,在获得内容结果的过程中非常有用。就像对象一样,它也是一个不变的集合,用于保存搜索结果。它可以保存ID对象的一个列表,Version对象等等,而且在内容操作的例子中,我还会提到它。

ISortableFilterablePagedList list = null;
// using the seachManager to access Content Nodes
try{
    list = searchManager.search(cc,search);
}
catch(RepositoryException repExcep){
    // handle exception
    throw repExcep;
}

  如果要使用多个库,可以通过使用搜索路径来缩小搜索的范围。

  

   使用有版本的内容和内容工作流时,我们可以利用WebLogic Portal的Library Services功能。如果没有启用Library Services,我们需要熟悉INodeManager类。通过一个管理者界面可以清楚地访问和操作内容节点(类型节点)。

INodeManager nodeManager = ContentManagerFactory,getNodeManager();
// Finally, we iterate through our search results
Iterator it = list.iterator;
while(it.hasNext()){
    ID id = (ID) it.next();
    Node node = nodeManager.getNodeByUUID(ctx,id);
    // Accessing a specific property 
    Property prop1 = node.getProperty("Name");
    Value val = prop1.getValue();
    String stringValue = val.getStringValue();
}

  如果要访问有版本内容的属性,我们应该熟悉VirtualNodes。如果我们为内容库启用了库服务,这将变得特别重要。此外,使用IVersionManager可以获取对VirtualNode的引用,IVersionManager是另一个用于访问有版本内容的重要Manager API,在版本控制部分中,我将对它进行更详细的讨论。

// Version manager
IVersionManager versionManager = ContentManagerFactory.getVersionManager();

// Finally, we iterate through our search results
Iterator it = list.iterator;
while(it.hasNext()){
    ID id = (ID) it.next();
    // Getting a virtual node for the content ID.
    VirtualNode vNode = versionManager.getNode(cc, id);
     Version ver = vNode.getCurrentVersion();
    Property prop = ver.getProperty(propertyName);
}

  这是一个十分简单的例子,其内容是如何搜索内容和使用CM API访问这些内容。

   创建/修改内容

  内容创建或修改是一项管理任务,需要通过证书进行正确的访问。需要熟悉的另一个重要CM类是VersionableContent,尤其是当使用内容版本控制的时候。如果我们不必处理内容版本控制,那么创建内容就会更加或更不直观。在这两种情况下,我们需要创建Property[]来封装内容属性。

// creating properties
// Value has overloaded constructor to accept values of various primitive types. 
// For creating a Binary value property use BinaryValue
Value val = new Value(propertyValue);
Property prop = new Property(propertyName, val);
ArrayList propList = new ArrayList();
propList.add(prop);
...

Property[] props = new Property[propList.size()];
propList.toArray(props);

  让我们讨论一个处理无需版本控制的内容时的场景:

// non versioning content
INodeManager nodeManager = ContentManagerFactory.getNodeManager();

// cc = ContentContext, see above on how to get this,
// repositoryPath = "BEA Repository", 
// contentType - must be a string value matching the type in the repository

Node contentNode = nodeManager.addNode(cc, repositoryPath, contentType, props);

  对于可有版本的内容,可以使用以上代码,并加入下面的内容:

// Here we are setting the content status to PUBLISHED. See Workflow where a list of content status is mentioned
// Also, VersionableContent is the API required for creating a content that is under version control

VersionableContent vc = new VersionableContent(Workflow.PUBLISHED, "", props);

// We have dealt with versionManager before
versionManager.checkIn(cc, contentNode.getId(), vc);

  使用CM API创建内容时,以上就是全部过程。WebLogic 9.2中还有一项新功能,用于处理链接内容,下面就是一个演示如何创建LinkedContent的例子:

  使用链接内容

  链接内容是9.2版本中的新功能。如前所述,这项功能允许建立内容关系。事实上,使用链接内容时,上面所讨论的概念也适用。

Node contentNode = nm.addNode(cc, albumRepositoryPath + "/" + trackInfo.getAlbumName(), propertyType, props);
ID id = contentNode.getId();
// search for a linked ID and store it in a ID variable linkID
...
Value val = new Value(linkID);
Property prop = new Property(linkPropertyName, val);
...
//create the props array which of type Property[], and create a VersionableContent
VersionableContent vc = new VersionableContent(Workflow.PUBLISHED,"", props);
// cc - ContentContext
ContentManagerFactory.getVersionManager.checkIn(cc, id, vc);

  您可以看到模式在重复,它所采用的是对API的初始理解。

原文出处:http://dev2dev.bea.com/blog/srengan/archive/2006/10/cm_api_92_unlea.html

dot dot dot

dot
  作者其它文章
您对本文的评价
您对这篇文章的看法如何?
太棒了!5分 不错啊 4分 一般般 3分 有待提高 2分 不好 1分