public class FileHandlingAction extends AbstractAction
 This class defines the following keys:
 
 os -  The possible general values for the Operating System can
                    be "all", "windows", "unix". Or the value can be more
                    specific to a particular Windows platform or unix platform
                    such as "Windows 95", "Windows 98", "Windows NT",
                    "Windows 2000", "Solaris". These values should EXACTLY
                    match the value returned by the System property "os.name"
                    when called from Java.
 
 file_operation -
                    The possible general values for the File Operation can be
                    COPY_IF_NOT_EXIST, OVERWRITE, APPEND,
                    APPEND_OR_COPY_IF_NOT_EXIST, APPEND_OR_NOTHING, INSERT,
                    REPLACE, or REMOVE_CONTENT. Descriptive
                    explaination of each of these can be seen below.
 
 source_file -
                    Specifies the absolute path to the source file.
 
 source_string -
                    The string which is going to be used in either appending,
                    replacing or inserting in the destination file.
 
 destination_file -
                    Specifies the absolute path to the destination file.
 
 check_string -
                    The string whose existence is checked in the destination
                    file before performaing append or insert. If the string is
                    found in the file then the operation is not done.
 
 insert_linefeed -
                    The possible values for this can be "true" or "false".
                    By default it is "false". When set to "true", there would
                    be a linefeed inserted in the destination file before and
                    after the insert file/string and before the appended file.
 
 insert_around_line_containing -
                    This string is used in the INSERT file operation. The line
                    before/after which the insertion is to be done is found
                    using this string. The first line in the destination file
                    which contains this string is set to be the target line
                    before/after which the insertion is to be done.
 
 string_to_replace -
                    This is the string you want to replace in the destination
                    file.
 
 insert_after -
                    The possible values for this can be "true" or "false".
                    By default it is "false". When set to "true", the
                    insertion of the string/file is done before the target
                    line in the destination file.
 
| Modifier and Type | Field and Description | 
|---|---|
static String | 
ALL_OS
Value for the key "os". 
 | 
static String | 
APPEND
Value for the key "fileoperation". 
 | 
static String | 
APPEND_OR_COPY_IF_NOT_EXIST
Value for the key "fileoperation". 
 | 
static String | 
APPEND_OR_NOTHING
Value for the key "fileoperation". 
 | 
static String | 
CHECKSTRING_KEY
The string to check if the APPEND/INSERT is conditional. 
 | 
static String | 
COPY_IF_NOT_EXIST
Value for the key "fileoperation". 
 | 
static String | 
DESTINATION_KEY
The destination file (absolute path)
 Defined as: "destination_file". 
 | 
static String | 
FILE_OPERATION_KEY  | 
static String | 
INSERT
Value for the key "fileoperation". 
 | 
static String | 
INSERT_AFTER_KEY
A boolean value to tell if you wish to insert after the line specified
 using INSERT_AROUND_LINE_KEY or before it. 
 | 
static String | 
INSERT_AROUND_LINE_KEY
This string is used to find the line after/before which the source file/string
 is to be inserted. 
 | 
static String | 
INSERT_LINEFEED_KEY
A boolean value to tell if you wish to insert a line feed before
 APPENDING/INSERTING a file or string. 
 | 
static String | 
OS_KEY  | 
static String | 
OVERWRITE
Value for the key "fileoperation". 
 | 
static String | 
REMOVE_CONTENT
Value for the key "fileoperation". 
 | 
static String | 
REPLACE
Value for the key "fileoperation". 
 | 
static String | 
SOURCE_KEY
The source file (absolute path)
 Defined as: "source_file". 
 | 
static String | 
SOURCE_STRING_KEY
The source string
 Defined as: "source_string". 
 | 
static String | 
STRING_TO_REPLACE_KEY
This is the string which needs to be replaced. 
 | 
static String | 
UNIX_OS
Value for the key "os". 
 | 
static String | 
WINDOWS_OS
Value for the key "os". 
 | 
CONTINUE_ON_ERROR, m_defaultOptions, m_options| Constructor and Description | 
|---|
FileHandlingAction()  | 
FileHandlingAction(String[] args)  | 
| Modifier and Type | Method and Description | 
|---|---|
protected void | 
appendFile(File sourceFile,
          File destFile,
          String checkString,
          boolean insertLinefeed)  | 
protected void | 
appendString(String stringToAppend,
            File destFile,
            String checkString,
            boolean insertLinefeed)  | 
protected void | 
copyFile(File sourceFile,
        File destFile)  | 
protected boolean | 
doesFileContainString(File file,
                     String checkString)  | 
void | 
failed(Throwable t)
Invoked if this Action has failed. 
 | 
protected File | 
getFile(String dir,
       String fname,
       boolean createDir,
       boolean createFile)
Returns a File object given the directory location and filename. 
 | 
protected void | 
insertFile(File sourceFile,
          File destFile,
          String locationString,
          boolean afterLine,
          String checkString,
          boolean insertLinefeed)  | 
protected void | 
insertString(String stringToInsert,
            File destFile,
            String locationString,
            boolean afterLine,
            String checkString,
            boolean insertLinefeed)  | 
static void | 
main(String[] args)  | 
protected void | 
parseArguments(String[] args)  | 
void | 
perform()
Performs this Action. 
 | 
protected void | 
removeContents(File sourceFile,
              File destFile)  | 
protected void | 
replaceString(String stringToInsert,
             File destFile,
             String stringToReplace)  | 
void | 
stop()
Stops this Action. 
 | 
getDescription, getName, getValue, isContinueOnError, isPostgres, putValue, setDefaultOptions, setDescription, setName, setOptionspublic static final String OS_KEY
public static final String FILE_OPERATION_KEY
public static final String SOURCE_KEY
public static final String SOURCE_STRING_KEY
public static final String DESTINATION_KEY
public static final String CHECKSTRING_KEY
public static final String INSERT_LINEFEED_KEY
public static final String INSERT_AROUND_LINE_KEY
public static final String STRING_TO_REPLACE_KEY
public static final String INSERT_AFTER_KEY
public static final String COPY_IF_NOT_EXIST
public static final String OVERWRITE
public static final String APPEND
public static final String APPEND_OR_COPY_IF_NOT_EXIST
public static final String APPEND_OR_NOTHING
public static final String INSERT
public static final String REPLACE
public static final String REMOVE_CONTENT
public static final String ALL_OS
public static final String WINDOWS_OS
public static final String UNIX_OS
public FileHandlingAction(String[] args)
public FileHandlingAction()
public void perform()
             throws ActionFailedException
ActionFailedException - if the action could not be performed.protected void copyFile(File sourceFile, File destFile) throws ActionFailedException
ActionFailedExceptionprotected void appendString(String stringToAppend, File destFile, String checkString, boolean insertLinefeed) throws ActionFailedException
ActionFailedExceptionprotected void appendFile(File sourceFile, File destFile, String checkString, boolean insertLinefeed) throws ActionFailedException
ActionFailedExceptionprotected void insertString(String stringToInsert, File destFile, String locationString, boolean afterLine, String checkString, boolean insertLinefeed) throws ActionFailedException
ActionFailedExceptionprotected void insertFile(File sourceFile, File destFile, String locationString, boolean afterLine, String checkString, boolean insertLinefeed) throws ActionFailedException
ActionFailedExceptionprotected void replaceString(String stringToInsert, File destFile, String stringToReplace) throws ActionFailedException
ActionFailedExceptionprotected void removeContents(File sourceFile, File destFile) throws ActionFailedException
ActionFailedExceptionprotected boolean doesFileContainString(File file, String checkString) throws ActionFailedException
ActionFailedExceptionprotected File getFile(String dir, String fname, boolean createDir, boolean createFile) throws ActionFailedException
dir - the parent directory.fname - the filename.createDir - whether the parent directory should be created.createFile - whether a new file should be created.Exception - if an error occurs.ActionFailedExceptionpublic void failed(Throwable t)
Actionperform method has executed.t - the error that occurred.public void stop()
Actionperform will return as soon as possible.
 This method should do nothing if this Action has already been stopped.
 
 This method will probably be invoked from within the Thread that created
 the ActionQueue that this Action is being executed in, rather than from
 within the Thread that is invoking the perform method
 (the ActionQueue's Action processing Thread).
 Because of this, clients implementing this interface should
 provide a way of canceling what is happening in the perform
 method when this stop method is invoked.
 
 Note: this is especially important when the perform method
       executes a tight loop or creates new Threads.
protected void parseArguments(String[] args)
public static void main(String[] args) throws ActionFailedException
ActionFailedExceptionCopyright © 2025. All rights reserved.