Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.layout.format

public Class WrapFileLinks

extends AbstractParamLayoutFormatter
Class Inheritance
Imports
java.nio.file.Path, java.util.ArrayList, .HashMap, .List, .Map, org.jabref.logic.importer.util.FileFieldParser, org.jabref.logic.layout.AbstractParamLayoutFormatter, org.jabref.logic.util.io.FileUtil, org.jabref.model.entry.LinkedFile

This formatter iterates over all file links, or all file links of a specified type, outputting a format string given as the first argument. The format string can contain a number of escape sequences indicating file link information to be inserted into the string.

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:

ormat[WrapFileLinks(\i. \d (\p))]{ ile}
\format[WrapFileLinks(\i. \d (\p))]{\file}

would give the following output:

1. John's final report (/home/john/report.pdf)
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)
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:

ormat[WrapFileLinks(\i. \d (\p),text file)]{ ile}
\format[WrapFileLinks(\i. \d (\p),text file)]{\file}

would show only the text file:

1. An early "draft" (/home/john/draft.txt)
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:

ormat[WrapFileLinks(\i. \d (\p),text file,",")]{ ile}
\format[WrapFileLinks(\i. \d (\p),text file,",")]{\file}

would give the following output:

1. An early "draft" (/home/john/draft.txt)
1. An early "draft" (/home/john/draft.txt)

Additional pairs of replacements can be added.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
WrapFileLinks.FormatEntry

This class defines the building blocks of a parsed format strings.

Field Summary

Modifier and TypeField and Description
private static final Map<Character, Integer>
private static final int
private static final int
private static final int
private static final int
private final List<Path>
private String
private List<WrapFileLinks.FormatEntry>
private static final int
private final Path
private static final int
private final Map<String, String>
private static final int

Constructor Summary

AccessConstructor and Description

Method Summary

Modifier and TypeMethod and Description
public String
format(String field)

Implements org.jabref.logic.layout.LayoutFormatter.format.

Failure Mode:

Formatters should be robust in the sense that they always return some relevant string.

private static List<WrapFileLinks.FormatEntry>

Returns:

the resulting format entries.
parseFormatString
(String
The marked-up string.
format
)

Parse a format string and return a list of FormatEntry objects.

private String
public void
setArgument(String arg)

Implements org.jabref.logic.layout.ParamLayoutFormatter.setArgument.

Method for setting the argument of this formatter.

Inherited from org.jabref.logic.layout.AbstractParamLayoutFormatter:
parseArgument

Field Detail

ESCAPE_SEQback to summary
private static final Map<Character, Integer> ESCAPE_SEQ
FILE_DESCRIPTIONback to summary
private static final int FILE_DESCRIPTION
FILE_EXTENSIONback to summary
private static final int FILE_EXTENSION
FILE_PATHback to summary
private static final int FILE_PATH
FILE_TYPEback to summary
private static final int FILE_TYPE
fileDirectoriesback to summary
private final List<Path> fileDirectories
fileTypeback to summary
private String fileType
formatback to summary
private List<WrapFileLinks.FormatEntry> format
ITERATION_COUNTback to summary
private static final int ITERATION_COUNT
mainFileDirectoryback to summary
private final Path mainFileDirectory
RELATIVE_FILE_PATHback to summary
private static final int RELATIVE_FILE_PATH
replacementsback to summary
private final Map<String, String> replacements
STRINGback to summary
private static final int STRING

Constructor Detail

Method Detail

formatback to summary
public String format(String field)

Implements org.jabref.logic.layout.LayoutFormatter.format.

Doc from org.jabref.logic.layout.LayoutFormatter.format.

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.

Annotations
@Override
parseFormatStringback to summary
private static List<WrapFileLinks.FormatEntry> parseFormatString(String format)

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.

Parameters
format:String

The marked-up string.

Returns:List<WrapFileLinks.FormatEntry>

the resulting format entries.

replaceStringsback to summary
private String replaceStrings(String text)
setArgumentback to summary
public void setArgument(String arg)

Implements org.jabref.logic.layout.ParamLayoutFormatter.setArgument.

Doc from org.jabref.logic.layout.ParamLayoutFormatter.setArgument.

Method for setting the argument of this formatter.

Annotations
@Override
org.jabref.logic.layout.format back to summary

pack-priv Class WrapFileLinks.FormatEntry

extends Object
Class Inheritance

This class defines the building blocks of a parsed format strings. Each FormatEntry represents either a literal string or a piece of information pertaining to the file link to be exported or to the iteration through a series of file links. For literal strings this class encapsulates the literal itself, while for other types of information, only a type code is provided, and the subclass needs to fill in the proper information based on the file link to be exported or the iteration status.

Field Summary

Modifier and TypeField and Description
private String
private final int

Constructor Summary

AccessConstructor and Description
public
FormatEntry(int type)

public

Method Summary

Modifier and TypeMethod and Description
public String
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

stringback to summary
private String string
typeback to summary
private final int type

Constructor Detail

FormatEntryback to summary
public FormatEntry(int type)
FormatEntryback to summary
public FormatEntry(String value)

Method Detail

getStringback to summary
public String getString()
getTypeback to summary
public int getType()