Verified Owner
Top Description Inners Fields Constructors Methods
org.jabref.model.entry.identifier

public Class DOI

extends Object
implements Identifier
Class Inheritance
All Implemented Interfaces
org.jabref.model.entry.identifier.Identifier
Annotations
@AllowedToUseLogic:because we want to have this class \'smart\' an be able to parse obscure DOIs, too. For this, we need the LatexToUnicodeformatter.
@NullMarked
Imports
java.net.URI, .URISyntaxException, .URLDecoder, java.nio.charset.StandardCharsets, java.util.Comparator, .Locale, .Objects, .Optional, java.util.function.Function, java.util.regex.Matcher, .Pattern, java.util.stream.Stream, org.jabref.architecture.AllowedToUseLogic, org.jabref.logic.layout.format.LatexToUnicodeFormatter, org.jabref.logic.util.URLUtil, org.jabref.model.entry.field.Field, .StandardField, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Class for working with Digital object identifiers (DOIs) and Short DOIs

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static record
DOI.DoiTextMatch

Result of locating a DOI inside a text: the parsed DOI string plus the matched region (which may include a URL or doi: prefix).

Field Summary

Modifier and TypeField and Description
public static final URI
private static final String
private final String
private static final String
private static final String
private static final Pattern
private static final Pattern
private static final Pattern
private static final String
private static final Pattern
private static final String
private static final Pattern
private static final Pattern
private static final String
private static final String
private boolean
private static final Logger
public static final URI
private static final String
private static final String
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
public
DOI(String
the DOI/Short DOI string
doi
)

Creates a DOI from various schemes including URL, URN, and plain DOIs/Short DOIs.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

the plain DOI/Short DOI value.
asString
()

Implements org.jabref.model.entry.identifier.Identifier.asString.

Return the plain DOI/Short DOI

public boolean
equals(@Nullable Object o)

Overrides java.lang.Object.equals.

DOIs are case-insensitive.

public static Optional<DOI>

Returns:

an Optional containing the DOI or an empty Optional
findInText
(String
the text which might contain a DOI/Short DOI
text
)

Tries to find a DOI/Short DOI inside the given text.

private static Optional<DOI.DoiTextMatch>
findInTextInternal(String
text that has already been passed through removeReplacementCharacters
text
)

private static Optional<DOI.DoiTextMatch>
firstMatch(Pattern pattern, String text, Function<Matcher, String> doiExtractor)

public Field
public Optional<URI>

Returns:

an encoded URI representation of the DOI/Short DOI
getExternalURI
()

Implements org.jabref.model.entry.identifier.Identifier.getExternalURI.

Return a URI presentation for the DOI/Short DOI

Todo

Bad design, because Optional is used for Exception handling.

public Optional<URI>
public Optional<URI>
public String

Returns:

an encoded URL representation of the DOI/Short DOI. Empty string in the case of an error.
getURIAsASCIIString
()

Return an ASCII URL presentation for the DOI/Short DOI

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if DOI is short DOI, false otherwise
isShortDoi
()

Determines whether DOI is short DOI or not

public static boolean

Returns:

true if DOI is valid, false otherwise
isValid
(String
the DOI/Short DOI string
doi
)

Determines whether a DOI/Short DOI is valid or not

public static Optional<DOI>

Returns:

an Optional containing the DOI or an empty Optional
parse
(String
the DOI/Short DOI string
doi
)

Creates an Optional<DOI> from various schemes including URL, URN, and plain DOIs.

private static String
public static String

Returns:

the text with the first DOI occurrence replaced
replaceInText
(String
the text which might contain a DOI/Short DOI
text
,
String
the string to put in place of the matched DOI
replacement
)

Replaces the first DOI/Short DOI found in the text with the given replacement.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

AGENCY_RESOLVERback to summary
public static final URI AGENCY_RESOLVER
CHARS_TO_REMOVEback to summary
private static final String CHARS_TO_REMOVE
doiback to summary
private final String doi
DOI_EXPback to summary
private static final String DOI_EXP
DOI_GROUPback to summary
private static final String DOI_GROUP
EXACT_DOI_PATTback to summary
private static final Pattern EXACT_DOI_PATT
EXACT_SHORT_DOI_PATTback to summary
private static final Pattern EXACT_SHORT_DOI_PATT
EXACT_SHORT_DOI_SHORTCUTback to summary
private static final Pattern EXACT_SHORT_DOI_SHORTCUT
FIND_DOI_EXPback to summary
private static final String FIND_DOI_EXP
FIND_DOI_PATTback to summary
private static final Pattern FIND_DOI_PATT
FIND_SHORT_DOI_EXPback to summary
private static final String FIND_SHORT_DOI_EXP
FIND_SHORT_DOI_PATTback to summary
private static final Pattern FIND_SHORT_DOI_PATT
FIND_SHORT_DOI_SHORTCUTback to summary
private static final Pattern FIND_SHORT_DOI_SHORTCUT
HTTP_EXPback to summary
private static final String HTTP_EXP
IN_TEXT_SHORT_DOI_SHORTCUTback to summary
private static final String IN_TEXT_SHORT_DOI_SHORTCUT
isShortDoiback to summary
private boolean isShortDoi
LOGGERback to summary
private static final Logger LOGGER
RESOLVERback to summary
public static final URI RESOLVER
SHORT_DOI_EXPback to summary
private static final String SHORT_DOI_EXP
SHORT_DOI_EXP_PREFIXback to summary
private static final String SHORT_DOI_EXP_PREFIX
SHORT_DOI_HTTP_EXPback to summary
private static final String SHORT_DOI_HTTP_EXP
SHORT_DOI_SHORTCUTback to summary
private static final String SHORT_DOI_SHORTCUT

Constructor Detail

DOIback to summary
public DOI(String doi)

Creates a DOI from various schemes including URL, URN, and plain DOIs/Short DOIs.

Parameters
doi:String

the DOI/Short DOI string

Exceptions
NullPointerException:
if DOI/Short DOI is null
IllegalArgumentException:
if doi does not include a valid DOI/Short DOI

Method Detail

asStringback to summary
public String asString()

Implements org.jabref.model.entry.identifier.Identifier.asString.

Return the plain DOI/Short DOI

Returns:String

the plain DOI/Short DOI value.

Annotations
@Override
equalsback to summary
public boolean equals(@Nullable Object o)

Overrides java.lang.Object.equals.

DOIs are case-insensitive. Thus, 10.1109/cloud.2017.89 equals 10.1109/CLOUD.2017.89

Annotations
@Override
findInTextback to summary
public static Optional<DOI> findInText(String text)

Tries to find a DOI/Short DOI inside the given text.

Parameters
text:String

the text which might contain a DOI/Short DOI

Returns:Optional<DOI>

an Optional containing the DOI or an empty Optional

findInTextInternalback to summary
private static Optional<DOI.DoiTextMatch> findInTextInternal(String text)
Parameters
text:String

text that has already been passed through removeReplacementCharacters

firstMatchback to summary
private static Optional<DOI.DoiTextMatch> firstMatch(Pattern pattern, String text, Function<Matcher, String> doiExtractor)
getDefaultFieldback to summary
public Field getDefaultField()

Implements org.jabref.model.entry.identifier.Identifier.getDefaultField.

Annotations
@Override
getExternalURIback to summary
public Optional<URI> getExternalURI()

Implements org.jabref.model.entry.identifier.Identifier.getExternalURI.

Return a URI presentation for the DOI/Short DOI

Todo

Bad design, because Optional is used for Exception handling. Should be rewritten to throw a malformed URL exception.

Returns:Optional<URI>

an encoded URI representation of the DOI/Short DOI

Annotations
@Override
getExternalURIFromBaseback to summary
public Optional<URI> getExternalURIFromBase(URI base)
getExternalURIWithCustomBaseback to summary
public Optional<URI> getExternalURIWithCustomBase(String customBase)
getURIAsASCIIStringback to summary
public String getURIAsASCIIString()

Return an ASCII URL presentation for the DOI/Short DOI

Returns:String

an encoded URL representation of the DOI/Short DOI. Empty string in the case of an error.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
isShortDoiback to summary
public boolean isShortDoi()

Determines whether DOI is short DOI or not

Returns:boolean

true if DOI is short DOI, false otherwise

isValidback to summary
public static boolean isValid(String doi)

Determines whether a DOI/Short DOI is valid or not

Parameters
doi:String

the DOI/Short DOI string

Returns:boolean

true if DOI is valid, false otherwise

parseback to summary
public static Optional<DOI> parse(String doi)

Creates an Optional<DOI> from various schemes including URL, URN, and plain DOIs.

Useful for suppressing the IllegalArgumentException of the constructor and checking for java.util.Optional#isPresent instead.

Parameters
doi:String

the DOI/Short DOI string

Returns:Optional<DOI>

an Optional containing the DOI or an empty Optional

removeReplacementCharactersback to summary
private static String removeReplacementCharacters(String text)
replaceInTextback to summary
public static String replaceInText(String text, String replacement)

Replaces the first DOI/Short DOI found in the text with the given replacement. The replaced region includes any URL or doi: prefix that was part of the match. Returns the text unchanged if no DOI is present.

This reuses the same matching as findInText(String) so callers that need to strip a DOI from text do not have to re-derive the regex.

Parameters
text:String

the text which might contain a DOI/Short DOI

replacement:String

the string to put in place of the matched DOI

Returns:String

the text with the first DOI occurrence replaced

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
org.jabref.model.entry.identifier back to summary

private final Record DOI.DoiTextMatch

extends Record
Class Inheritance
Record Components
doi:String 
start:int 
end:int 

Result of locating a DOI inside a text: the parsed DOI string plus the matched region (which may include a URL or doi: prefix).

Field Summary

Modifier and TypeField and Description
private final String
doi

Record Component accessed by doi().

private final int
end

Record Component accessed by end().

private final int
start

Record Component accessed by start().

Constructor Summary

AccessConstructor and Description
private
DoiTextMatch(String doi, int start, int end)

Method Summary

Modifier and TypeMethod and Description
public String
doi()

Record Component getter of doi.

public int
end()

Record Component getter of end.

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

Record Component getter of start.

public final String
toString()

Implements abstract java.lang.Record.toString.

Returns a string representation of the record.

Field Detail

doiback to summary
private final String doi

Record Component accessed by doi().

endback to summary
private final int end

Record Component accessed by end().

startback to summary
private final int start

Record Component accessed by start().

Constructor Detail

DoiTextMatchback to summary
private DoiTextMatch(String doi, int start, int end)

Method Detail

doiback to summary
public String doi()

Record Component getter of doi.

endback to summary
public int end()

Record Component getter of end.

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.

startback to summary
public int start()

Record Component getter of start.

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.