Verified Owner
Top Fields Constructors Methods
org.jabref.logic.util.io

pack-priv Class RegExpBasedFileFinder

extends Object
implements FileFinder
Class Inheritance
All Implemented Interfaces
org.jabref.logic.util.io.FileFinder
Imports
java.io.IOException, .UncheckedIOException, java.nio.file.FileVisitOption, .Files, .Path, java.nio.file.attribute.BasicFileAttributes, java.util.ArrayList, .Arrays, .List, .Optional, java.util.function.BiPredicate, .Function, java.util.regex.Matcher, .Pattern, .PatternSyntaxException, java.util.stream.Stream, org.jabref.logic.citationkeypattern.BracketedPattern, org.jabref.logic.util.strings.StringUtil, org.jabref.model.entry.BibEntry, .Month, org.jabref.model.entry.field.StandardField

Field Summary

Modifier and TypeField and Description
private static final Pattern
private static final Pattern
private static final String
private final Character
private final String

Constructor Summary

AccessConstructor and Description
pack-priv
RegExpBasedFileFinder(String
The expression deciding which names are acceptable.
regExp
,
Character keywordDelimiter)

Method Summary

Modifier and TypeMethod and Description
private Pattern
createFileNamePattern(String[] fileParts, String extensionRegExp, BibEntry entry)

Creates a Pattern that matches the file name corresponding to the last element of fileParts with any bracketed patterns expanded.

public List<Path>

Returns:

A list of files paths matching the given criteria.
findAssociatedFiles
(BibEntry
The entry to search for.
entry
,
List<Path>
The root directories to search.
directories
,
List<String>
The extensions that are acceptable.
extensions
)

Implements org.jabref.logic.util.io.FileFinder.findAssociatedFiles.

Method for searching for files using regexp.

private List<Path>

Returns:

Will return the first file found to match the given criteria or null if none was found.
findFile
(BibEntry
non-null
entry
,
List<Path>
A set of root directories to start the search from. Paths are returned relative to these directories if relative is set to true. These directories will not be expanded or anything. Use the file attribute for this.
dirs
,
String extensionRegExp)

Searches the given directory and filename pattern for a file for the BibTeX entry.

private List<Path>
findFile(final BibEntry entry, final Path directory, final String file, final String extensionRegExp)

The actual work-horse.

private List<String>

Returns:

date candidates in decreasing specificity, or an empty list if no date information is available
getDateFallbackCandidates
(BibEntry
the bibliography entry to extract date information from
entry
)

Builds date candidates for [DATE] pattern matching, ordered from most to least specific.

private boolean
isSubDirectory(Path rootDirectory, Path path)

private static String

Returns:

a String representation of a regex matching the expanded content and the expanded content cleaned for file name use
toFileNameRegex
(String
the expanded content of a bracketed expression
expandedContent
)

Helper method for both exact matching (if the file name were not created by JabRef) and cleaned file name matching.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DATE_MARKER_PATTERNback to summary
private static final Pattern DATE_MARKER_PATTERN
ESCAPE_PATTERNback to summary
private static final Pattern ESCAPE_PATTERN
EXT_MARKERback to summary
private static final String EXT_MARKER
keywordDelimiterback to summary
private final Character keywordDelimiter
regExpback to summary
private final String regExp

Constructor Detail

RegExpBasedFileFinderback to summary
pack-priv RegExpBasedFileFinder(String regExp, Character keywordDelimiter)
Parameters
regExp:String

The expression deciding which names are acceptable.

Method Detail

createFileNamePatternback to summary
private Pattern createFileNamePattern(String[] fileParts, String extensionRegExp, BibEntry entry) throws IOException

Creates a Pattern that matches the file name corresponding to the last element of fileParts with any bracketed patterns expanded.

Exceptions
IOException:
throws an IOException if a PatternSyntaxException occurs
findAssociatedFilesback to summary
public List<Path> findAssociatedFiles(BibEntry entry, List<Path> directories, List<String> extensions) throws IOException

Implements org.jabref.logic.util.io.FileFinder.findAssociatedFiles.

Method for searching for files using regexp. A list of extensions and directories can be given.

Parameters
entry:BibEntry

The entry to search for.

directories:List<Path>

The root directories to search.

extensions:List<String>

The extensions that are acceptable.

Returns:List<Path>

A list of files paths matching the given criteria.

Annotations
@Override
findFileback to summary
private List<Path> findFile(BibEntry entry, List<Path> dirs, String extensionRegExp) throws IOException

Searches the given directory and filename pattern for a file for the BibTeX entry.

Used to fix:

http://sourceforge.net/tracker/index.php?func=detail&aid=1503410&group_id=92314&atid=600309

Requirements:

  • Be able to find the associated PDF in a set of given directories.
  • Be able to return a relative path or absolute path.
  • Be fast.
  • Allow for flexible naming schemes in the PDFs.

Syntax scheme for file:

    • Any subDir
  • ** Any subDir (recursive)
  • key Key from BibTeX file and database
  • .* Anything else is taken to be a Regular expression.
Parameters
entry:BibEntry

non-null

dirs:List<Path>

A set of root directories to start the search from. Paths are returned relative to these directories if relative is set to true. These directories will not be expanded or anything. Use the file attribute for this.

Returns:List<Path>

Will return the first file found to match the given criteria or null if none was found.

findFileback to summary
private List<Path> findFile(final BibEntry entry, final Path directory, final String file, final String extensionRegExp) throws IOException

The actual work-horse. Will find absolute filepaths starting from the given directory using the given regular expression string for search.

getDateFallbackCandidatesback to summary
private List<String> getDateFallbackCandidates(BibEntry entry)

Builds date candidates for [DATE] pattern matching, ordered from most to least specific.

Uses the date field if present. Otherwise, constructs a date from the year, month, and day fields. BibTeX month strings (e.g., #jul#) are normalized to two-digit numbers via Month#parse(String).

For example, a date of 2021-07-07 produces ["2021-07-07", "2021-07", "2021"].

Parameters
entry:BibEntry

the bibliography entry to extract date information from

Returns:List<String>

date candidates in decreasing specificity, or an empty list if no date information is available

isSubDirectoryback to summary
private boolean isSubDirectory(Path rootDirectory, Path path)
toFileNameRegexback to summary
private static String toFileNameRegex(String expandedContent)

Helper method for both exact matching (if the file name were not created by JabRef) and cleaned file name matching.

Parameters
expandedContent:String

the expanded content of a bracketed expression

Returns:String

a String representation of a regex matching the expanded content and the expanded content cleaned for file name use