thanks Ard,
code attached.
note: the key is an object that implements serializable.
the validity is an object that implements SourceValidity
the method isValid() returns 0, which should then call
isValid(SourceValidity newValidity) which is returning -1 or +1
-Ed.
On 7/30/07, Ard Schrijvers <[EMAIL PROTECTED]> wrote:
>
> If you attach the code I can take a look at it. Is it with cocoon-2.1.xor
> 2.2? For 2.1.X I am most likely to be able to help you out. 2.2 I haven't
> had time for yet.
>
> Do realize also, that if former parts in the pipeline are not cacheable,
> your generator won't be cached either! So try isolating your generator (and
> of course, put it in caching pipeline also!!)
>
> Ard
>
>
> --
>
> Hippo
> Oosteinde 11
> 1017WT Amsterdam
> The Netherlands
> Tel +31 (0)20 5224466
> -------------------------------------------------------------
> [EMAIL PROTECTED] / http://www.hippo.nl
> --------------------------------------------------------------
>
> -----Original Message-----
> *From:* Edward S [mailto:[EMAIL PROTECTED]
> *Posted At:* maandag 30 juli 2007 15:28
> *Posted To:* Cocoon User List
> *Conversation:* Cocoon Caching
> *Subject:* Re: Cocoon Caching
>
> As per the document, I created a cocoon generator and implemented the
> CacheableProcessingComponent
> interface.
>
> As stated, 2 methods should be implemented:
> 1] getKey()
> 2] getValidity()
>
> I created an object, that had all the request parameters along with the
> URI. Made that object serializable and set that one as te key.
> Similarly, I created another object that implemented SourceValidity and
> returned that object from the getValidty method.
>
> However, when I run thru the pipeline... its never adds anything to the
> cache neither it returns anything back from the cache.
>
> any thots on where I am going wrong??
>
> -Ed.
>
>
>
package com.mycompany.platform.pubfrmwrk.cocoon.generation;
import java.io.*;
import java.util.*;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.cocoon.components.source.SourceUtil;
import org.apache.cocoon.environment.*;
import org.apache.cocoon.generation.ServiceableGenerator;
import org.apache.excalibur.source.Source;
import org.apache.excalibur.source.SourceValidity;
import org.apache.log4j.Logger;
import org.xml.sax.SAXException;
import com.documentum.com.DfClientX;
import com.documentum.com.IDfClientX;
import com.documentum.fc.client.*;
import com.documentum.fc.common.*;
import com.documentum.operations.IDfExportNode;
import com.documentum.operations.IDfExportOperation;
import com.documentum.operations.IDfOperationError;
import com.mycompany.platform.utility.ConstraintChecker;
import com.mycompany.platform.utility.DocumentumProperties;
import com.mycompany.platform.pubfrmwrk.cocoon.cache.key.DctmObjectCacheKey;
import
com.mycompany.platform.pubfrmwrk.cocoon.cache.validity.DctmObjectValidity;
import com.mycompany.platform.pubfrmwrk.cocoon.servlet.ImSessionManager;
/**
* A Cocoon Generator class that returns the XML Content of a documentum object
*
*/
public class ImDMXMLContentGenerator extends ServiceableGenerator implements
CacheableProcessingComponent {
/** The logging class **/
private static Logger imLogger =
Logger.getLogger(ImDMXMLContentGenerator.class);
/** The Session Manager object that contains the documentum sessions */
protected ImSessionManager imSessionManager = null;
/** The documentum r_object_id or the folder path */
protected String objectIdOrFolderPath = null;
/** Flag indicating whether object id is present or not */
protected boolean containsObjectId = false;
/** indicates whether the output should include dctm: attributes */
protected boolean includeDmAttributes = false;
/** the temp working directory where files will be exported */
protected File workingDirectory;
/** boolean indicating whether we should download support docs or take
it directly from the catalog */
protected boolean downloadSupportDocs;
/** boolean indicating whether we should include external references to
other components */
protected boolean includeExternalRef;
protected DctmObjectCacheKey key;
protected DctmObjectValidity validity;
/* (non-Javadoc)
* @see
org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String,
org.apache.avalon.framework.parameters.Parameters)
*/
public void setup(SourceResolver resolver, Map objectModel, String src,
Parameters par)
throws ProcessingException, SAXException, IOException {
imLogger.debug("Enter - setup method of
ImDMXMLContentGenerator");
// Get Docbase and object ID from request
IDfSession session = null;
try {
Request request =
ObjectModelHelper.getRequest(objectModel);
//checks to see if docbase is provided in the request
if(! ConstraintChecker.checkDocbase(request,par)){
throw new SAXException("MISSING REQUIRED
PARAMETER - DOCBASE");
}
//checks to see that both username and password are
present
if(!
ConstraintChecker.checkUsernameAndPassword(request, par)){
throw new SAXException("EITHER USERNAME OR
PASSWORD IS MISSING IN THE REQUEST.");
}
//retreive the include_dmattr
this.includeDmAttributes =
ConstraintChecker.checkAndRetrieveIncludeDMAttr(request, par);
imLogger.debug("Include Documentum Attributes: " +
this.includeDmAttributes);
//check if we should download support docs or not
this.downloadSupportDocs =
ConstraintChecker.shouldDownloadSupportDocs(request, par);
imLogger.debug("Download Support Documents: " +
this.downloadSupportDocs);
//check if we should download support docs or not
this.includeExternalRef =
ConstraintChecker.shouldIncludeExternalReferences(request, par);
imLogger.debug("Include external references: " +
this.includeExternalRef);
this.imSessionManager =
ImSessionManager.getImSessionManager(request);
session =
this.imSessionManager.getSessionFromImSessionManager();
//gets the object id. if its not null, sets the flag to
true. if its null, gets the folder path
//if that is also null, throws an exception
this.objectIdOrFolderPath =
ConstraintChecker.checkAndRetrieveObjectId(request, par);
if(this.objectIdOrFolderPath != null &&
this.objectIdOrFolderPath.length() > 0){
this.containsObjectId = true;
imLogger.info("Object Id present in the
request. " + this.objectIdOrFolderPath);
}else{
imLogger.info("Object id not specified.
Retrieving folder path");
this.objectIdOrFolderPath =
ConstraintChecker.checkAndRetrieveFolderPath(request, par);
if(this.objectIdOrFolderPath == null ||
this.objectIdOrFolderPath.length() == 0){
imLogger.error("Folder path also NOT
specified.");
throw new SAXException("OBJECT ID OR
FOLDER PATH IS MISSING. ATLEAST ONE SHOULD BE PRESENT");
}
}
//fills the cache key object.
this.key = new DctmObjectCacheKey();
this.key.setUri(request.getRequestURI());
this.key.setObjectIdOrFolderPath(objectIdOrFolderPath);
this.key.setContainsObjectId(containsObjectId);
this.key.setIncludeDmAttributes(includeDmAttributes);
this.key.setDownloadSupportDocs(downloadSupportDocs);
this.key.setIncludeExternalRef(includeExternalRef);
imLogger.debug("Key set to:\n" + this.key);
//checks to see if the documentum object exists
IDfSysObject object = null;
object =
ConstraintChecker.validateAndRetrieveObject(session, this.objectIdOrFolderPath,
this.containsObjectId);
if(null == object){
throw new SAXException("DOCUMENTUM SYSOBJECT
DOES NOT EXIST FOR THE SPECIFIED ID: " + this.objectIdOrFolderPath);
}
String vStamp =
DocumentumProperties.getNonRepeatingAttributeValue(object,"i_vstamp");
validity = new
DctmObjectValidity(this.objectIdOrFolderPath, vStamp);
imLogger.debug("validity set to:\n" +validity);
super.setup(resolver, objectModel, src, par);
}catch (DfException e){
throw new ProcessingException("Exception in
ImDMXMLContentGenerator.setup()", e);
}finally {
if(null != this.imSessionManager){
this.imSessionManager.releaseSessionFromImSessionManager(session);
}
}
imLogger.debug("Exit - setup method of
ImDMXMLContentGenerator");
}
/* (non-Javadoc)
* @see org.apache.cocoon.generation.Generator#generate()
*/
public void generate() throws IOException, SAXException,
ProcessingException {
imLogger.debug("Enter - generate method of
ImDMXMLContentGenerator");
//checks to see if the documentum object exists
IDfSysObject object = null;
IDfSession session = null;
try {
session =
this.imSessionManager.getSessionFromImSessionManager();
object =
ConstraintChecker.validateAndRetrieveObject(session, this.objectIdOrFolderPath,
this.containsObjectId);
if(null == object){
throw new SAXException("DOCUMENTUM SYSOBJECT
DOES NOT EXIST FOR THE SPECIFIED ID: " + this.objectIdOrFolderPath);
}
this.workingDirectory = File.createTempFile("XMLC", "",
new File(System.getProperty("java.io.tmpdir")));
if (!this.workingDirectory.delete()) {
throw new IOException();
}
if (!this.workingDirectory.mkdir()) {
throw new IOException();
}
IDfClientX clientX = new DfClientX();
IDfClient localClient = clientX.getLocalClient();
IDfExportOperation operation =
clientX.getExportOperation();
operation.setDestinationDirectory(this.workingDirectory.getAbsolutePath());
operation.setRecordInRegistry(IDfExportOperation.DONT_RECORD_IN_REGISTRY);
operation.enableManageApplicationSupportDocuments(this.downloadSupportDocs);
//whether to include dctm: attributes in the result. if
using 5.2.5 use
//IDfProperties props = operation.getProperties();
//props.putBoolean("AddDCTMObjectXMLAttrs",
this.includeDmAttributes);
operation.setIncludeDCTMAttrsInXML(this.includeDmAttributes);
operation.setIncludeExternalReferences(this.includeExternalRef);
IDfExportNode node = null;
// If the document is a virtual document, we should
download its children
if (object.isVirtualDocument()) {
node = (IDfExportNode)
operation.add(object.asVirtualDocument(
"CURRENT", false));
imLogger.debug("Object is a virtual document");
} else {
node = (IDfExportNode) operation.add(object);
node.setFormat("xml");
imLogger.debug("Object NOT a virtual document");
}
imLogger.debug("Node file path set to: " +
node.getFilePath());
// Check if any errors occured during the execution of
the operation
if(!operation.execute()) {
// Get the list of errors
imLogger.error("export operation failed");
IDfList errorList = operation.getErrors();
String message = "";
IDfOperationError error = null;
// Iterate through the errors and concatenate
the error messages
for(int i = 0 ; i < errorList.getCount() ; i++)
{
error = (IDfOperationError)
errorList.get(i);
message += error.getMessage();
}
imLogger.error("Error executing the export
operation: \n" + message);
}
File file = new File(node.getFilePath());
String srcUri = file.toURI().toString();
Source inputSource = resolver.resolveURI(srcUri);
try {
imLogger.debug("Source " + super.source + "
resolved to " + inputSource.getURI());
imLogger.info("Including content for object " +
this.objectIdOrFolderPath + "): " + super.source);
SourceUtil.parse(this.manager, inputSource,
super.xmlConsumer);
} catch (SAXException e) {
SourceUtil.handleSAXException(inputSource.getURI(), e);
}
imLogger.debug("Temp file containg docbase content: " +
srcUri);
}catch (DfException e){
throw new ProcessingException("Exception in
ImDMXMLContentGenerator.setup()", e);
}finally {
if(null != this.imSessionManager){
this.imSessionManager.releaseSessionFromImSessionManager(session);
}
}
imLogger.debug("Exit - generate method of
ImDMXMLContentGenerator");
}
/* (non-Javadoc)
* @see org.apache.avalon.excalibur.pool.Recyclable#recycle()
*/
public void recycle() {
imLogger.debug("Enter - recycle method of
ImDMXMLContentGenerator");
super.recycle();
this.containsObjectId = false;
this.imSessionManager = null;
this.objectIdOrFolderPath = null;
this.includeDmAttributes = false;
//deleteFileRecursively(this.workingDirectory);
this.downloadSupportDocs = false;
this.includeExternalRef = false;
imLogger.debug("Exit - recycle method of
ImDMXMLContentGenerator");
}
/* (non-Javadoc)
* @see org.apache.avalon.framework.activity.Disposable#dispose()
*/
public void dispose() {
imLogger.debug("Enter - dispose method of
ImDMXMLContentGenerator");
this.containsObjectId = false;
this.imSessionManager = null;
this.objectIdOrFolderPath = null;
this.includeDmAttributes = false;
this.downloadSupportDocs = false;
this.includeExternalRef = false;
imLogger.debug("Exit - dispose method of
ImDMXMLContentGenerator");
}
/**
* Deletes a file recursively, ignoring errors.
*
* @param dir File to delete
*/
private void deleteFileRecursively(File dir){
imLogger.debug("Enter - deleteFileRecurse method of
ImDMXMLContentGenerator");
if(dir.isDirectory()){
File[] files = dir.listFiles();
for(int i=0; i<files.length; i++){
deleteFileRecursively(files[i]);
}
}
if (dir.delete()){
if(imLogger.isDebugEnabled()){
imLogger.debug("Deleted:" + dir.getAbsolutePath());
}
}else{
imLogger.warn("Failed to delete:" +
dir.getAbsolutePath());
}
imLogger.debug("Enter - deleteFileRecurse method of
ImDMXMLContentGenerator");
}
public Serializable getKey() {
imLogger.debug("Enter - getKey method of
ImDMXMLContentGenerator");
imLogger.debug("Key: " + key);
imLogger.debug("Exit - getKey method of
ImDMXMLContentGenerator");
return key;
}
public SourceValidity getValidity() {
imLogger.debug("Enter - getValidity method of
ImDMXMLContentGenerator");
imLogger.debug("Validity: " + validity);
imLogger.debug("Exit - getValidity method of
ImDMXMLContentGenerator");
return validity;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]