3.1.2: 2012-07-31

net.sf.basedb.util.extensions.manager.processor
Class ExtractResourcesProcessor

java.lang.Object
  extended by net.sf.basedb.util.extensions.manager.processor.ExtractResourcesProcessor
All Implemented Interfaces:
ExtensionsFileProcessor

public class ExtractResourcesProcessor
extends Object
implements ExtensionsFileProcessor

A file processor implementation that extracts resources from JAR files. The main target directory must be specified when an instance is constructed. Each processed JAR file is extracted into a subdirectory with the same name as the JAR file. Existing files are always overwritten.

The filter (in the form of a regular expressions pattern) can be specified to limit which files are extracted from the JAR file. The filter is also used to re-write target file names if they need to be different from the file names in the JAR file.

Note! It is recommended that this processor is paired with a ValidAndNewOrModifiedFilter since it is usually no point in extracting resources from invalid extensions.

Since:
3.0
Author:
Nicklas
Last modified
$Date: 2012-03-14 10:54:51 +0100 (Wed, 14 Mar 2012) $

Field Summary
private  Pattern filter
           
private static org.apache.log4j.Logger log
           
private  File mainDir
           
private  int numError
           
private  int numFiles
           
private  int numTotalExtracted
           
private  String replacement
           
private  ProcessResults results
           
 
Constructor Summary
ExtractResourcesProcessor(File mainDir, Pattern filter, String replacement, ProcessResults results)
          Create a new processor.
ExtractResourcesProcessor(File mainDir, ProcessResults results)
          Create a new processor.
 
Method Summary
 void begin(ExtensionsManager manager, int numFiles)
          Called by the extensions manager before the processing starts.
 void done(ExtensionsManager manager)
          Called by the extensions manager after a successful completion of the processing.
 void done(ExtensionsManager manager, Throwable t)
          Called by the extensions manager if an exception was thrown by the processor.
 int getNumError()
          Get the number of files that was had an error.
 int getNumExtracted()
          Get the total number of resources that was extracts.
 int getNumFiles()
          Get the number of files that was successfully processed.
 void processFile(ExtensionsManager manager, ExtensionsFile.WriteableExtensionsFile wFile)
          Called by the extensions manager for each extensions file that it manages.
 void setForceOverwrite(boolean forceOverwrite)
          Deprecated. In 3.1, no replacement since all files must be overwritten to ensure proper functionality
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static final org.apache.log4j.Logger log

mainDir

private final File mainDir

filter

private final Pattern filter

replacement

private final String replacement

results

private final ProcessResults results

numFiles

private int numFiles

numError

private int numError

numTotalExtracted

private int numTotalExtracted
Constructor Detail

ExtractResourcesProcessor

public ExtractResourcesProcessor(File mainDir,
                                 ProcessResults results)
Create a new processor.

Parameters:
mainDir - The main directory to where the resources should be extracted

ExtractResourcesProcessor

public ExtractResourcesProcessor(File mainDir,
                                 Pattern filter,
                                 String replacement,
                                 ProcessResults results)
Create a new processor.

Parameters:
mainDir - The main directory to where the resources should be extracted
filter - A regular expression filter that must match the file name in the JAR file
replacement - A replacement string to create a new file name using Matcher.replaceAll(String).
Method Detail

begin

public void begin(ExtensionsManager manager,
                  int numFiles)
Description copied from interface: ExtensionsFileProcessor
Called by the extensions manager before the processing starts.

Specified by:
begin in interface ExtensionsFileProcessor
Parameters:
manager - The manager that is executing the action
numFiles - The number of extension files that is going to be processed this time

processFile

public void processFile(ExtensionsManager manager,
                        ExtensionsFile.WriteableExtensionsFile wFile)
Description copied from interface: ExtensionsFileProcessor
Called by the extensions manager for each extensions file that it manages. The order of the files is generally not predicatable and may change from one invokation to the next.

If the processor throws an exception the manager will abort processing and call ExtensionsFileProcessor.done(ExtensionsManager, Throwable). Error that are related to a specific file should be catched by the processor and registered by calling .......

If all files was processed without exceptions the manager will call ExtensionsFileProcessor.done(ExtensionsManager).

Note that the file is read-only to begin with. If the processor wants to call any write-operation the file must be opened by calling ExtensionsFile.WriteableExtensionsFile.open(). It is recommended that the processor calls ExtensionsFile.WriteableExtensionsFile.close() once it is done writing.

Specified by:
processFile in interface ExtensionsFileProcessor
Parameters:
manager - The manager that is executing the action
wFile - The file to be processed

done

public void done(ExtensionsManager manager)
Description copied from interface: ExtensionsFileProcessor
Called by the extensions manager after a successful completion of the processing.

Specified by:
done in interface ExtensionsFileProcessor
Parameters:
manager - The manager that is executing the action

done

public void done(ExtensionsManager manager,
                 Throwable t)
Description copied from interface: ExtensionsFileProcessor
Called by the extensions manager if an exception was thrown by the processor.

Specified by:
done in interface ExtensionsFileProcessor
Parameters:
manager - The manager that is executing the action
t - The exception

setForceOverwrite

@Deprecated
public void setForceOverwrite(boolean forceOverwrite)
Deprecated. In 3.1, no replacement since all files must be overwritten to ensure proper functionality

Set a flag indicating if already existing files should always be updated or not.

Parameters:
forceOverwrite - TRUE to force overwriting existing files, FALSE to only overwrite files if they are different from the files in the JAR

getNumFiles

public int getNumFiles()
Get the number of files that was successfully processed.


getNumError

public int getNumError()
Get the number of files that was had an error.


getNumExtracted

public int getNumExtracted()
Get the total number of resources that was extracts.


3.1.2: 2012-07-31