-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Feat: Add the ability to open linked pdf files in bib files #14275
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
base: main
Are you sure you want to change the base?
Changes from 19 commits
ab9b3f5
3d7c638
714e3c7
9a31138
93a8bad
b3cf132
13e1d1e
4956a86
8d07104
99b46cd
d618738
5b0aa66
8cfe32f
cc75b7a
08f90e5
6a26f18
2bb3f84
a1242d7
47f02c1
1105762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,13 @@ | |
| import java.nio.file.InvalidPathException; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.jabref.logic.util.URLUtil; | ||
| import org.jabref.model.entry.LinkedFile; | ||
| import org.jabref.model.util.Range; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
@@ -21,7 +24,7 @@ public class FileFieldParser { | |
|
|
||
| private boolean windowsPath; | ||
|
|
||
| public FileFieldParser(String value) { | ||
| private FileFieldParser(String value) { | ||
| if (value == null) { | ||
| this.value = null; | ||
| } else { | ||
|
|
@@ -46,11 +49,16 @@ public FileFieldParser(String value) { | |
| public static List<LinkedFile> parse(String value) { | ||
| // We need state to have a more clean code. Thus, we instantiate the class and then return the result | ||
| FileFieldParser fileFieldParser = new FileFieldParser(value); | ||
| return fileFieldParser.parse(); | ||
| return new ArrayList<>(fileFieldParser.parse().stream().map(LinkedFilePosition::linkedFile).toList()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To create a modifiable list, the usual way is with Also add to JavaDoc that the list is modifiable. However - why do you need the result be modifiable? I think, the caller should convert it to a modifiable list (I might be wrong here, did not check all the code, but only thought of parsing and that the parsed representation should be read-only, because the underlying thing does not change) |
||
| } | ||
|
|
||
| public List<LinkedFile> parse() { | ||
| List<LinkedFile> files = new ArrayList<>(); | ||
| public static Map<LinkedFile, Range> parseToPosition(String value) { | ||
| FileFieldParser fileFieldParser = new FileFieldParser(value); | ||
| return fileFieldParser.parse().stream().collect(HashMap::new, (map, position) -> map.put(position.linkedFile(), position.range()), HashMap::putAll); | ||
| } | ||
|
|
||
| private List<LinkedFilePosition> parse() { | ||
| List<LinkedFilePosition> files = new ArrayList<>(); | ||
|
|
||
| if ((value == null) || value.trim().isEmpty()) { | ||
| return files; | ||
|
|
@@ -59,7 +67,7 @@ public List<LinkedFile> parse() { | |
| if (LinkedFile.isOnlineLink(value.trim())) { | ||
| // needs to be modifiable | ||
| try { | ||
| return List.of(new LinkedFile(URLUtil.create(value), "")); | ||
| return List.of(new LinkedFilePosition(new LinkedFile(URLUtil.create(value), ""), new Range(0, value.length() - 1))); | ||
| } catch (MalformedURLException e) { | ||
| LOGGER.error("invalid url", e); | ||
| return files; | ||
|
|
@@ -72,6 +80,7 @@ public List<LinkedFile> parse() { | |
| resetDataStructuresForNextElement(); | ||
| boolean inXmlChar = false; | ||
| boolean escaped = false; | ||
| int startColumn = 0; | ||
|
|
||
| for (int i = 0; i < value.length(); i++) { | ||
| char c = value.charAt(i); | ||
|
|
@@ -114,7 +123,8 @@ public List<LinkedFile> parse() { | |
| } | ||
| } else if (!escaped && (c == ';') && !inXmlChar) { | ||
| linkedFileData.add(charactersOfCurrentElement.toString()); | ||
| files.add(convert(linkedFileData)); | ||
| files.add(new LinkedFilePosition(convert(linkedFileData), new Range(startColumn, i))); | ||
| startColumn = i + 1; | ||
|
|
||
| // next iteration | ||
| resetDataStructuresForNextElement(); | ||
|
|
@@ -127,7 +137,7 @@ public List<LinkedFile> parse() { | |
| linkedFileData.add(charactersOfCurrentElement.toString()); | ||
| } | ||
| if (!linkedFileData.isEmpty()) { | ||
| files.add(convert(linkedFileData)); | ||
| files.add(new LinkedFilePosition(convert(linkedFileData), new Range(startColumn, value.length() - 1))); | ||
| } | ||
| return files; | ||
| } | ||
|
|
@@ -193,4 +203,7 @@ static LinkedFile convert(List<String> entry) { | |
| entry.clear(); | ||
| return field; | ||
| } | ||
|
|
||
| private record LinkedFilePosition(LinkedFile linkedFile, Range range) { | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.