Implement Comment service for a document in KM using Java
Summary
This document provides the detailed steps for implementing comment service for a document in KM. Using this we can create a new comment entry, read all the comments for a document
Applies to:
SAP Enterprise Portal, NWDS 7.0
Pre-requisites:
Knowledge of PDK application development
Basic knowledge on KM
Access to KM folders on the portal
Steps to enable comment service in KM
Steps to create the application in NWDS:
String rLocationtest = "/collaboration/comment";
IResourceContext resourceContext =
ResourceFactory.getInstance().getServiceContext("cmadmin_service");
ICollection collection =
(ICollection)ResourceFactory.getInstance().getResource(RID.getRID
(rLocationtest),resourceContext);
loopFolder(collection,resourceContext);
public void loopFolder(ICollection collection, IResourceContext resourceContext, IPortalComponentResponse response)
{
resList = collection.getChildren();
resItr = resList.listIterator();
while(resItr.hasNext())
{
IResource restemp = resItr.next();
if(restemp.isCollection() &&
LinkType.NONE.equals(restemp.getLinkType()))
{
loopFolder((ICollection)restemp,resourceContext,response);
}
else
{
docRID = RID.getRID(""+restemp);
kmResource =(IResource)
ResourceFactory.getInstance().getResource(docRID,resourceContext);
retrieveCommentsForFileInKM(kmResource);
createNewComment(docRID.toString,resourceContext);
}
restemp = null;
}// End of while
}
private void retrieveCommentsForFileInKM(IResource kmResource, IPortalComponentResponse response){
if(kmResource != null)
{
IContent content = kmResource.getContent();
InputStream is = content.getInputStream();
fileLength = content.getContentLength();
BufferedReader br = new BufferedReader(new
InputStreamReader(is));
String str = "";
StringBuffer sbuf = new StringBuffer();
while ((str = br.readLine()) != null)
{
if (!str.trim().equals(""))
{
sbuf.append(str);
}
}
br.close();
strContent = sbuf.toString();
response.write("Content in comment file: - "+strContent);
br = null;str = null;sbuf = null;content = null;is = null;
}
}
private void createNewComment(String kmPath, IPortalComponentResponse response, IResourceContext resourceContext)
{
stkRID = new StringTokenizer(kmPath,"/");
numberOfTokens = stkRID.countTokens();
difference = 1;
RIDForCreatingFile = "";
while(numberOfTokens != difference)
{
RIDForCreatingFile += "/"+stkRID.nextToken();
difference++;
}
RIDForCreatingFile = RIDForCreatingFile + "/";
newCommentFileName =
"comment_"+ep5User.getName()+"_"+System.currentTimeMillis()+".html";
//code for creating a new file
docRID = RID.getRID(RIDForCreatingFile);
folder = (ICollection)
ResourceFactory.getInstance().getResource(docRID,resourceContext);
kmResource = folder.createResource(newCommentFileName,null,null);
newCommentFileName = RIDForCreatingFile+newCommentFileName;
docRID = RID.getRID(newCommentFileName);
kmResource =(IResource)
ResourceFactory.getInstance().getResource(docRID,resourceContext);
strContent = "Adding contect to empty files to check KM write
functionality";
is = new ByteArrayInputStream(strContent.getBytes("UTF-8"));
content = new Content(is, "text/html", -1, "UTF-8", null);
kmResource.updateContent(content);
response.write("Content updated successfully<br>");
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 |