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

public Class ScholarFetcher

extends Object
implements FulltextFetcher, PagedSearchBasedFetcher, CustomizableKeyFetcher
Class Inheritance
All Implemented Interfaces
org.jabref.logic.importer.fetcher.CustomizableKeyFetcher, org.jabref.logic.importer.WebFetcher, org.jabref.logic.importer.PagedSearchBasedFetcher, org.jabref.logic.importer.SearchBasedFetcher, org.jabref.logic.importer.FulltextFetcher
Annotations
@NullMarked
Imports
java.io.IOException, .InputStream, java.net.HttpURLConnection, .MalformedURLException, .URISyntaxException, .URL, java.util.ArrayList, .List, .Map, .Optional, java.util.concurrent.ConcurrentHashMap, java.util.regex.Matcher, .Pattern, org.jabref.logic.importer.FetcherException, .FulltextFetcher, .ImporterPreferences, .PagedSearchBasedFetcher, .ParseException, org.jabref.logic.importer.fetcher.transformers.ScholarApiQueryTransformer, org.jabref.logic.importer.util.JsonReader, org.jabref.logic.net.URLDownload, org.jabref.logic.util.URLUtil, org.jabref.logic.util.strings.StringUtil, org.jabref.model.entry.AuthorList, .BibEntry, org.jabref.model.entry.field.StandardField, .UnknownField, org.jabref.model.entry.types.StandardEntryType, org.jabref.model.paging.Page, org.jabref.model.search.query.BaseQueryNode, kong.unirest.core.json.JSONArray, kong.unirest.core.json.JSONException, kong.unirest.core.json.JSONObject, org.apache.hc.core5.net.URIBuilder, org.jspecify.annotations.NullMarked, org.slf4j.Logger, .LoggerFactory

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
private static enum

Field Summary

Modifier and TypeField and Description
private final Map<ScholarFetcher.PageKey, String>
public static final String
private final ImporterPreferences
private static final Pattern
private static final Pattern
private static final String
private static final Logger
private static final int
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
ScholarFetcher(ImporterPreferences importerPreferences)

Method Summary

Modifier and TypeMethod and Description
private URL
buildSearchUrl(ScholarFetcher.SearchEndpoint endpoint, String query, int pageNumber, Optional<Integer> startYear, Optional<Integer> endYear)

private kong.unirest.core.json.JSONObject
callApi(URL url)

private Page<BibEntry>
fetchPage(String query, int pageNumber, Optional<Integer> startYear, Optional<Integer> endYear)

public Optional<URL>
private Optional<String>
public Map<String, String>
getDownloadHeaders()

Overrides default org.jabref.logic.importer.FulltextFetcher.getDownloadHeaders.

Returns HTTP headers required for downloading the PDF returned by findFullText.

public String
getName()

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

Returns the localized name of this fetcher.

private URL
public TrustLevel
getTrustLevel()

Implements org.jabref.logic.importer.FulltextFetcher.getTrustLevel.

Returns the level of trust for this fetcher.

public boolean
isValidKey(String apiKey)

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

Returns whether the API key is valid

public static BibEntry

Returns:

the converted BibEntry
jsonItemToBibEntry
(kong.unirest.core.json.JSONObject
the JSONObject from search results
scholarJsonEntry
)

Convert a JSONObject obtained from the Scholar API to a BibEntry

public Page<BibEntry>
public Page<BibEntry>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cursorCacheMapback to summary
private final Map<ScholarFetcher.PageKey, String> cursorCacheMap
FETCHER_NAMEback to summary
public static final String FETCHER_NAME
importerPreferencesback to summary
private final ImporterPreferences importerPreferences
JOURNAL_ISSUE_NUMBERback to summary
private static final Pattern JOURNAL_ISSUE_NUMBER
JOURNAL_VOLUMEback to summary
private static final Pattern JOURNAL_VOLUME
LIST_URLback to summary
private static final String LIST_URL
LOGGERback to summary
private static final Logger LOGGER
NO_YEAR_BOUNDback to summary
private static final int NO_YEAR_BOUND
PDF_URLback to summary
private static final String PDF_URL
SEARCH_URLback to summary
private static final String SEARCH_URL

Constructor Detail

ScholarFetcherback to summary
public ScholarFetcher(ImporterPreferences importerPreferences)

Method Detail

buildSearchUrlback to summary
private URL buildSearchUrl(ScholarFetcher.SearchEndpoint endpoint, String query, int pageNumber, Optional<Integer> startYear, Optional<Integer> endYear) throws URISyntaxException, MalformedURLException, FetcherException
callApiback to summary
private kong.unirest.core.json.JSONObject callApi(URL url) throws FetcherException
fetchPageback to summary
private Page<BibEntry> fetchPage(String query, int pageNumber, Optional<Integer> startYear, Optional<Integer> endYear) throws FetcherException
findFullTextback to summary
public Optional<URL> findFullText(BibEntry entry) throws IOException, FetcherException
Annotations
@Override
getApiKeyback to summary
private Optional<String> getApiKey()
getDownloadHeadersback to summary
public Map<String, String> getDownloadHeaders()

Overrides default org.jabref.logic.importer.FulltextFetcher.getDownloadHeaders.

Doc from org.jabref.logic.importer.FulltextFetcher.getDownloadHeaders.

Returns HTTP headers required for downloading the PDF returned by findFullText. Fetchers that require authentication (for ex: API tokens) should override this method.

Annotations
@Override
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
getTestUrlback to summary
private URL getTestUrl() throws MalformedURLException
getTrustLevelback to summary
public TrustLevel getTrustLevel()

Implements org.jabref.logic.importer.FulltextFetcher.getTrustLevel.

Doc from org.jabref.logic.importer.FulltextFetcher.getTrustLevel.

Returns the level of trust for this fetcher. We distinguish between publishers and meta search engines for example.

Annotations
@Override
isValidKeyback to summary
public boolean isValidKey(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
public static BibEntry jsonItemToBibEntry(kong.unirest.core.json.JSONObject scholarJsonEntry) throws ParseException

Convert a JSONObject obtained from the Scholar API to a BibEntry

Parameters
scholarJsonEntry:kong.unirest.core.json.JSONObject

the JSONObject from search results

Returns:BibEntry

the converted BibEntry

performRawSearchQueryPagedback to summary
public Page<BibEntry> performRawSearchQueryPaged(String rawQuery, int pageNumber) throws FetcherException

Overrides default org.jabref.logic.importer.PagedSearchBasedFetcher.performRawSearchQueryPaged.

Annotations
@Override
performSearchPagedback to summary
public Page<BibEntry> performSearchPaged(BaseQueryNode queryNode, int pageNumber) throws FetcherException

Implements org.jabref.logic.importer.PagedSearchBasedFetcher.performSearchPaged.

Annotations
@Override
org.jabref.logic.importer.fetcher back to summary

private final Record ScholarFetcher.PageKey

extends Record
Class Inheritance
Record Components
endpoint:ScholarFetcher.SearchEndpoint 
query:String 
startYear:int 
endYear:int 
pageNumber:int 

Field Summary

Modifier and TypeField and Description
private final ScholarFetcher.SearchEndpoint
endpoint

Record Component accessed by endpoint().

private final int
endYear

Record Component accessed by endYear().

private final int
pageNumber

Record Component accessed by pageNumber().

private final String
query

Record Component accessed by query().

private final int
startYear

Record Component accessed by startYear().

Constructor Summary

AccessConstructor and Description
private
PageKey(ScholarFetcher.SearchEndpoint endpoint, String query, int startYear, int endYear, int pageNumber)

Method Summary

Modifier and TypeMethod and Description
public ScholarFetcher.SearchEndpoint
endpoint()

Record Component getter of endpoint.

public int
endYear()

Record Component getter of endYear.

public final boolean
equals(Object o)

Implements abstract java.lang.Record.equals.

Indicates whether some other object is "equal to" this one.

public final int
hashCode()

Implements abstract java.lang.Record.hashCode.

Returns a hash code value for the record.

public int
pageNumber()

Record Component getter of pageNumber.

public String
query()

Record Component getter of query.

public int
startYear()

Record Component getter of startYear.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

endpointback to summary
private final ScholarFetcher.SearchEndpoint endpoint

Record Component accessed by endpoint().

endYearback to summary
private final int endYear

Record Component accessed by endYear().

pageNumberback to summary
private final int pageNumber

Record Component accessed by pageNumber().

queryback to summary
private final String query

Record Component accessed by query().

startYearback to summary
private final int startYear

Record Component accessed by startYear().

Constructor Detail

PageKeyback to summary
private PageKey(ScholarFetcher.SearchEndpoint endpoint, String query, int startYear, int endYear, int pageNumber)

Method Detail

endpointback to summary
public ScholarFetcher.SearchEndpoint endpoint()

Record Component getter of endpoint.

endYearback to summary
public int endYear()

Record Component getter of endYear.

equalsback to summary
public final boolean equals(Object o)

Implements abstract java.lang.Record.equals.

Doc from java.lang.Record.equals.

Indicates whether some other object is "equal to" this one. In addition to the general contract of Object.equals, record classes must further obey the invariant that when a record instance is "copied" by passing the result of the record component accessor methods to the canonical constructor, as follows:

    R copy = new R(r.c1(), r.c2(), ..., r.cn());
then it must be the case that r.equals(copy).
hashCodeback to summary
public final int hashCode()

Implements abstract java.lang.Record.hashCode.

Doc from java.lang.Record.hashCode.

Returns a hash code value for the record. Obeys the general contract of Object.hashCode. For records, hashing behavior is constrained by the refined contract of Record.equals, so that any two records created from the same components must have the same hash code.

pageNumberback to summary
public int pageNumber()

Record Component getter of pageNumber.

queryback to summary
public String query()

Record Component getter of query.

startYearback to summary
public int startYear()

Record Component getter of startYear.

toStringback to summary
public final String toString()

Implements abstract java.lang.Record.toString.

Doc from java.lang.Record.toString.

Returns a string representation of the record. In accordance with the general contract of Object#toString(), the toString method returns a string that "textually represents" this record. The result should be a concise but informative representation that is easy for a person to read.

In addition to this general contract, record classes must further participate in the invariant that any two records which are equal must produce equal strings. This invariant is necessarily relaxed in the rare case where corresponding equal component values might fail to produce equal strings for themselves.

org.jabref.logic.importer.fetcher back to summary

private final Enum ScholarFetcher.SearchEndpoint

extends Enum<ScholarFetcher.SearchEndpoint>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
public static final ScholarFetcher.SearchEndpoint
private final String
public static final ScholarFetcher.SearchEndpoint
private final String

Constructor Summary

AccessConstructor and Description
private
SearchEndpoint(String url, String cursorRequestParameter, String nextCursorResponseParameter)

Method Summary

Modifier and TypeMethod and Description
pack-priv String
pack-priv String
pack-priv String
url()

public static ScholarFetcher.SearchEndpoint
public static ScholarFetcher.SearchEndpoint[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

cursorRequestParameterback to summary
private final String cursorRequestParameter
LISTback to summary
public static final ScholarFetcher.SearchEndpoint LIST
nextCursorResponseParameterback to summary
private final String nextCursorResponseParameter
SEARCHback to summary
public static final ScholarFetcher.SearchEndpoint SEARCH
urlback to summary
private final String url

Constructor Detail

SearchEndpointback to summary
private SearchEndpoint(String url, String cursorRequestParameter, String nextCursorResponseParameter)

Method Detail

cursorRequestParameterback to summary
pack-priv String cursorRequestParameter()
nextCursorResponseParameterback to summary
pack-priv String nextCursorResponseParameter()
urlback to summary
pack-priv String url()
valueOfback to summary
public static ScholarFetcher.SearchEndpoint valueOf(String name)
valuesback to summary
public static ScholarFetcher.SearchEndpoint[] values()