# Actions: Text

install4j BeanInfo catalog. Each entry below documents a bean class that can appear inside a `<serializedBean>` element in an install4j project file.

## Contents

- [Fix line feeds](#fix-line-feeds) — `com.install4j.runtime.beans.actions.text.FixCrLfAction`
- [Modify text files](#modify-text-files) — `com.install4j.runtime.beans.actions.text.ModifyTextFileAction`
- [Modify text files with regular expressions](#modify-text-files-with-regular-expressions) — `com.install4j.runtime.beans.actions.text.RegexTextFileAction`
- [Read text from file](#read-text-from-file) — `com.install4j.runtime.beans.actions.text.ReadTextFromFileAction`
- [Replace installer variables in text files](#replace-installer-variables-in-text-files) — `com.install4j.runtime.beans.actions.text.ReplaceInstallerVariablesAction`
- [Write text to a file](#write-text-to-a-file) — `com.install4j.runtime.beans.actions.text.WriteTextFileAction`

---

### Fix line feeds
- **Class:** `com.install4j.runtime.beans.actions.text.FixCrLfAction`
- **Category:** Text files
- **Multiple instances:** yes

Changes the line feeds of text files to the platform-specific type.

| Property | Type | Category | Visible when | Description |
|---|---|---|---|---|
| `files` — Text files | File[] | Configuration | — | The text files that should be fixed. In the edit dialog you can choose files from the distribution tree or enter them manually. Text files that are installer variables with array or collection values (e.g. String[], Object[] or List<File>) are expanded as separate text files, this allows you to build a variable length list of text files at runtime. You can add directories as well. In this case, all files in the selected directories that satisfy the "Suffixes" property will be fixed. |
| `suffixes` — Suffixes | String[] | Configuration | — | The suffixes with a leading dot of the files to be fixed if the "File" property is a directory. If empty, all files will be used. In the edit dialog, you have to enter one item per line. Suffixes that are installer variables with array or collection values (e.g. String[], Object[] or List<File>) are expanded as separate suffixes, this allows you to build a variable length list of suffixes at runtime. |
| `recursive` — Recursive | boolean | Configuration | — | If selected, the operation will be performed recursively on directories. If no selected, all files in directories will be fixed, but subdirectories will not be touched. |

### Modify text files
- **Class:** `com.install4j.runtime.beans.actions.text.ModifyTextFileAction`
- **Category:** Text files
- **Multiple instances:** yes
- **Installed files required:** yes

Modify installed text files by replacing a search value in the selected files. This action does not read the entire file into memory and can work on arbitrarily large text files.

| Property | Type | Category | Visible when | Description |
|---|---|---|---|---|
| `files` — Text files | File[] | Configuration | — | The text files that should be modified. In the edit dialog you can choose files from the distribution tree or enter them manually. Text files that are installer variables with array or collection values (e.g. String[], Object[] or List<File>) are expanded as separate text files, this allows you to build a variable length list of text files at runtime. |
| `searchValue` — Search value | String | Configuration | — | The value that should be searched |
| `replaceValue` — Replace value | String [context=multiline] | Configuration | — | The value that should be used instead |
| `logReplacement` — Log replacement | boolean | Configuration | — | If the replacement text should be written into the log file or not. If the modified file has different security settings than the log file, you might want to disable this property for security reasons. |
| `failIfNoReplacement` — Fail if no replacement occurred | boolean | Configuration | — | If selected, the action will fail if no replacement was performed by the action. Note that you have to set the error message property to display the error to the user. |
| `escapeForPropertyFile` — Escape for property file | boolean | Configuration | — | If set, the replaced values will be escaped for use in a Java property file. |
| `encoding` — Encoding | String | Configuration | — | The encoding of the file. If you leave this empty, the system default will be used. Common encodings are UTF-8, UTF-16, ISO-8859-1. |

### Modify text files with regular expressions
- **Class:** `com.install4j.runtime.beans.actions.text.RegexTextFileAction`
- **Category:** Text files
- **Multiple instances:** yes
- **Installed files required:** yes

Modify installed text files by applying a regular expression.

| Property | Type | Category | Visible when | Description |
|---|---|---|---|---|
| `files` — Text files | File[] | Configuration | — | The text files that should be modified. In the edit dialog you can choose files from the distribution tree or enter them manually. Text files that are installer variables with array or collection values (e.g. String[], Object[] or List<File>) are expanded as separate text files, this allows you to build a variable length list of text files at runtime. |
| `regex` — Match expression | String | Configuration | — | The match expression, which is applied to the entire contents of the file. If you wish to use the characters ^ and $ for matching line start and line end, please prefix the expression with (?m). This switches on multi-line mode. For case-insensitive expressions, prefix with (?i). |
| `replacement` — Replacement | String [context=multiline] | Configuration | — | The replacement. |
| `replaceAll` — Replace all | boolean | Configuration | — | If all occurrences should be replaced or only the first one. |
| `quoteVariables` — Quote variables | boolean | Configuration | — | If values of installer variables in the match and replacement expressions should be quoted. This means that the characters of replaced installer variables will be treated literally instead of modifying the search or replace expressions with special characters such as \\ or $. |
| `logReplacement` — Log replacement | boolean | Configuration | — | If the replacement text should be written into the log file or not. If the modified file has different security settings than the log file, you might want to disable this property for security reasons. |
| `failIfNoReplacement` — Fail if no replacement occurred | boolean | Configuration | — | If selected, the action will fail if no replacement was performed by the action. Note that you have to set the error message property to display the error to the user. |
| `escapeForPropertyFile` — Escape for property file | boolean | Configuration | — | If set, the replaced values will be escaped for use in a Java property file. |
| `encoding` — Encoding | String | Configuration | — | The encoding of the file. If you leave this empty, the system default will be used. Common encodings are UTF-8, UTF-16, ISO-8859-1. |

### Read text from file
- **Class:** `com.install4j.runtime.beans.actions.text.ReadTextFromFileAction`
- **Category:** Text files
- **Multiple instances:** yes

Read the content of a text file and save it to an installer variable. The variable value will be of type String.

| Property | Type | Category | Visible when | Description |
|---|---|---|---|---|
| `file` — File | File | Configuration | — | The file from which the text should be read. If the file does not exist, the variable value will not be set. |
| `encoding` — File encoding | String | Configuration | — | The character set name as recognized by java.nio.Charset.forName(...). Values supported by all JREs include "US-ASCII" "ISO-8859-1", "UTF-8" and "UTF-16". If empty, the native encoding of the runtime platform will be used. |
| `variableName` — Variable name | String [context=variableName] | Configuration | — | The name of the variable whose value will be set to the text content of the file. If the file cannot be found, the variable value will not be set. |
| `saveAsArray` — Save as string array | boolean | Configuration | — | If selected, the text will be split into separate lines and saved as a value of type String[]. |

### Replace installer variables in text files
- **Class:** `com.install4j.runtime.beans.actions.text.ReplaceInstallerVariablesAction`
- **Category:** Text files
- **Multiple instances:** yes
- **Installed files required:** yes

Modify installed text files by replacing all occurrences of installer variables of the form ${installer:myVariable} with their current values. The action also replaces i18n variables like ${i18n;myKey} and compiler variables like ${compiler:myCompilerVariable}

| Property | Type | Category | Visible when | Description |
|---|---|---|---|---|
| `files` — Text files | File[] | Configuration | — | The text files that should be modified. In the edit dialog you can choose files from the distribution tree or enter them manually. Text files that are installer variables with array or collection values (e.g. String[], Object[] or List<File>) are expanded as separate text files, this allows you to build a variable length list of text files at runtime. |
| `ignoreMissing` — Ignore missing variables | boolean | Configuration | — | If selected, all missing occurrences of variables will be left as they are. If unselected, a missing variable will be a fatal error leading to the termination of the installer. |
| `failIfNoReplacement` — Fail if no replacement occurred | boolean | Configuration | — | If selected, the action will fail if no replacement was performed by the action. Note that you have to set the error message property to display the error to the user. |
| `escapeForPropertyFile` — Escape for property file | boolean | Configuration | — | If set, the replaced values will be escaped for use in a Java property file. |
| `encoding` — Encoding | String | Configuration | — | The encoding of the file. If you leave this empty, the system default will be used. Common encodings are UTF-8, UTF-16, ISO-8859-1. |

### Write text to a file
- **Class:** `com.install4j.runtime.beans.actions.text.WriteTextFileAction`
- **Category:** Text files
- **Multiple instances:** yes
- **Installed files required:** yes

Write text to a new file or append text to an existing file.

| Property | Type | Category | Visible when | Description |
|---|---|---|---|---|
| `file` — File | File | Configuration | — | The file that the text should be appended to. If it doesn't exist it will be created. |
| `text` — Text | String [context=multiline] | Configuration | — | The text that should be appended. |
| `encoding` — Encoding | String | Configuration | — | The encoding of the file. If you leave this empty the system default will be used. |
| `escaped` — Escaped text | boolean | Configuration | — | If selected, escape sequences like \\n,\\t or \\u1234 in the text property will be replaced. |
| `append` — Append | boolean | Configuration | — | If selected, and the file exists, the text will be appended to the existing file. If the file does not exist, it will be created in any case. |
| `logText` — Log text | boolean | Configuration | — | If the text should be written into the log file or not. If the written file has different security settings than the log file, you might want to disable this property for security reasons. |

