Cookie Consent by TermsFeed

Java Filter – Retrieving a File

January 13, 2012

When within a Java Filter, one may need to get the file for a particular revision of a content item. There is a class intradoc.server.DirectoryLocator that is very helpful. From this class, we can obtain the FileStoreProvider.

FileStoreProvider fileStoreProvider = DirectoryLocator.m_fileStore;

DirectoryLocator has several static methods that can get paths within the filestore to places such as weblayout directory, the vault directory, the temporary directory, the provider directory, etc. It can provide you a String path to almost any directory you want.

IdcFileDescriptor is a class that can provide the pathing to files. From a FileStoreProvider, we can create an IdcFileDescriptor.
IdcFileDescriptor idcFileDescriptor = fileStoreProvider.createDescriptor(binder, null, context);

The first parameter is a DataBinder. This is where the paremeters that are needed to build the path to the file are set. The second parameter is not needed and can be set to null. The third parameter is the ExecutionContext.

The required parameters that need to be in the DataBinder are “RenditionId”, “dDocName”, “dDocType”, “dRevLabel”, “dSecurityGroup”, “dDocAccount”, “dID”, and “dExtension”. RenditionId should be set to “primaryFile” for the primary file and “web” for the alternateFile.

Fortunately, a lot of the time most of these required parameters are already in your the original DataBinder. If you are missing some parameters you should be able to make a service call to DOC_INFO to get a ResultSet which contains all of the necessary parameters. You can then dump these parameters into a new DataBinder and feed it to the createDescriptor method call.

The file descriptor that comes back will give you something like this:

idcFileDescriptor: intradoc.filestore.BasicIdcFileDescriptor{dWebExtension=xml, dID=80, RenditionId.path=primaryFile, dStatus=RELEASED, Storage, RenditionId=primaryFile, dSecurityGroup=Public, dDoc, dOriginalName=jh000035.xml, dExtension=xml, uniqueId=c:/oracle/ucm/server/vault/web/80.xml, fileNamePrefix=null, dReleaseState=Y, dDocAccount=, path=c:/oracle/ucm/server/vault/web/80.xml, dDocName=JH000035, dRevLabel=27, dRenditionId=primaryFile}

To get the path to the file, do the following:

fileStoreProvider.forceToFilesystemPath(idcFileDescriptor, null, context); String filePath = fileStoreProvider.getFilesystemPath(idcFileDescriptor, context);

You can of course turn this file path into a Java object by using:

File myFile = new File(filePath);
© 2020 Jason Stortz (version 20200114-085855)