Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace LinkedFiles backslashes with forward slashes #3403

Merged
merged 6 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We fixed an issue where JabRef would freeze when trying to replace the original entry after a merge with new information from identifiers like DOI/ISBN etc. [3294](https://github.com/JabRef/jabref/issues/3294)
- We fixed an issue where JabRef would not show the translated content at some points, although there existed a translation
- We fixed an issue where editing in the source tab would override content of other entries [#3352](https://github.com/JabRef/jabref/issues/3352#issue-268580818)
- We fixed an issue where file links created under windows could not be opened on Linux/OSX [#3311](https://github.com/JabRef/jabref/issues/3311)
- We fixed several issues with the automatic linking of files in the entry editor where files were not found or not correctly saved in the bibtex source [#3346](https://github.com/JabRef/jabref/issues/3346)
- We fixed an issue where fetching entries from crossref that had no titles caused an error [#3376](https://github.com/JabRef/jabref/issues/3376)
- We fixed an issue where the same Java Look and Feel would be listed more than once in the Preferences. [#3391](https://github.com/JabRef/jabref/issues/3391)


### Removed


Expand Down
27 changes: 24 additions & 3 deletions src/main/java/org/jabref/model/entry/LinkedFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ public class LinkedFile implements Serializable {

public LinkedFile(String description, String link, String fileType) {
this.description.setValue(Objects.requireNonNull(description));
this.link.setValue(Objects.requireNonNull(link));

String fileLink = Objects.requireNonNull(link);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of adding the additional variable named fileLink here? Since Strings are immutable you can just keep using link directly below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or even shorter: setLink(Objects.requireNonNull(link)), which also removes a bit of code duplication.

if (!isOnlineLink(fileLink)) {
this.link.setValue(fileLink.replace("\\", "/"));
} else {
this.link.setValue(fileLink);
}

this.fileType.setValue(Objects.requireNonNull(fileType));
}

Expand Down Expand Up @@ -62,7 +69,11 @@ public String getLink() {
}

public void setLink(String link) {
this.link.setValue(link);
if (!isOnlineLink(link)) {
this.link.setValue(link.replace("\\", "/"));
} else {
this.link.setValue(link);
}
}

public Observable[] getObservables() {
Expand Down Expand Up @@ -106,6 +117,15 @@ private void readObject(ObjectInputStream in) throws IOException {
description = new SimpleStringProperty(in.readUTF());
}

/**
* Checks if the given String is an online link
* @param toCheck The String to check
* @return True if it starts with http://, https:// or contains www; false otherwise
*/
private boolean isOnlineLink(String toCheck) {
return toCheck.startsWith("http://") || toCheck.startsWith("https://") || toCheck.contains("www.");
}

@Override
public int hashCode() {
return Objects.hash(description.get(), link.get(), fileType.get());
Expand All @@ -125,7 +145,7 @@ public boolean isEmpty() {
}

public boolean isOnlineLink() {
return link.get().startsWith("http://") || link.get().startsWith("https://") || link.get().contains("www.");
return isOnlineLink(link.get());
}

public Optional<Path> findIn(BibDatabaseContext databaseContext, FileDirectoryPreferences fileDirectoryPreferences) {
Expand All @@ -141,4 +161,5 @@ public Optional<Path> findIn(List<Path> directories) {
return FileHelper.expandFilenameAsPath(link.get(), directories);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void testEncodeStringArray() {
@Test
public void testFileFieldWriterGetStringRepresentation() {
LinkedFile file = new LinkedFile("test", "X:\\Users\\abc.pdf", "PDF");
assertEquals("test:X\\:\\\\Users\\\\abc.pdf:PDF", FileFieldWriter.getStringRepresentation(file));
assertEquals("test:X\\:/Users/abc.pdf:PDF", FileFieldWriter.getStringRepresentation(file));
}


Expand Down