Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.logic.browserext

public Class BrowserExtensionBridgeClient

extends Object
Class Inheritance
Imports
java.io.IOException, java.net.URI, .URISyntaxException, java.net.http.HttpClient, .HttpRequest, .HttpResponse, java.nio.charset.StandardCharsets, java.nio.file.Files, .Path, java.time.Duration, java.util.Optional, org.jabref.logic.os.OS, org.jabref.logic.util.strings.StringUtil, org.slf4j.Logger, .LoggerFactory, tools.jackson.core.JacksonException, tools.jackson.databind.JsonNode, .ObjectMapper

Talks to the loopback HTTP bridge the JabRef Browser Extension (experimental) starts on demand (bridge/JabExtBridge.java, see docs/requirements/mathscinet.md, req~mathscinet.sync.transport~1).

The bridge is discovered, not configured: it writes a small JSON file naming its ephemeral port and a token file once it is running. If that file is absent (extension not installed, or not started), every method here fails silently by returning an empty Optional — the bridge is an optional enhancement, never a hard dependency for identifier editing.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
public static record
BrowserExtensionBridgeClient.MathSciNetOpenResult

Result of a successful /v1/mathscinet/open call.

Field Summary

Modifier and TypeField and Description
private final Path
private final HttpClient
private static final Logger
private static final ObjectMapper
private static final String
private static final Duration

Constructor Summary

AccessConstructor and Description
public
pack-priv
BrowserExtensionBridgeClient(Path discoveryDirectory)

Visible for tests, to point at a temporary discovery directory instead of the real OS-specific one.

Method Summary

Modifier and TypeMethod and Description
private static Path
private static Path
defaultDiscoveryDirectory()

Mirrors the path resolution in the JabRef Browser Extension's bridge/JabExtBridge.java (there: JabRefPaths.jabrefConfigBase()).

public Optional<BrowserExtensionBridgeClient.MathSciNetOpenResult>
openMathSciNet(String mrNumber)

Asks the browser extension to open (or focus and navigate) the one tab it keeps for this feature to the MathSciNet page for mrNumber.

private Optional<BrowserExtensionBridgeClient.Discovery>
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

discoveryDirectoryback to summary
private final Path discoveryDirectory
httpClientback to summary
private final HttpClient httpClient
LOGGERback to summary
private static final Logger LOGGER
MAPPERback to summary
private static final ObjectMapper MAPPER
PROVIDER_NAMEback to summary
private static final String PROVIDER_NAME
REQUEST_TIMEOUTback to summary
private static final Duration REQUEST_TIMEOUT

Constructor Detail

BrowserExtensionBridgeClientback to summary
public BrowserExtensionBridgeClient()
BrowserExtensionBridgeClientback to summary
pack-priv BrowserExtensionBridgeClient(Path discoveryDirectory)

Visible for tests, to point at a temporary discovery directory instead of the real OS-specific one.

Method Detail

configBaseback to summary
private static Path configBase()
defaultDiscoveryDirectoryback to summary
private static Path defaultDiscoveryDirectory()

Mirrors the path resolution in the JabRef Browser Extension's bridge/JabExtBridge.java (there: JabRefPaths.jabrefConfigBase()). The two repos share no code, so this must be kept in sync by hand with that method if either side changes.

openMathSciNetback to summary
public Optional<BrowserExtensionBridgeClient.MathSciNetOpenResult> openMathSciNet(String mrNumber)

Asks the browser extension to open (or focus and navigate) the one tab it keeps for this feature to the MathSciNet page for mrNumber. Returns empty if the bridge isn't running or the request fails for any reason.

readDiscoveryback to summary
private Optional<BrowserExtensionBridgeClient.Discovery> readDiscovery()
org.jabref.logic.browserext back to summary

private final Record BrowserExtensionBridgeClient.Discovery

extends Record
Class Inheritance
Record Components
port:int 
token:String 

Field Summary

Modifier and TypeField and Description
private final int
port

Record Component accessed by port().

private final String
token

Record Component accessed by token().

Constructor Summary

AccessConstructor and Description
private
Discovery(int port, String token)

Method Summary

Modifier and TypeMethod and Description
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
port()

Record Component getter of port.

public String
token()

Record Component getter of token.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

portback to summary
private final int port

Record Component accessed by port().

tokenback to summary
private final String token

Record Component accessed by token().

Constructor Detail

Discoveryback to summary
private Discovery(int port, String token)

Method Detail

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.

portback to summary
public int port()

Record Component getter of port.

tokenback to summary
public String token()

Record Component getter of token.

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.browserext back to summary

public final Record BrowserExtensionBridgeClient.MathSciNetOpenResult

extends Record
Class Inheritance
Record Components
action:String
either "opened" (a new tab was created) or "focused" (an existing, extension-owned tab was reused)
tabId:int
the browser's id for the tab, for diagnostics only

Result of a successful /v1/mathscinet/open call.

Field Summary

Modifier and TypeField and Description
private final String
action

Record Component accessed by action().

either "opened" (a new tab was created) or "focused" (an existing, extension-owned tab was reused)
private final int
tabId

Record Component accessed by tabId().

the browser's id for the tab, for diagnostics only

Constructor Summary

AccessConstructor and Description
public
MathSciNetOpenResult(String action, int tabId)

Method Summary

Modifier and TypeMethod and Description
public String
action()

Record Component getter of action.

Record Component either "opened" (a new tab was created) or "focused" (an existing, extension-owned tab was reused)

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
tabId()

Record Component getter of tabId.

Record Component the browser's id for the tab, for diagnostics only

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

actionback to summary
private final String action

Record Component accessed by action().

either "opened" (a new tab was created) or "focused" (an existing, extension-owned tab was reused)

tabIdback to summary
private final int tabId

Record Component accessed by tabId().

the browser's id for the tab, for diagnostics only

Constructor Detail

MathSciNetOpenResultback to summary
public MathSciNetOpenResult(String action, int tabId)

Method Detail

actionback to summary
public String action()

Record Component getter of action.

Record Component
either "opened" (a new tab was created) or "focused" (an existing, extension-owned tab was reused)
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.

tabIdback to summary
public int tabId()

Record Component getter of tabId.

Record Component
the browser's id for the tab, for diagnostics only
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.