This formatter can take an optional second argument specifying the name of a file type. If specified, the iteration will only include those files with a file type matching the given name (case-insensitively). If specified as an empty argument, all file links will be included.
After the second argument, pairs of additional arguments can be added in order to specify regular expression replacements to be done upon the inserted link information before insertion into the output string. A non-paired argument will be ignored. In order to specify replacements without filtering on file types, use an empty second argument.
The escape sequences for embedding information are as follows:
\i : This inserts the iteration index (starting from 1), and can be useful if the output list of files should be enumerated. \p : This inserts the file path of the file link. Relative links below your file directory will be expanded to their absolute path. \r : This inserts the file path without expanding relative links. \f : This inserts the name of the file link's type. \x : This inserts the file's extension, if any. \d : This inserts the file link's description, if any.
For instance, an entry could contain a file link to the file "/home/john/report.pdf" of the "PDF" type with description "John's final report".
Using the WrapFileLinks formatter with the following argument:
\format[WrapFileLinks(\i. \d (\p))]{\file}
would give the following output: 1. John's final report (/home/john/report.pdf)
If the entry contained a second file link to the file "/home/john/draft.txt" of the "Text file" type with description 'An early "draft"', the output would be as follows: 1. John's final report (/home/john/report.pdf) 2. An early "draft" (/home/john/draft.txt)
If the formatter was called with a second argument, the list would be filtered. For instance: \format[WrapFileLinks(\i. \d (\p),text file)]{\file}
would show only the text file: 1. An early "draft" (/home/john/draft.txt)
If we wanted this output to be part of an XML styled output, the quotes in the file description could cause problems. Adding two additional arguments to translate the quotes into XML characters solves this: \format[WrapFileLinks(\i. \d (\p),text file,",")]{\file}
would give the following output: 1. An early "draft" (/home/john/draft.txt)
Additional pairs of replacements can be added.
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | WrapFileLinks.
This class defines the building blocks of a parsed format strings. |
| Modifier and Type | Field and Description |
|---|---|
| private static final Map | |
| private static final int | |
| private static final int | |
| private static final int | |
| private static final int | |
| private final List | |
| private String | |
| private List | |
| private static final int | |
| private final String | |
| private static final int | |
| private final Map | |
| private static final int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | format(String
The text to layout. field)Implements org. Failure Mode: Formatters should be robust in the sense that they always return some relevant string. |
| private static List | Returns: the resulting format entries.The marked-up string. format)Parse a format string and return a list of FormatEntry objects. |
| private String | |
| public void | setArgument(String
A String argument. arg)Implements org. Method for setting the argument of this formatter. |
| ESCAPE_SEQ | back to summary |
|---|---|
| private static final Map<Character, Integer> ESCAPE_SEQ | |
| FILE_DESCRIPTION | back to summary |
|---|---|
| private static final int FILE_DESCRIPTION | |
| FILE_EXTENSION | back to summary |
|---|---|
| private static final int FILE_EXTENSION | |
| FILE_PATH | back to summary |
|---|---|
| private static final int FILE_PATH | |
| FILE_TYPE | back to summary |
|---|---|
| private static final int FILE_TYPE | |
| fileDirectories | back to summary |
|---|---|
| private final List<Path> fileDirectories | |
| fileType | back to summary |
|---|---|
| private String fileType | |
| format | back to summary |
|---|---|
| private List<WrapFileLinks. | |
| ITERATION_COUNT | back to summary |
|---|---|
| private static final int ITERATION_COUNT | |
| mainFileDirectory | back to summary |
|---|---|
| private final String mainFileDirectory | |
| RELATIVE_FILE_PATH | back to summary |
|---|---|
| private static final int RELATIVE_FILE_PATH | |
| replacements | back to summary |
|---|---|
| private final Map<String, String> replacements | |
| STRING | back to summary |
|---|---|
| private static final int STRING | |
| WrapFileLinks | back to summary |
|---|---|
| public WrapFileLinks(List<Path> fileDirectories, String mainFileDirectory) | |
| format | back to summary |
|---|---|
| public String format(String field) Implements org. Doc from org. Failure Mode: Formatters should be robust in the sense that they always return some relevant string. If the formatter can detect an invalid input it should return the original string otherwise it may simply return a wrong output. | |
| parseFormatString | back to summary |
|---|---|
| private static List Parse a format string and return a list of FormatEntry objects. The format string is basically marked up with "\i" marking that the iteration number should be inserted, and with "\p" marking that the file path of the current iteration should be inserted, plus additional markers.
| |
| replaceStrings | back to summary |
|---|---|
| private String replaceStrings(String text) | |
| setArgument | back to summary |
|---|---|
| public void setArgument(String arg) Implements org. Doc from org. Method for setting the argument of this formatter. | |
| Access | Constructor and Description |
|---|---|
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| public String | |
| public int |
| FormatEntry | back to summary |
|---|---|
| public FormatEntry(int type) | |
| FormatEntry | back to summary |
|---|---|
| public FormatEntry(String value) | |
| getString | back to summary |
|---|---|
| public String getString() | |
| getType | back to summary |
|---|---|
| public int getType() | |