CM API 9.2 - Unleash the CM power
Suchin Rengan's Blog |
October 15, 2006 2:15 PM
|
Comments (4)
WebLogic Portal 9.2 has greatly improved Content Management (CM) features.
Some of the new CM features include:
- Content Linking - Ability to link contents, useful in
creating content relationships.
- Content Workflows
You can find a complete set of WebLogic Portal features here.
You can also find useful code samples here.
I thought it might be useful for some one trying to develop a portal
solution encompassing BEA Vitual Content Repository (VCR). If you have been
working on WebLogic 8.1 portal, there has been changes to the portal
libraries
(some of the libraries have been deprecated, approaches to accessing
repository through API have changed).
Let's break down some of the common repository related operations that
you might be working on.
- Searching Content
- Create, Update, Delete content - version and non-version
- Fetching Linked contents
- Managing Repository Types
- Managing Repository
All the VCR operations is done by accessing ContentManagerFactory.
ContentManagerFactory is a factory class that provides reference to
various APIs that allow us to perform the above mentioned operations.
Some CM
operations require appropriate credentials which is encapsulated in the
HttpServletRequest object. ContentContext
encapsulates the request and
provides a context to which a user is performing content access. An
instance of
ContentContext class is created by simply providing a
HttpServletRequest object to its constructor.
Searching Content
Content searching is a very common operation that is performed on a
content repository. Following is a simple example for searching content
nodes. ISearchManager is the high level interface class that provides
access to low level search operations.
// Get access to ISearchManager ISearchManager searchManager = ContentManagerFactory.getSearchManager();
//Create a ContentContext ContentContext ctx = new ContentContext(request);
We then need to create a Search
object. This may be a familiar operation to those who have worked on
WebLogic Portal 8.1 CM APIs. A quick sample is provided below.
//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);
Before we do an actual search, I would like to introduce another class
that one has to get familarized with.
ISortableFilterablePagedList, quite
a mouthful and also very useful in getting our content results. It is
an immutable collections like object and is used to hold search
results. It
can hold a list of ID
objects, Version
objects etc. and will be
mentioned in examples that I am presenting for content
operations.
ISortableFilterablePagedList list = null; // using the seachManager to access Content Nodes try{ list = searchManager.search(cc,search); } catch(RepositoryException repExcep){ // handle exception throw repExcep; }
If you are dealing with multiple repositories, then you can narrow down the search by using search paths.
We can avail Library Services feature of WebLogic Portal where we can
have versioned content and content workflows. If we have not enabled Library Services, we need to get familiarized
with INodeManager class. Clearly a manager interface to accessing and
manipulating content nodes (type Node).
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(); }
If we are accessing properties of a verioned content, we should get
familiarized with VirtualNodes. This is important specially if we have
library services enabled for our content repository. Also, a reference
for a VirtualNode is fetched using IVersionManager, which is another
important Manager API to access versioned content and I will be
discussing more in the versioning part.
// 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); }
This is a very simple example of how to search content and access them
using CM APIs.
Creating/ Modifying
Content
Content creation or modification is an administrative task and needs
appropriate access through credentials. Another important CM class to
get familiarized is VersionableContent, especially in
scenarios where content versioning is used. If we do not have to deal
with content versioning then the creation of content is more or less
straight forward. In both scenarios, we need to create Property[] that
encapsulates content properties.
// 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);
Lets take a scenario where we are dealing with content that do not need
versioning
// 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);
For a versionable content, you can use the above code and add the
following:
// 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);
That is about it, if you are creating content using CM APIs. There is
also a new feature in WebLogic 9.2 that deals with Linked Contents and
following is an example that demonstrates how to create a LinkedContent.
Working with Linked Content
Linked
contents are new in 9.2. As mentioned earlier they allow establishing
content relationships. In fact, the concepts discussed above holds good
when working with Linked Contents.
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);
So as you can see the pattern repeats. All it takes is an initial understanding of the APIs.
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Suchin-
Great post! Thank you! We should also point out that the 8.1 CM SPI will still work with WLP 9.2. We did, however, introduce a new "Extended SPI" which will support the new CM capabilities that we added to WLP9.2. The javadocs for the SPI can be found at: http://e-docs.bea.com/wlp/docs92/javadoc/com/bea/content/spi/package-summary.html.
Cheers,
Wendy Bales
Posted by: wbales on October 16, 2006 at 1:17 PM
-
Great post to get us newbies rolling on this api. Any chance you'd have the basic process for securing a webapp that integrates these apis to create content? i.e., which resources should be accessible to a role/group/user?...and how to work through that in the admin console?
Posted by: rgarrison@acm.org on August 2, 2007 at 6:28 AM
-
I stuck in searching a Node containing Calendar Property ...
Could any one help me out in this regard.
thanks
Posted by: pavankumarjoshi on August 9, 2007 at 6:32 AM
-
Thanks Thanks Thanks!!! Finally a sample.. - xeozone.com
Posted by: xeozone on October 8, 2007 at 1:56 PM
|