Temporary File Management

Top  Previous  Next

In our applications most of the time we create files that we do not want to store permanently. Such files need to be cleaned afterwards.

One of the tasks of the MoreMotion AF is Temporary File Management and thus maintains the files under
{APPLICATION_ROOT}/WEB-INF/MM-INF/~tempfiles folder all the time.

Temporary files can be requested from MoreMotion using the MoreMotion Java API functions. Such files are temporary and are deleted automatically when their life are over.

In the following code a temporary file whose life is 5 minutes long is requested from MoreMotion.

File file = SystemContext.getTempFileManager().getTempFile(60 * 5);

 

If we assume that the time is 2009/02/15 12:00 during the request, MoreMotion will return a file object of the file "200902151200" that is located under {APPLICATION_ROOT}/WEB-INF/MM-INF/~tempfiles folder.

If this file is created by the caller, it will be deleted by the MoreMotion after 5 minutes.
 

Storing the Temporary Files to Variables

With the functions provided by MoreMotionRequest class the use of the temporary files are even more practical. For example the following code requests  a temporary file from MoreMotion. MoreMotion returns a temporary file and stores its actual name in the pool variable "TEMPF".

File outFile = request.getOutputFile("v:TEMPF","text/xml");

 

This way, without knowing the actual name, a temporary file can be created and later that file can be accessed by using the same variable.

File inputFile = request.getRealFile("v:TEMPF");

 

Using the Temporary Files in the parameters of the Components

In all the MoreMotion components that deal with files (e.g. Filer, Reporter, ADOM) permanent files ( that can be specified in Absolute or Relative form) or  temporary files (that are implied with "v:" or "f:" prefixes)

For example to define an output file name in a component property one can specify one of the several ways as follows:

/usr/logs/1.log Absolute permanent file
logs/1.log Relative permanent file
v:log Temporary file. The name of the file is stored in pool variable "log"