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

public Class LinkedFileHandler

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.file.Files, .Path, .StandardCopyOption, java.util.Optional, java.util.stream.Stream, org.jabref.logic.FilePreferences, org.jabref.logic.util.io.FileNameUniqueness, .FileUtil, org.jabref.logic.util.strings.StringUtil, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, .LinkedFile, org.jspecify.annotations.NonNull, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
LinkedFileHandler.GetTargetPathResult

If exists: the path already exists and has the same content as the given sourcePath

Field Summary

Modifier and TypeField and Description
private final BibDatabaseContext
private final BibEntry
private final FilePreferences
private final LinkedFile
private static final Logger

Constructor Summary

AccessConstructor and Description
public
LinkedFileHandler(LinkedFile linkedFile, BibEntry entry, @NonNull BibDatabaseContext databaseContext, @NonNull FilePreferences filePreferences)

Method Summary

Modifier and TypeMethod and Description
public boolean
copyOrMoveToDefaultDirectory(boolean shouldMove, boolean shouldRenameToFilenamePattern)

Returns: true if the file was copied/moved or the same file exists in the target directory

private boolean
copyOrMoveToExactDirectory(Path targetDirectory, boolean shouldMove, boolean shouldRenameToFilenamePattern)

public Optional<Path>

Returns:

First identified path that matches an existing file. This name can be used in subsequent calls to override the existing file.
findExistingFile
(LinkedFile linkedFile, BibEntry entry, String targetFileName)

Check to see if a file already exists in the target directory.

public String

Returns:

the suggested filename, including extension
getSuggestedFileName
()

Determines the suggested file name based on the pattern specified in the preferences and valid for the file system.

public String

Returns:

the suggested filename, including extension
getSuggestedFileName
(@NonNull String
The extension of the file.
extension
)

Determines the suggested file name based on the pattern specified in the preferences and valid for the file system.

private LinkedFileHandler.GetTargetPathResult
getTargetPath(Path sourcePath, Path targetDirectory, boolean useSuggestedName)

public boolean
public void
moveToExactDirectory(Path targetDirectory)

public boolean
renameToName(String targetFileName, boolean overwriteExistingFile)

public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databaseContextback to summary
private final BibDatabaseContext databaseContext
entryback to summary
private final BibEntry entry
filePreferencesback to summary
private final FilePreferences filePreferences
linkedFileback to summary
private final LinkedFile linkedFile
LOGGERback to summary
private static final Logger LOGGER

Constructor Detail

LinkedFileHandlerback to summary
public LinkedFileHandler(LinkedFile linkedFile, BibEntry entry, @NonNull BibDatabaseContext databaseContext, @NonNull FilePreferences filePreferences)

Method Detail

copyOrMoveToDefaultDirectoryback to summary
public boolean copyOrMoveToDefaultDirectory(boolean shouldMove, boolean shouldRenameToFilenamePattern) throws IOException
Returns:boolean

true if the file was copied/moved or the same file exists in the target directory

copyOrMoveToExactDirectoryback to summary
private boolean copyOrMoveToExactDirectory(Path targetDirectory, boolean shouldMove, boolean shouldRenameToFilenamePattern) throws IOException
findExistingFileback to summary
public Optional<Path> findExistingFile(LinkedFile linkedFile, BibEntry entry, String targetFileName)

Check to see if a file already exists in the target directory. Search is not case sensitive.

Returns:Optional<Path>

First identified path that matches an existing file. This name can be used in subsequent calls to override the existing file.

getSuggestedFileNameback to summary
public String getSuggestedFileName()

Determines the suggested file name based on the pattern specified in the preferences and valid for the file system. Uses file extension from original file.

Returns:String

the suggested filename, including extension

getSuggestedFileNameback to summary
public String getSuggestedFileName(@NonNull String extension)

Determines the suggested file name based on the pattern specified in the preferences and valid for the file system. Uses the provided file extension.

Parameters
extension:@NonNull String

The extension of the file.

Returns:String

the suggested filename, including extension

getTargetPathback to summary
private LinkedFileHandler.GetTargetPathResult getTargetPath(Path sourcePath, Path targetDirectory, boolean useSuggestedName) throws IOException
moveToDefaultDirectoryback to summary
public boolean moveToDefaultDirectory() throws IOException
moveToExactDirectoryback to summary
public void moveToExactDirectory(Path targetDirectory) throws IOException
renameToNameback to summary
public boolean renameToName(String targetFileName, boolean overwriteExistingFile) throws IOException
renameToSuggestedNameback to summary
public boolean renameToSuggestedName() throws IOException
org.jabref.logic.externalfiles back to summary

private final Record LinkedFileHandler.GetTargetPathResult

extends Record
Class Inheritance
Record Components
exists:boolean 
renamed:boolean
The original/suggested filename was adapted to fit it
path:Path 

If exists: the path already exists and has the same content as the given sourcePath

Field Summary

Modifier and TypeField and Description
private final boolean
exists

Record Component accessed by exists().

private final Path
path

Record Component accessed by path().

private final boolean
renamed

Record Component accessed by renamed().

The original/suggested filename was adapted to fit it

Constructor Summary

AccessConstructor and Description
private
GetTargetPathResult(boolean exists, boolean renamed, Path path)

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public boolean
exists()

Record Component getter of exists.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public Path
path()

Record Component getter of path.

public boolean
renamed()

Record Component getter of renamed.

Record Component The original/suggested filename was adapted to fit it

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

existsback to summary
private final boolean exists

Record Component accessed by exists().

pathback to summary
private final Path path

Record Component accessed by path().

renamedback to summary
private final boolean renamed

Record Component accessed by renamed().

The original/suggested filename was adapted to fit it

Constructor Detail

GetTargetPathResultback to summary
private GetTargetPathResult(boolean exists, boolean renamed, Path path)

Method Detail

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
existsback to summary
public boolean exists()

Record Component getter of exists.

hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

pathback to summary
public Path path()

Record Component getter of path.

renamedback to summary
public boolean renamed()

Record Component getter of renamed.

Record Component
The original/suggested filename was adapted to fit it
toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.