Verified Owner
Top Inners Fields Constructors Methods
org.jabref.gui.externalfiles

public Class AutoSetFileLinksUtil

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.file.Files, .Path, java.util.ArrayList, .Collection, .HashMap, .HashSet, .List, .Map, .Objects, .Optional, .Set, java.util.function.BiConsumer, java.util.stream.Collectors, .Stream, org.jabref.gui.externalfiletype.ExternalFileType, .ExternalFileTypes, org.jabref.gui.frame.ExternalApplicationsPreferences, org.jabref.logic.FilePreferences, org.jabref.logic.bibtex.FileFieldWriter, org.jabref.logic.util.io.AutoLinkPreferences, .FileFinder, .FileFinders, .FileUtil, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, .LinkedFile, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final AutoLinkPreferences
private final FileFinder
private final List<Path>
private final ExternalApplicationsPreferences
private static final Logger
private final FileFinder

Constructor Summary

AccessConstructor and Description
public
AutoSetFileLinksUtil(BibDatabaseContext databaseContext, ExternalApplicationsPreferences externalApplicationsPreferences, FilePreferences filePreferences, AutoLinkPreferences autoLinkPreferences)

private
AutoSetFileLinksUtil(List<Path> directories, ExternalApplicationsPreferences externalApplicationsPreferences, AutoLinkPreferences autoLinkPreferences)

Method Summary

Modifier and TypeMethod and Description
private List<LinkedFile>
private LinkedFile
buildLinkedFileFromPath(Path associatedFile)

private String
checkAndGetFileType(Path associatedFile)

private void
doLinkAssociatedFiles(BibEntry entry, BiConsumer<List<LinkedFile>, BibEntry> onAddLinkedFile, AutoSetFileLinksUtil.LinkFilesResult result)

Source of associated not linked files:

  • Part A. match file name with CitationKey, (START, EXACT, REGEX) configured by user
  • Part B. match file name with broken linked file names, currently silently happen
private boolean
filesChanged(List<LinkedFile> newLinkedFiles, List<LinkedFile> files)

public Collection<LinkedFile>
findAssociatedNotLinkedFiles(BibEntry entry)

Scans for missing files which should be linked to the given entry.

public Collection<LinkedFile>
private Map<String, LinkedFile>
private Map<String, LinkedFile>
private List<String>
private boolean
private static boolean
isFileAlreadyLinked(Path foundFile, List<Path> linkedFiles)

public AutoSetFileLinksUtil.LinkFilesResult
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

autoLinkPreferencesback to summary
private final AutoLinkPreferences autoLinkPreferences
brokenLinkedFileNameBasedFileFinderback to summary
private final FileFinder brokenLinkedFileNameBasedFileFinder
directoriesback to summary
private final List<Path> directories
externalApplicationsPreferencesback to summary
private final ExternalApplicationsPreferences externalApplicationsPreferences
LOGGERback to summary
private static final Logger LOGGER
preConfiguredFileFinderback to summary
private final FileFinder preConfiguredFileFinder

Constructor Detail

AutoSetFileLinksUtilback to summary
public AutoSetFileLinksUtil(BibDatabaseContext databaseContext, ExternalApplicationsPreferences externalApplicationsPreferences, FilePreferences filePreferences, AutoLinkPreferences autoLinkPreferences)
AutoSetFileLinksUtilback to summary
private AutoSetFileLinksUtil(List<Path> directories, ExternalApplicationsPreferences externalApplicationsPreferences, AutoLinkPreferences autoLinkPreferences)

Method Detail

autoLinkBrokenLinkedFilesback to summary
private List<LinkedFile> autoLinkBrokenLinkedFiles(List<LinkedFile> linkedFiles, Map<String, LinkedFile> files)
buildLinkedFileFromPathback to summary
private LinkedFile buildLinkedFileFromPath(Path associatedFile)
checkAndGetFileTypeback to summary
private String checkAndGetFileType(Path associatedFile)
doLinkAssociatedFilesback to summary
private void doLinkAssociatedFiles(BibEntry entry, BiConsumer<List<LinkedFile>, BibEntry> onAddLinkedFile, AutoSetFileLinksUtil.LinkFilesResult result)

Source of associated not linked files:

  • Part A. match file name with CitationKey, (START, EXACT, REGEX) configured by user
  • Part B. match file name with broken linked file names, currently silently happen

The auto-link process:

  • Prolog: we only consider the file with a unique name
    • if a file's name is found multiple times in Part A, we do not consider it in Step 1
    • if a file's name is found multiple times in Part B, we do not consider it in Step 2
  • Step 1. try to auto link each broken linked file with Part A at first. For unlinked files left in Part A, if no linked file with same name exists, add them
    • why add: Part A are found mainly by CitationKey, which has strong connection to the entry, so we are confident that we should add them automatically
  • Step 2. try to auto link each broken linked file with Part B.
    • how about unlinked files left in Part B: those files have the same name with one broken linked file but different extension. We skip those files.
    • one trick: we accumulate Part B after Step 1, so Part A does not affect those broken linked files we use to query Part B
filesChangedback to summary
private boolean filesChanged(List<LinkedFile> newLinkedFiles, List<LinkedFile> files)
findAssociatedNotLinkedFilesback to summary
public Collection<LinkedFile> findAssociatedNotLinkedFiles(BibEntry entry) throws IOException

Scans for missing files which should be linked to the given entry.

Related: org.jabref.gui.externalfiles.UnlinkedFilesCrawler for scanning files missing at all entries

NOTE:

  1. This method does not check if the file is already linked to another entry.
  2. This method does not guarantee how the returned files are ordered. Order by how they appear in BibEntry does not work since findAssociatedFilesByBrokenLinkedFile may return multiple files (with the same name) for one broken linked file in the entry.
findAssociatedNotLinkedFilesWithFinderback to summary
public Collection<LinkedFile> findAssociatedNotLinkedFilesWithFinder(BibEntry entry, FileFinder finder, List<String> extensions) throws IOException
findAssociatedNotLinkedFilesWithUniqueNameback to summary
private Map<String, LinkedFile> findAssociatedNotLinkedFilesWithUniqueName(BibEntry entry, FileFinder finder) throws IOException
getAssociatedFilesback to summary
private Map<String, LinkedFile> getAssociatedFiles(BibEntry entry, AutoSetFileLinksUtil.LinkFilesResult result, FileFinder finder)
getConfiguredExtensionsback to summary
private List<String> getConfiguredExtensions()
isBrokenLinkedFileback to summary
private boolean isBrokenLinkedFile(LinkedFile file)
isFileAlreadyLinkedback to summary
private static boolean isFileAlreadyLinked(Path foundFile, List<Path> linkedFiles)
linkAssociatedFilesback to summary
public AutoSetFileLinksUtil.LinkFilesResult linkAssociatedFiles(List<BibEntry> entries, BiConsumer<List<LinkedFile>, BibEntry> onAddLinkedFile)

impl->req~logic.externalfiles.file-transfer.auto-link~1

org.jabref.gui.externalfiles back to summary

public Class AutoSetFileLinksUtil.LinkFilesResult

extends Object
Class Inheritance
  • java.lang.Object
  • org.jabref.gui.externalfiles.AutoSetFileLinksUtil.LinkFilesResult

Field Summary

Modifier and TypeField and Description
private final List<BibEntry>
private final List<IOException>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
public List<BibEntry>
public List<IOException>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

changedEntriesback to summary
private final List<BibEntry> changedEntries
fileExceptionsback to summary
private final List<IOException> fileExceptions

Constructor Detail

LinkFilesResultback to summary
public LinkFilesResult()

Method Detail

addBibEntryback to summary
protected void addBibEntry(BibEntry bibEntry)
addFileExceptionback to summary
protected void addFileException(IOException exception)
getChangedEntriesback to summary
public List<BibEntry> getChangedEntries()
getFileExceptionsback to summary
public List<IOException> getFileExceptions()