Verified Owner
Top Inners Fields Constructors Methods
org.jabref.logic.openoffice.style

pack-priv Class JStyleGetCitationMarker

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Arrays, .List, .Optional, org.jabref.logic.formatter.bibtexfields.RemoveEnclosingBracesFormatter, org.jabref.logic.util.strings.StringUtil, org.jabref.model.database.BibDatabase, org.jabref.model.entry.Author, .AuthorList, .BibEntry, org.jabref.model.entry.field.Field, .OrFields, org.jabref.model.openoffice.ootext.OOText, org.jabref.model.openoffice.style.CitationLookupResult, .CitationMarkerEntry, .CitationMarkerNormEntry, .CitationType, .NonUniqueCitationMarker, .PageInfo, org.jspecify.annotations.NonNull

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
private static class
JStyleGetCitationMarker.CitationMarkerNormEntryWrap

Add / override methods for the purpose of creating a normalized citation marker.

private static class
JStyleGetCitationMarker.FieldAndContent

On success, getRawCitationMarkerField returns content, but we also need to know which field matched, because for some fields (actually: for author names) we need to reproduce the surrounding braces to inform AuthorList.parse not to split up the content.

Field Summary

Modifier and TypeField and Description
private static final RemoveEnclosingBracesFormatter

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static int
calculateNAuthorsToEmit(JStyle style, CitationMarkerEntry entry)

How many authors would be emitted for entry, considering style and entry.getIsFirstAppearanceOfSource()

If entry is unresolved, return 0.

public static OOText
createCitationMarker(JStyle style, List<CitationMarkerEntry>
A group of citations to process.
citationMarkerEntries
,
boolean
If true, put parenthesis around the whole group, otherwise around each (year,uniqueLetter,pageInfo) part.
inParenthesis
,
NonUniqueCitationMarker
What should happen if we stumble upon citations with identical normalized citation markers which cite different sources and are not distinguished by uniqueLetters.
nonUniqueCitationMarkerHandling
)

Produce citation marker for a citation group.

public static OOText
createCitationMarker(JStyle style, List<CitationMarkerEntry> citationMarkerEntries, CitationType
Decides brackets and which of the (author, year) parts are emitted.
citationType
,
NonUniqueCitationMarker nonUniqueCitationMarkerHandling)

As above, but selects the presentation from the citation type of the group.

private static String

Returns:

"AuASBuASCuOXFORD_COMMADuyearSep" or "AuetAlString", where AS = AUTHOR_SEPARATOR, Au, Bu, Cu, Du are last names of authors.
formatAuthorList
(JStyle style, @NonNull AuthorList
Parsed list of authors.
authorList
,
int
The maximum number of authors to write out. If there are more authors, then ET_AL_STRING is emitted to mark their omission. Set to -1 to write out all authors. maxAuthors=0 is pointless, now throws IllegalArgumentException. (Earlier it behaved as maxAuthors=1). maxAuthors less than -1 : throw IllegalArgumentException
maxAuthors
,
String
For "A, BandC"
andString
)

Note:

  • The "AuASBuASCu" (or the "Au") part may be empty (maxAuthors==0 or nAuthors==0).
  • OXFORD_COMMA is only emitted if nAuthors is at least 3.
  • andString is only emitted if nAuthors is at least 2.
private static String

Returns:

The author name, or an empty String if inapplicable.
getAuthorLastName
(AuthorList
The author list.
authorList
,
int
The number of the author to return.
number
)

Look up the nth author and return the "proper" last name for citation markers.

private static AuthorList
getAuthorList(JStyle style, CitationLookupResult citationLookupResult)

private static OOText

Returns:

The formatted citation.
getAuthorYearParenthesisMarker2
(JStyle style, JStyleGetCitationMarker.AuthorYearMarkerPurpose
IN_PARENTHESIS and NORMALIZED puts parentheses around the whole, IN_TEXT around each (year,uniqueLetter,pageInfo) part. NORMALIZED omits uniqueLetter and pageInfo, ignores isFirstAppearanceOfSource (always style.getMaxAuthors, not getMaxAuthorsFirst)
purpose
,
List<CitationMarkerEntry>
The list of CitationMarkerEntry values to process.
entries
,
boolean[]
Should have the same length as entries, and contain true for entries starting a new group, false for those that only add a uniqueLetter tothe grouped presentation.
startsNewGroup
,
Optional<Integer>
If not empty, always show this number of authors. Added to allow NORMALIZED to use maxAuthors value that differs from style.getMaxAuthors()
maxAuthorsOverride
)

Produce (Author, year) or "Author (year)" style citation strings.

private static String

Returns:

The resolved field content, or an empty string if the field(s) were empty.
getCitationMarkerField
(JStyle style, @NonNull CitationLookupResult citationLookupResult, OrFields
A list of fields, to look up, using first nonempty hit. If backup fields are needed, separate field names by /. E.g. to use "author" with "editor" as backup, specify FieldFactory.serializeOrFields(StandardField.AUTHOR, StandardField.EDITOR)
fields
)

This method looks up a field for an entry in a database.

pack-priv static OOText
getNormalizedCitationMarker(JStyle style, CitationMarkerNormEntry
A citation to process.
normEntry
,
Optional<Integer> maxAuthorsOverride)

Returns: A normalized citation marker for deciding which citations need uniqueLetters.

private static List<OOText>
getNormalizedCitationMarkers(JStyle style, List<CitationMarkerEntry> citationMarkerEntries, Optional<Integer> maxAuthorsOverride)

private static Optional<JStyleGetCitationMarker.FieldAndContent>
getRawCitationMarkerField(@NonNull BibEntry entry, @NonNull BibDatabase database, @NonNull OrFields fields)

Returns: the field and the content of the first nonempty (after trimming) field (or alias) from fields found in entry.

private static String
private static JStyleGetCitationMarker.AuthorYearMarkerPurpose
purposeOf(CitationType citationType)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

REMOVE_BRACES_FORMATTERback to summary
private static final RemoveEnclosingBracesFormatter REMOVE_BRACES_FORMATTER

Constructor Detail

JStyleGetCitationMarkerback to summary
private JStyleGetCitationMarker()

Method Detail

calculateNAuthorsToEmitback to summary
private static int calculateNAuthorsToEmit(JStyle style, CitationMarkerEntry entry)

How many authors would be emitted for entry, considering style and entry.getIsFirstAppearanceOfSource()

If entry is unresolved, return 0.

createCitationMarkerback to summary
public static OOText createCitationMarker(JStyle style, List<CitationMarkerEntry> citationMarkerEntries, boolean inParenthesis, NonUniqueCitationMarker nonUniqueCitationMarkerHandling)

Produce citation marker for a citation group.

Attempts to join consecutive citations: if normalized citations markers match and no pageInfo is present, the second entry can be presented by appending its uniqueLetter to the previous.

If either entry has pageInfo, join is inhibited. If the previous entry has more names than we need we check with extended normalizedMarkers if they match.

For consecutive identical entries, the second one is omitted. Identical requires same pageInfo here, we do not try to merge them.

Note

notifying the user about them would be nice.

Note

only consecutive citations are checked.

Parameters
citationMarkerEntries:List<CitationMarkerEntry>

A group of citations to process.

inParenthesis:boolean

If true, put parenthesis around the whole group, otherwise around each (year,uniqueLetter,pageInfo) part.

nonUniqueCitationMarkerHandling:NonUniqueCitationMarker

What should happen if we stumble upon citations with identical normalized citation markers which cite different sources and are not distinguished by uniqueLetters.

createCitationMarkerback to summary
public static OOText createCitationMarker(JStyle style, List<CitationMarkerEntry> citationMarkerEntries, CitationType citationType, NonUniqueCitationMarker nonUniqueCitationMarkerHandling)

As above, but selects the presentation from the citation type of the group.

Parameters
citationType:CitationType

Decides brackets and which of the (author, year) parts are emitted.

formatAuthorListback to summary
private static String formatAuthorList(JStyle style, @NonNull AuthorList authorList, int maxAuthors, String andString)

Note:

  • The "AuASBuASCu" (or the "Au") part may be empty (maxAuthors==0 or nAuthors==0).
  • OXFORD_COMMA is only emitted if nAuthors is at least 3.
  • andString is only emitted if nAuthors is at least 2.
Parameters
authorList:@NonNull AuthorList

Parsed list of authors.

maxAuthors:int

The maximum number of authors to write out. If there are more authors, then ET_AL_STRING is emitted to mark their omission. Set to -1 to write out all authors. maxAuthors=0 is pointless, now throws IllegalArgumentException. (Earlier it behaved as maxAuthors=1). maxAuthors less than -1 : throw IllegalArgumentException

andString:String

For "A, BandC"

Returns:String

"AuASBuASCuOXFORD_COMMADuyearSep" or "AuetAlString", where AS = AUTHOR_SEPARATOR, Au, Bu, Cu, Du are last names of authors.

getAuthorLastNameback to summary
private static String getAuthorLastName(AuthorList authorList, int number)

Look up the nth author and return the "proper" last name for citation markers.

Note

"proper" in the sense that it includes the "von" part of the name (followed by a space) if there is one.

Parameters
authorList:AuthorList

The author list.

number:int

The number of the author to return.

Returns:String

The author name, or an empty String if inapplicable.

getAuthorListback to summary
private static AuthorList getAuthorList(JStyle style, CitationLookupResult citationLookupResult)
getAuthorYearParenthesisMarker2back to summary
private static OOText getAuthorYearParenthesisMarker2(JStyle style, JStyleGetCitationMarker.AuthorYearMarkerPurpose purpose, List<CitationMarkerEntry> entries, boolean[] startsNewGroup, Optional<Integer> maxAuthorsOverride)

Produce (Author, year) or "Author (year)" style citation strings.

Here we do not check for duplicate entries: those are handled by getCitationMarker by omitting them from the list.

Unresolved citations recognized by entry.getBibEntry() and/or entry.getDatabase() returning empty, and emitted as "Unresolved${citationKey}".

Neither uniqueLetter nor pageInfo are emitted for unresolved citations.

Parameters
purpose:JStyleGetCitationMarker.AuthorYearMarkerPurpose

IN_PARENTHESIS and NORMALIZED puts parentheses around the whole, IN_TEXT around each (year,uniqueLetter,pageInfo) part. NORMALIZED omits uniqueLetter and pageInfo, ignores isFirstAppearanceOfSource (always style.getMaxAuthors, not getMaxAuthorsFirst)

entries:List<CitationMarkerEntry>

The list of CitationMarkerEntry values to process.

startsNewGroup:boolean[]

Should have the same length as entries, and contain true for entries starting a new group, false for those that only add a uniqueLetter tothe grouped presentation.

maxAuthorsOverride:Optional<Integer>

If not empty, always show this number of authors. Added to allow NORMALIZED to use maxAuthors value that differs from style.getMaxAuthors()

Returns:OOText

The formatted citation.

getCitationMarkerFieldback to summary
private static String getCitationMarkerField(JStyle style, @NonNull CitationLookupResult citationLookupResult, OrFields fields)

This method looks up a field for an entry in a database.

Any number of backup fields can be used if the primary field is empty.

Parameters
fields:OrFields

A list of fields, to look up, using first nonempty hit. If backup fields are needed, separate field names by /. E.g. to use "author" with "editor" as backup, specify FieldFactory.serializeOrFields(StandardField.AUTHOR, StandardField.EDITOR)

Returns:String

The resolved field content, or an empty string if the field(s) were empty.

getNormalizedCitationMarkerback to summary
pack-priv static OOText getNormalizedCitationMarker(JStyle style, CitationMarkerNormEntry normEntry, Optional<Integer> maxAuthorsOverride)
Parameters
normEntry:CitationMarkerNormEntry

A citation to process.

Returns:OOText

A normalized citation marker for deciding which citations need uniqueLetters.

For details of what "normalized" means: See JStyleGetCitationMarker#getAuthorYearParenthesisMarker2

Note

now includes some markup.

getNormalizedCitationMarkersback to summary
private static List<OOText> getNormalizedCitationMarkers(JStyle style, List<CitationMarkerEntry> citationMarkerEntries, Optional<Integer> maxAuthorsOverride)
getRawCitationMarkerFieldback to summary
private static Optional<JStyleGetCitationMarker.FieldAndContent> getRawCitationMarkerField(@NonNull BibEntry entry, @NonNull BibDatabase database, @NonNull OrFields fields)
Returns:Optional<JStyleGetCitationMarker.FieldAndContent>

the field and the content of the first nonempty (after trimming) field (or alias) from fields found in entry. Return Optional.empty() if found nothing.

markupAuthorNameback to summary
private static String markupAuthorName(JStyle style, String name)
purposeOfback to summary
private static JStyleGetCitationMarker.AuthorYearMarkerPurpose purposeOf(CitationType citationType)
org.jabref.logic.openoffice.style back to summary

private final Enum JStyleGetCitationMarker.AuthorYearMarkerPurpose

extends Enum<JStyleGetCitationMarker.AuthorYearMarkerPurpose>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose
AUTHOR_ONLY

"Doe" -- author part only.

public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose
NO_PARENTHESIS

"Doe, 2003" -- no brackets at all.

public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose
YEAR_ONLY

"2003a" -- year part only.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static JStyleGetCitationMarker.AuthorYearMarkerPurpose
public static JStyleGetCitationMarker.AuthorYearMarkerPurpose[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AUTHOR_ONLYback to summary
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose AUTHOR_ONLY

"Doe" -- author part only.

IN_PARENTHESISback to summary
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose IN_PARENTHESIS
IN_TEXTback to summary
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose IN_TEXT
NO_PARENTHESISback to summary
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose NO_PARENTHESIS

"Doe, 2003" -- no brackets at all.

NORMALIZEDback to summary
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose NORMALIZED
YEAR_ONLYback to summary
public static final JStyleGetCitationMarker.AuthorYearMarkerPurpose YEAR_ONLY

"2003a" -- year part only.

Constructor Detail

AuthorYearMarkerPurposeback to summary
private AuthorYearMarkerPurpose()

Method Detail

valueOfback to summary
public static JStyleGetCitationMarker.AuthorYearMarkerPurpose valueOf(String name)
valuesback to summary
public static JStyleGetCitationMarker.AuthorYearMarkerPurpose[] values()
org.jabref.logic.openoffice.style back to summary

private Class JStyleGetCitationMarker.CitationMarkerNormEntryWrap

extends Object
implements CitationMarkerEntry
Class Inheritance
  • java.lang.Object
  • org.jabref.logic.openoffice.style.JStyleGetCitationMarker.CitationMarkerNormEntryWrap
All Implemented Interfaces
org.jabref.model.openoffice.style.CitationMarkerEntry, org.jabref.model.openoffice.style.CitationMarkerNormEntry

Add / override methods for the purpose of creating a normalized citation marker.

Field Summary

Modifier and TypeField and Description
pack-priv CitationMarkerNormEntry

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
public boolean
public Optional<CitationLookupResult>
getLookupResult()

Implements org.jabref.model.openoffice.style.CitationMarkerNormEntry.getLookupResult.

Result of looking up citation key in databases.

public Optional<OOText>
getPageInfo()

Implements org.jabref.model.openoffice.style.CitationMarkerEntry.getPageInfo.

pageInfo for this citation, provided by the user.

public Optional<String>
getUniqueLetter()

Implements org.jabref.model.openoffice.style.CitationMarkerEntry.getUniqueLetter.

uniqueLetter or Optional.empty() if not needed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

innerback to summary
pack-priv CitationMarkerNormEntry inner

Constructor Detail

CitationMarkerNormEntryWrapback to summary
pack-priv CitationMarkerNormEntryWrap(CitationMarkerNormEntry inner)

Method Detail

getCitationKeyback to summary
public String getCitationKey()

Implements org.jabref.model.openoffice.style.CitationMarkerNormEntry.getCitationKey.

Doc from org.jabref.model.openoffice.style.CitationMarkerNormEntry.getCitationKey.

Citation key. This is what we usually get from the document.

Used if getLookupResult() returns empty, which indicates failure to lookup in the databases.

Annotations
@Override
getIsFirstAppearanceOfSourceback to summary
public boolean getIsFirstAppearanceOfSource()

Implements org.jabref.model.openoffice.style.CitationMarkerEntry.getIsFirstAppearanceOfSource.

Annotations
@Override
getLookupResultback to summary
public Optional<CitationLookupResult> getLookupResult()

Implements org.jabref.model.openoffice.style.CitationMarkerNormEntry.getLookupResult.

Doc from org.jabref.model.openoffice.style.CitationMarkerNormEntry.getLookupResult.

Result of looking up citation key in databases.

Optional.empty() indicates unresolved citation.

Annotations
@Override
getPageInfoback to summary
public Optional<OOText> getPageInfo()

Implements org.jabref.model.openoffice.style.CitationMarkerEntry.getPageInfo.

Doc from org.jabref.model.openoffice.style.CitationMarkerEntry.getPageInfo.

pageInfo for this citation, provided by the user. May be empty, for none.

Annotations
@Override
getUniqueLetterback to summary
public Optional<String> getUniqueLetter()

Implements org.jabref.model.openoffice.style.CitationMarkerEntry.getUniqueLetter.

Doc from org.jabref.model.openoffice.style.CitationMarkerEntry.getUniqueLetter.

uniqueLetter or Optional.empty() if not needed.

Annotations
@Override
org.jabref.logic.openoffice.style back to summary

private Class JStyleGetCitationMarker.FieldAndContent

extends Object
Class Inheritance
  • java.lang.Object
  • org.jabref.logic.openoffice.style.JStyleGetCitationMarker.FieldAndContent

On success, getRawCitationMarkerField returns content, but we also need to know which field matched, because for some fields (actually: for author names) we need to reproduce the surrounding braces to inform AuthorList.parse not to split up the content.

Field Summary

Modifier and TypeField and Description
pack-priv String
pack-priv Field

Constructor Summary

AccessConstructor and Description
pack-priv
FieldAndContent(Field field, String content)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contentback to summary
pack-priv String content
fieldback to summary
pack-priv Field field

Constructor Detail

FieldAndContentback to summary
pack-priv FieldAndContent(Field field, String content)