Verified Owner
Top Description Fields Constructors Methods
org.jabref.logic.importer.fetcher

public Class CrossRef

extends Object
implements IdParserFetcher<DOI>, EntryBasedParserFetcher, SearchBasedParserFetcher, IdBasedParserFetcher, CustomizableKeyFetcher
Class Inheritance
All Implemented Interfaces
org.jabref.logic.importer.fetcher.CustomizableKeyFetcher, org.jabref.logic.importer.WebFetcher, org.jabref.logic.importer.IdBasedParserFetcher, org.jabref.logic.importer.ParserFetcher, org.jabref.logic.importer.IdBasedFetcher, org.jabref.logic.importer.SearchBasedParserFetcher, org.jabref.logic.importer.SearchBasedFetcher, org.jabref.logic.importer.EntryBasedParserFetcher, org.jabref.logic.importer.EntryBasedFetcher, org.jabref.logic.importer.IdParserFetcher, org.jabref.logic.importer.IdFetcher
Imports
java.io.IOException, java.net.HttpURLConnection, .MalformedURLException, .URISyntaxException, .URL, .URLEncoder, java.nio.charset.StandardCharsets, java.util.ArrayList, .List, .Optional, java.util.stream.IntStream, org.jabref.logic.cleanup.FieldFormatterCleanup, org.jabref.logic.formatter.bibtexfields.ClearFormatter, .RemoveEnclosingBracesFormatter, org.jabref.logic.help.HelpFile, org.jabref.logic.importer.EntryBasedParserFetcher, .FetcherException, .IdBasedParserFetcher, .IdParserFetcher, .ImporterPreferences, .ParseException, .Parser, .SearchBasedParserFetcher, org.jabref.logic.importer.fetcher.transformers.DefaultQueryTransformer, org.jabref.logic.importer.util.JsonReader, org.jabref.logic.net.URLDownload, org.jabref.logic.util.strings.StringSimilarity, .StringUtil, org.jabref.model.entry.Author, .AuthorList, .BibEntry, org.jabref.model.entry.field.StandardField, org.jabref.model.entry.identifier.DOI, org.jabref.model.entry.types.EntryType, .StandardEntryType, org.jabref.model.search.query.BaseQueryNode, org.jabref.model.util.OptionalUtil, com.google.common.annotations.VisibleForTesting, kong.unirest.core.UnirestException, kong.unirest.core.json.JSONArray, kong.unirest.core.json.JSONException, kong.unirest.core.json.JSONObject, org.apache.hc.core5.net.URIBuilder, org.jspecify.annotations.NonNull

A class for fetching DOIs from CrossRef

See their GitHub page for documentation.

Field Summary

Modifier and TypeField and Description
private static final String
public static final String
private final ImporterPreferences
private static final String
private static final FetcherRateLimiter
RATE_LIMITER

Rate limit for the CrossRef REST API public pool.

private static final RemoveEnclosingBracesFormatter

Constructor Summary

AccessConstructor and Description
public
public
CrossRef(ImporterPreferences importerPreferences)

Method Summary

Modifier and TypeMethod and Description
private void
private EntryType
public void
doPostCleanup(BibEntry entry)

Overrides default org.jabref.logic.importer.ParserFetcher.doPostCleanup.

Performs a cleanup of the fetched entry.

public Optional<DOI>
extractIdentifier(BibEntry inputEntry, List<BibEntry> fetchedEntries)

Implements org.jabref.logic.importer.IdParserFetcher.extractIdentifier.

Extracts the identifier from the list of fetched entries.

public Optional<DOI>
findIdentifier(@NonNull BibEntry entry)

Implements org.jabref.logic.importer.IdFetcher.findIdentifier.

Looks for an identifier based on the information stored in the given BibEntry.

public Optional<HelpFile>
getHelpPage()

Overrides default org.jabref.logic.importer.WebFetcher.getHelpPage.

Returns the help page for this fetcher.

public String
getIdentifierName()

Implements org.jabref.logic.importer.IdFetcher.getIdentifierName.

Returns the name of the identifier that is returned by this fetcher.

private String
getKeywords(kong.unirest.core.json.JSONArray jsonArray)

public String
getName()

Implements org.jabref.logic.importer.WebFetcher.getName.

Returns the localized name of this fetcher.

public Parser
pack-priv String
public URL
public URL
getUrlForIdentifier(String identifier)

Implements org.jabref.logic.importer.IdBasedParserFetcher.getUrlForIdentifier.

Constructs a URL based on the query.

public URL
getURLForQuery(BaseQueryNode queryNode)

Implements org.jabref.logic.importer.SearchBasedParserFetcher.getURLForQuery.

Constructs a URL based on the lucene query.

public boolean
isValidKey(@NonNull String apiKey)

Overrides default org.jabref.logic.importer.fetcher.CustomizableKeyFetcher.isValidKey.

Returns whether the API key is valid

private BibEntry
jsonItemToBibEntry(kong.unirest.core.json.JSONObject item)

public List<BibEntry>
performSearch(@NonNull BibEntry entry)

Implements org.jabref.logic.importer.EntryBasedFetcher.performSearch.

Looks for hits which are matched by the given BibEntry.

public List<BibEntry>
performSearch(@NonNull BaseQueryNode queryNode)

Overrides default org.jabref.logic.importer.SearchBasedParserFetcher.performSearch.

This method is used to send queries with advanced URL parameters.

public Optional<BibEntry>
performSearchById(@NonNull String identifier)

Overrides default org.jabref.logic.importer.IdBasedParserFetcher.performSearchById.

Looks for bibliographic information associated to the given identifier.

private String
toAuthors(kong.unirest.core.json.JSONArray authors)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

API_URLback to summary
private static final String API_URL
FETCHER_NAMEback to summary
public static final String FETCHER_NAME
importerPreferencesback to summary
private final ImporterPreferences importerPreferences
MAILTO_PARAMETERback to summary
private static final String MAILTO_PARAMETER
RATE_LIMITERback to summary
private static final FetcherRateLimiter RATE_LIMITER

Rate limit for the CrossRef REST API public pool. CrossRef's public pool defaults to 50 req/s, as measured via X-Rate-Limit-Interval/X-Rate-Limit-Limit response headers - consistent with DoiFetcher's existing CROSSREF_DCN_RATE_LIMITER.

REMOVE_BRACES_FORMATTERback to summary
private static final RemoveEnclosingBracesFormatter REMOVE_BRACES_FORMATTER

Constructor Detail

CrossRefback to summary
public CrossRef()
CrossRefback to summary
public CrossRef(ImporterPreferences importerPreferences)

Method Detail

addMailtoParameterback to summary
private void addMailtoParameter(URIBuilder uriBuilder)
convertTypeback to summary
private EntryType convertType(String type)
doPostCleanupback to summary
public void doPostCleanup(BibEntry entry)

Overrides default org.jabref.logic.importer.ParserFetcher.doPostCleanup.

Doc from org.jabref.logic.importer.ParserFetcher.doPostCleanup.

Performs a cleanup of the fetched entry.

Only systematic errors of the fetcher should be corrected here (i.e. if information is consistently contained in the wrong field or the wrong format) but not cosmetic issues which may depend on the user's taste (for example, LateX code vs HTML in the abstract).

Try to reuse existing org.jabref.logic.formatter.Formatter for the cleanup. For example, new FieldFormatterCleanup(StandardField.TITLE, new RemoveBracesFormatter()).cleanup(entry);

By default, no cleanup is done.

Annotations
@Override
extractIdentifierback to summary
public Optional<DOI> extractIdentifier(BibEntry inputEntry, List<BibEntry> fetchedEntries)

Implements org.jabref.logic.importer.IdParserFetcher.extractIdentifier.

Doc from org.jabref.logic.importer.IdParserFetcher.extractIdentifier.

Extracts the identifier from the list of fetched entries.

Annotations
@Override
findIdentifierback to summary
public Optional<DOI> findIdentifier(@NonNull BibEntry entry) throws FetcherException

Implements org.jabref.logic.importer.IdFetcher.findIdentifier.

Doc from org.jabref.logic.importer.IdFetcher.findIdentifier.

Looks for an identifier based on the information stored in the given BibEntry.

Annotations
@Override
getHelpPageback to summary
public Optional<HelpFile> getHelpPage()

Overrides default org.jabref.logic.importer.WebFetcher.getHelpPage.

Doc from org.jabref.logic.importer.WebFetcher.getHelpPage.

Returns the help page for this fetcher.

Annotations
@Override
getIdentifierNameback to summary
public String getIdentifierName()

Implements org.jabref.logic.importer.IdFetcher.getIdentifierName.

Doc from org.jabref.logic.importer.IdFetcher.getIdentifierName.

Returns the name of the identifier that is returned by this fetcher.

Annotations
@Override
getKeywordsback to summary
private String getKeywords(kong.unirest.core.json.JSONArray jsonArray)
getNameback to summary
public String getName()

Implements org.jabref.logic.importer.WebFetcher.getName.

Doc from org.jabref.logic.importer.WebFetcher.getName.

Returns the localized name of this fetcher. The title can be used to display the fetcher in the menu and in the side pane.

Todo

This name is also used for identifying the fetcher in preferences for API keys. Thus, any switch of the language will "remove" API keys.

Annotations
@Override
getParserback to summary
public Parser getParser()

Implements org.jabref.logic.importer.IdParserFetcher.getParser, org.jabref.logic.importer.EntryBasedParserFetcher.getParser, org.jabref.logic.importer.SearchBasedParserFetcher.getParser, org.jabref.logic.importer.IdBasedParserFetcher.getParser.

Doc from org.jabref.logic.importer.IdParserFetcher.getParser.

Returns the parser used to convert the response to a list of BibEntry.

Annotations
@Override
getTestUrlback to summary
pack-priv String getTestUrl(String apiKey)
Annotations
@VisibleForTesting
getURLForEntryback to summary
public URL getURLForEntry(BibEntry entry) throws URISyntaxException, MalformedURLException

Implements org.jabref.logic.importer.IdParserFetcher.getURLForEntry, org.jabref.logic.importer.EntryBasedParserFetcher.getURLForEntry.

Doc from org.jabref.logic.importer.IdParserFetcher.getURLForEntry.

Constructs a URL based on the BibEntry.

Annotations
@Override
getUrlForIdentifierback to summary
public URL getUrlForIdentifier(String identifier) throws URISyntaxException, MalformedURLException

Implements org.jabref.logic.importer.IdBasedParserFetcher.getUrlForIdentifier.

Doc from org.jabref.logic.importer.IdBasedParserFetcher.getUrlForIdentifier.

Constructs a URL based on the query.

Annotations
@Override
getURLForQueryback to summary
public URL getURLForQuery(BaseQueryNode queryNode) throws URISyntaxException, MalformedURLException

Implements org.jabref.logic.importer.SearchBasedParserFetcher.getURLForQuery.

Doc from org.jabref.logic.importer.SearchBasedParserFetcher.getURLForQuery.

Constructs a URL based on the lucene query.

Annotations
@Override
isValidKeyback to summary
public boolean isValidKey(@NonNull String apiKey)

Overrides default org.jabref.logic.importer.fetcher.CustomizableKeyFetcher.isValidKey.

Doc from org.jabref.logic.importer.fetcher.CustomizableKeyFetcher.isValidKey.

Returns whether the API key is valid

Annotations
@Override
jsonItemToBibEntryback to summary
private BibEntry jsonItemToBibEntry(kong.unirest.core.json.JSONObject item) throws ParseException
performSearchback to summary
public List<BibEntry> performSearch(@NonNull BibEntry entry) throws FetcherException

Implements org.jabref.logic.importer.EntryBasedFetcher.performSearch.

Doc from org.jabref.logic.importer.EntryBasedFetcher.performSearch.

Looks for hits which are matched by the given BibEntry.

Annotations
@Override
performSearchback to summary
public List<BibEntry> performSearch(@NonNull BaseQueryNode queryNode) throws FetcherException

Overrides default org.jabref.logic.importer.SearchBasedParserFetcher.performSearch.

Doc from org.jabref.logic.importer.SearchBasedParserFetcher.performSearch.

This method is used to send queries with advanced URL parameters. This method is necessary as the performSearch method does not support certain URL parameters that are used for fielded search, such as a title, author, or year parameter.

Annotations
@Override
performSearchByIdback to summary
public Optional<BibEntry> performSearchById(@NonNull String identifier) throws FetcherException

Overrides default org.jabref.logic.importer.IdBasedParserFetcher.performSearchById.

Doc from org.jabref.logic.importer.IdBasedFetcher.performSearchById.

Looks for bibliographic information associated to the given identifier.

Annotations
@Override
toAuthorsback to summary
private String toAuthors(kong.unirest.core.json.JSONArray authors)