Code for implementing a custom review zone provider component using the Java APIThe following code shows how to implement a review zone provider to use a simple file system as a review zone. The ReviewZoneProvider defines a set of APIs used to store and retrieve content from the content repository. The ReviewZoneProvider interface handles the interactions between the Review Commenting & Approval Core service and can be categorized as follows: For example, the review zone root in this example is C:/RCA and the share is on a computer with the name review zone provider. Based on the example, the review zone root is C:\RCA and the shared path to the review zone root is \\reviewzone-provider\RCA . package custom.rzp; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.List; import com.adobe.idp.Document; import com.adobe.livecycle.rca.common.exception.PersistenceException; import com.adobe.livecycle.rca.common.exception.UserNotFoundException; import com.adobe.livecycle.rca.rzp.ReviewZoneProvider; public class ReviewZoneProviderImpl implements ReviewZoneProvider { protected String reviewZoneRoot; protected String reviewZoneRootShareLocation; protected String uriSeperator; public ReviewZoneProviderImpl () {} public String getReviewZoneRoot() { return reviewZoneRoot; } public void setReviewZoneRoot(String reviewZoneRootDir) { this.reviewZoneRoot = reviewZoneRootDir; } public String getReviewZoneRootShareLocation() { return reviewZoneRootShareLocation; } public void setReviewZoneRootShareLocation(String reviewZoneRootShareLocation) { this.reviewZoneRootShareLocation = reviewZoneRootShareLocation; if (reviewZoneRootShareLocation == null || "".equals(reviewZoneRootShareLocation)) { return ; } if (!(this.reviewZoneRootShareLocation.endsWith("/") || this.reviewZoneRootShareLocation.endsWith("\\"))) { this.uriSeperator = "\\"; this.reviewZoneRootShareLocation += this.uriSeperator; } else { this.uriSeperator = this.reviewZoneRootShareLocation.substring(this.reviewZoneRootShareLocation.length()-1); } } public String createSpace(String spacePath) throws PersistenceException { String completeSpacePath = reviewZoneRoot + File.separator + spacePath; File f = new File(completeSpacePath); if (f.exists()) { if (f.isDirectory()) return reviewZoneRootShareLocation + convertFwdSlashToBack(spacePath); throw new PersistenceException(); } boolean retVal = f.mkdirs(); if (!retVal) { throw new PersistenceException(); } return reviewZoneRootShareLocation + convertFwdSlashToBack(spacePath); } private String convertFwdSlashToBack(String spacePath) { return spacePath.replaceAll("\\/", "\\\\"); } public boolean deleteNode(String nodePath) { String completeNodePath = reviewZoneRoot + File.separator + nodePath; File f = new File(completeNodePath); return deleteDir(f); } public boolean nodeExists(String parentSpacePath, String nodeName) { String completeSpacePath = reviewZoneRoot + File.separator + parentSpacePath; File f = new File(completeSpacePath + File.separator + nodeName); return f.exists() && f.isFile(); } public Document retrieveContent(String nodePath) throws PersistenceException { String completeNodePath = reviewZoneRoot + File.separator + nodePath; try { return getDocument(completeNodePath); } catch (FileNotFoundException e) { PersistenceException e1 = new PersistenceException(); e1.initCause(e); throw e1; } } public String storeContent(String spacePath, String nodeName, Document content, String contentType) { String completeSpacePath = reviewZoneRoot + File.separator + spacePath; File f = new File(completeSpacePath + File.separator + nodeName); content.copyToFile(f); return reviewZoneRootShareLocation + convertFwdSlashToBack(spacePath + "\\" + nodeName); } public boolean spaceExists(String parentSpacePath, String spaceName) throws PersistenceException { String completeSpacePath = reviewZoneRoot + File.separator + parentSpacePath; File f = new File(completeSpacePath + File.separator + spaceName); return f.exists() && f.isDirectory(); } public List<Document> getSpaceContent(String spacePath, Boolean getOnlyFiles) throws PersistenceException { List<Document> contents = new ArrayList<Document>(); File f = new File(reviewZoneRoot + File.separator + spacePath); String[] xmlFileNames = f.list(new FilenameFilter(){ public boolean accept(File dir, String name) { return true; }}); for (String xmlFile : xmlFileNames) { Document returnDoc = retrieveContent(spacePath + File.separator + xmlFile); returnDoc.setAttribute(DOCUMENT_NAME, xmlFile); contents.add(returnDoc); } return contents; } private boolean deleteDir(File f) { if (!f.exists()) return true; if (f.isDirectory()) { String[] children = f.list(); for (int i = 0; i < children.length; i++) { if (!deleteDir(new File(f, children[i]))) { return false; } } } return f.delete(); } private Document getDocument(String completePath) throws FileNotFoundException { return new Document(new FileInputStream(new File(completePath))); } public void grantContributePermission(String nodePath, List<String> usersWithContributePermission, Boolean applyToChild, Boolean inheritParent) throws PersistenceException, UserNotFoundException { throw new UnsupportedOperationException(); } public void grantPermission(String nodePath, List<String> usersWithReadPermission, List<String> usersWithReadWritePermission, Boolean applyToChild, Boolean inheritParent) throws PersistenceException, UserNotFoundException { // no-op } public void revokeContributePermission(String nodePath, List<String> usersWithContributePermission, Boolean applyToChild) throws PersistenceException, UserNotFoundException { throw new UnsupportedOperationException(); } public boolean supportsContributePermission() throws PersistenceException { return false; } public void revokePermission(String nodePath, List<String> usersWithReadPermission, List<String> usersWithReadWritePermission, Boolean applyToChild) throws PersistenceException { // no-op } } |
|
// Ethnio survey code removed