Skip to content

Commit

Permalink
add ability to insert arxivId (JabRef#7549)
Browse files Browse the repository at this point in the history
* add ability to insert arxivId

* modify change log

* fix checkstyle
  • Loading branch information
Ali96kz authored Mar 18, 2021
1 parent 303018f commit f1d3003
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added keybindings for setting and clearing the read status. [#7264](https://github.com/JabRef/jabref/issues/7264)
- We added two new fields to track the creation and most recent modification date and time for each entry. [koppor#130](https://github.com/koppor/jabref/issues/130)
- We added a feature that allows the user to copy highlighted text in the preview window. [#6962](https://github.com/JabRef/jabref/issues/6962)
- We added a feature that allows you to create new BibEntry via paste arxivId [#2292](https://github.com/JabRef/jabref/issues/2292)

### Changed

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/jabref/gui/ClipBoardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
import org.jabref.logic.importer.ImportFormatReader;
import org.jabref.logic.importer.ImportFormatReader.UnknownFormatImport;
import org.jabref.logic.importer.ParseException;
import org.jabref.logic.importer.fetcher.ArXiv;
import org.jabref.logic.importer.fetcher.DoiFetcher;
import org.jabref.logic.importer.fileformat.BibtexParser;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.identifier.ArXivIdentifier;
import org.jabref.model.entry.identifier.DOI;
import org.jabref.model.util.OptionalUtil;
import org.jabref.preferences.PreferencesService;
Expand Down Expand Up @@ -194,6 +196,10 @@ private List<BibEntry> handleStringData(String data) {
if (doi.isPresent()) {
return fetchByDOI(doi.get());
}
Optional<ArXivIdentifier> arXiv = ArXivIdentifier.parse(data);
if (arXiv.isPresent()) {
return fetchByArXiv(arXiv.get());
}

return tryImportFormats(data);
}
Expand All @@ -217,4 +223,15 @@ private List<BibEntry> fetchByDOI(DOI doi) {
return Collections.emptyList();
}
}

private List<BibEntry> fetchByArXiv(ArXivIdentifier arXivIdentifier) {
LOGGER.info("Found arxiv identifier in clipboard");
try {
Optional<BibEntry> entry = new ArXiv(preferencesService.getImportFormatPreferences()).performSearchById(arXivIdentifier.getNormalizedWithoutVersion());
return OptionalUtil.toList(entry);
} catch (FetcherException ex) {
LOGGER.error("Error while fetching", ex);
return Collections.emptyList();
}
}
}

0 comments on commit f1d3003

Please sign in to comment.