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

Parse pasted ISBNs on maintable #9865

Merged
merged 5 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -22,6 +22,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We enabled scrolling in the groups list when dragging a group on another group. [#2869](https://github.com/JabRef/jabref/pull/2869)
- We added the option to automatically download online files when a new entry is created from an existing ID (e.g. DOI). The option can be disabled in the preferences under "Import and Export" [#9756](https://github.com/JabRef/jabref/issues/9756)
- We added a new Integrity check for unscaped ampersands. [koppor#585](https://github.com/koppor/jabref/issues/585)
- We added the possibility to automatically fetch entries when an IBSN is pasted on the main table [#9864](https://github.com/JabRef/jabref/issues/9864)

### Changed

Expand All @@ -46,6 +47,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We changed the handling of an "overflow" of authors at `[authIniN]`: JabRef uses `+` to indicate an overflow. Example: `[authIni2]` produces `A+` (instead of `AB`) for `Aachen and Berlin and Chemnitz`. [#9703](https://github.com/JabRef/jabref/pull/9703)
- We moved the preferences option to open the last edited files on startup to the 'General' tab. [#9808](https://github.com/JabRef/jabref/pull/9808)
- We split the 'Import and Export' tab into 'Web Search' and 'Export'. [#9839](https://github.com/JabRef/jabref/pull/9839)
- We improved the recognition of DOIs when pasting a link containing a DOI on the maintable [#9864](https://github.com/JabRef/jabref/issues/9864s)

### Fixed

Expand Down
18 changes: 16 additions & 2 deletions src/main/java/org/jabref/gui/externalfiles/ImportHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.fetcher.ArXivFetcher;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.importer.fetcher.isbntobibtex.IsbnFetcher;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.util.UpdateField;
Expand All @@ -44,6 +45,7 @@
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.identifier.ArXivIdentifier;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.entry.identifier.ISBN;
import org.jabref.model.groups.GroupEntryChanger;
import org.jabref.model.groups.GroupTreeNode;
import org.jabref.model.util.FileUpdateMonitor;
Expand Down Expand Up @@ -289,15 +291,21 @@ public List<BibEntry> handleStringData(String data) throws FetcherException {
return Collections.emptyList();
}

Optional<DOI> doi = DOI.parse(data);
Optional<DOI> doi = DOI.findInText(data);
if (doi.isPresent()) {
return fetchByDOI(doi.get());
}

Optional<ArXivIdentifier> arXiv = ArXivIdentifier.parse(data);
if (arXiv.isPresent()) {
return fetchByArXiv(arXiv.get());
}

Optional<ISBN> isbn = ISBN.parse(data);
if (isbn.isPresent()) {
return fetchByISBN(isbn.get());
}

return tryImportFormats(data);
}

Expand All @@ -312,7 +320,7 @@ private List<BibEntry> tryImportFormats(String data) {
}

private List<BibEntry> fetchByDOI(DOI doi) throws FetcherException {
LOGGER.info("Found DOI in clipboard");
LOGGER.info("Found DOI identifer in clipboard");
Optional<BibEntry> entry = new DoiFetcher(preferencesService.getImportFormatPreferences()).performSearchById(doi.getDOI());
return OptionalUtil.toList(entry);
}
Expand All @@ -322,4 +330,10 @@ private List<BibEntry> fetchByArXiv(ArXivIdentifier arXivIdentifier) throws Fetc
Optional<BibEntry> entry = new ArXivFetcher(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion());
return OptionalUtil.toList(entry);
}

private List<BibEntry> fetchByISBN(ISBN isbn) throws FetcherException {
LOGGER.info("Found ISBN identifier in clipboard");
Optional<BibEntry> entry = new IsbnFetcher(preferencesService.getImportFormatPreferences()).performSearchById(isbn.getNormalized());
return OptionalUtil.toList(entry);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2542,4 +2542,4 @@ Delete\ %0\ files\ permanently\ from\ disk,\ or\ just\ remove\ the\ files\ from\
Error\ accessing\ file\ '%0'.=Error accessing file '%0'.
This\ operation\ requires\ selected\ linked\ files.=This operation requires selected linked files.

Create\ backup=Create backup
Create\ backup=Create backup