use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class OOBibStyle method getCitationMarker.
/**
* Format the marker for the in-text citation according to this BIB style. Uniquefier letters are added as
* provided by the uniquefiers argument. If successive entries within the citation are uniquefied from each other,
* this method will perform a grouping of these entries.
*
* @param entries The list of JabRef BibEntry providing the data.
* @param database A map of BibEntry-BibDatabase pairs.
* @param inParenthesis Signals whether a parenthesized citation or an in-text citation is wanted.
* @param uniquefiers Strings to add behind the year for each entry in case it's needed to separate similar
* entries.
* @param unlimAuthors Boolean for each entry. If true, we should not use "et al" formatting regardless
* of the number of authors. Can be null to indicate that no entries should have unlimited names.
* @return The formatted citation.
*/
public String getCitationMarker(List<BibEntry> entries, Map<BibEntry, BibDatabase> database, boolean inParenthesis, String[] uniquefiers, int[] unlimAuthors) {
// Look for groups of uniquefied entries that should be combined in the output.
// E.g. (Olsen, 2005a, b) should be output instead of (Olsen, 2005a; Olsen, 2005b).
int piv = -1;
String tmpMarker = null;
if (uniquefiers != null) {
for (int i = 0; i < uniquefiers.length; i++) {
if ((uniquefiers[i] == null) || uniquefiers[i].isEmpty()) {
// Check if we just passed a group of more than one entry with uniquefier:
if ((piv > -1) && (i > (piv + 1))) {
// Do the grouping:
group(entries, uniquefiers, piv, i - 1);
}
piv = -1;
} else {
BibEntry currentEntry = entries.get(i);
if (piv == -1) {
piv = i;
tmpMarker = getAuthorYearParenthesisMarker(Collections.singletonList(currentEntry), database, null, unlimAuthors);
} else {
// See if this entry can go into a group with the previous one:
String thisMarker = getAuthorYearParenthesisMarker(Collections.singletonList(currentEntry), database, null, unlimAuthors);
String authorField = getStringCitProperty(AUTHOR_FIELD);
int maxAuthors = getIntCitProperty(MAX_AUTHORS);
String author = getCitationMarkerField(currentEntry, database.get(currentEntry), authorField);
AuthorList al = AuthorList.parse(author);
// i always at least 1 here
int prevALim = unlimAuthors[i - 1];
if (!thisMarker.equals(tmpMarker) || ((al.getNumberOfAuthors() > maxAuthors) && (unlimAuthors[i] != prevALim))) {
// previous entry was part of a group:
if ((piv > -1) && (i > (piv + 1))) {
// Do the grouping:
group(entries, uniquefiers, piv, i - 1);
}
tmpMarker = thisMarker;
piv = i;
}
}
}
}
// Finished with the loop. See if the last entries form a group:
if (piv >= 0) {
// Do the grouping:
group(entries, uniquefiers, piv, uniquefiers.length - 1);
}
}
if (inParenthesis) {
return getAuthorYearParenthesisMarker(entries, database, uniquefiers, unlimAuthors);
} else {
return getAuthorYearInTextMarker(entries, database, uniquefiers, unlimAuthors);
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class EntryTypeFormatter method format.
/**
* Input: entry type as a string
*/
@Override
public String format(String entryType) {
BibEntry entry = new BibEntry();
entry.setType(entryType);
TypedBibEntry typedEntry = new TypedBibEntry(entry, BibDatabaseMode.BIBLATEX);
return typedEntry.getTypeForDisplay();
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class XMPUtil method writeDocumentInformation.
/**
* Try to write the given BibTexEntry in the Document Information (the
* properties of the pdf).
*
* Existing fields values are overriden if the bibtex entry has the
* corresponding value set.
*
* @param document The pdf document to write to.
* @param entry The Bibtex entry that is written into the PDF properties. *
* @param database maybenull An optional database which the given bibtex entries belong to, which will be used to
* resolve strings. If the database is null the strings will not be resolved.
*/
private static void writeDocumentInformation(PDDocument document, BibEntry entry, BibDatabase database, XMPPreferences xmpPreferences) {
PDDocumentInformation di = document.getDocumentInformation();
BibEntry resolvedEntry;
if (database == null) {
resolvedEntry = entry;
} else {
resolvedEntry = database.resolveForStrings(entry, false);
}
// Query privacy filter settings
boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter();
// Fields for which not to write XMP data later on:
Set<String> filters = new TreeSet<>(xmpPreferences.getXmpPrivacyFilter());
// Set all the values including key and entryType
for (Entry<String, String> field : resolvedEntry.getFieldMap().entrySet()) {
String fieldName = field.getKey();
String fieldContent = field.getValue();
if (useXmpPrivacyFilter && filters.contains(fieldName)) {
// erase field instead of adding it
if (FieldName.AUTHOR.equals(fieldName)) {
di.setAuthor(null);
} else if (FieldName.TITLE.equals(fieldName)) {
di.setTitle(null);
} else if (FieldName.KEYWORDS.equals(fieldName)) {
di.setKeywords(null);
} else if (FieldName.ABSTRACT.equals(fieldName)) {
di.setSubject(null);
} else {
di.setCustomMetadataValue("bibtex/" + fieldName, null);
}
continue;
}
if (FieldName.AUTHOR.equals(fieldName)) {
di.setAuthor(fieldContent);
} else if (FieldName.TITLE.equals(fieldName)) {
di.setTitle(fieldContent);
} else if (FieldName.KEYWORDS.equals(fieldName)) {
di.setKeywords(fieldContent);
} else if (FieldName.ABSTRACT.equals(fieldName)) {
di.setSubject(fieldContent);
} else {
di.setCustomMetadataValue("bibtex/" + fieldName, fieldContent);
}
}
di.setCustomMetadataValue("bibtex/entrytype", StringUtil.capitalizeFirst(resolvedEntry.getType()));
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class XMPUtil method writeToDCSchema.
private static void writeToDCSchema(XMPSchemaDublinCore dcSchema, BibEntry entry, BibDatabase database, XMPPreferences xmpPreferences) {
BibEntry resolvedEntry;
if (database == null) {
resolvedEntry = entry;
} else {
resolvedEntry = database.resolveForStrings(entry, false);
}
// Query privacy filter settings
boolean useXmpPrivacyFilter = xmpPreferences.isUseXMPPrivacyFilter();
// Fields for which not to write XMP data later on:
Set<String> filters = new TreeSet<>(xmpPreferences.getXmpPrivacyFilter());
for (Entry<String, String> field : resolvedEntry.getFieldMap().entrySet()) {
if (useXmpPrivacyFilter && filters.contains(field.getKey())) {
continue;
}
if (FieldName.EDITOR.equals(field.getKey())) {
String authors = field.getValue();
/*
* Editor -> Contributor
*
* Field: dc:contributor
*
* Type: bag ProperName
*
* Category: External
*
* Description: Contributors to the resource (other than the
* authors).
*
* Bibtex-Fields used: editor
*/
AuthorList list = AuthorList.parse(authors);
for (Author author : list.getAuthors()) {
dcSchema.addContributor(author.getFirstLast(false));
}
continue;
}
/*
* ? -> Coverage
*
* Unmapped
*
* dc:coverage Text External The extent or scope of the resource.
*
* Author -> Creator
*
* Field: dc:creator
*
* Type: seq ProperName
*
* Category: External
*
* Description: The authors of the resource (listed in order of
* precedence, if significant).
*
* Bibtex-Fields used: author
*/
if (FieldName.AUTHOR.equals(field.getKey())) {
String authors = field.getValue();
AuthorList list = AuthorList.parse(authors);
for (Author author : list.getAuthors()) {
dcSchema.addCreator(author.getFirstLast(false));
}
continue;
}
if (FieldName.MONTH.equals(field.getKey())) {
// Dealt with in year
continue;
}
if (FieldName.YEAR.equals(field.getKey())) {
/*
* Year + Month -> Date
*
* Field: dc:date
*
* Type: seq Date
*
* Category: External
*
* Description: Date(s) that something interesting happened to
* the resource.
*
* Bibtex-Fields used: year, month
*/
entry.getPublicationDate().ifPresent(publicationDate -> dcSchema.addSequenceValue("dc:date", publicationDate));
continue;
}
/*
* Abstract -> Description
*
* Field: dc:description
*
* Type: Lang Alt
*
* Category: External
*
* Description: A textual description of the content of the
* resource. Multiple values may be present for different languages.
*
* Bibtex-Fields used: abstract
*/
if (FieldName.ABSTRACT.equals(field.getKey())) {
dcSchema.setDescription(field.getValue());
continue;
}
/*
* DOI -> identifier
*
* Field: dc:identifier
*
* Type: Text
*
* Category: External
*
* Description: Unique identifier of the resource.
*
* Bibtex-Fields used: doi
*/
if (FieldName.DOI.equals(field.getKey())) {
dcSchema.setIdentifier(field.getValue());
continue;
}
/*
* Publisher -> Publisher
*
* Field: dc:publisher
*
* Type: bag ProperName
*
* Category: External
*
* Description: Publishers.
*
* Bibtex-Fields used: doi
*/
if (FieldName.PUBLISHER.equals(field.getKey())) {
dcSchema.addPublisher(field.getValue());
continue;
}
/*
* Keywords -> Subject
*
* Field: dc:subject
*
* Type: bag Text
*
* Category: External
*
* Description: An unordered array of descriptive phrases or
* keywords that specify the topic of the content of the resource.
*
* Bibtex-Fields used: doi
*/
if (FieldName.KEYWORDS.equals(field.getKey())) {
String o = field.getValue();
String[] keywords = o.split(",");
for (String keyword : keywords) {
dcSchema.addSubject(keyword.trim());
}
continue;
}
/*
* Title -> Title
*
* Field: dc:title
*
* Type: Lang Alt
*
* Category: External
*
* Description: The title of the document, or the name given to the
* resource. Typically, it will be a name by which the resource is
* formally known.
*
* Bibtex-Fields used: title
*/
if (FieldName.TITLE.equals(field.getKey())) {
dcSchema.setTitle(field.getValue());
continue;
}
/*
* All others (including the bibtex key) get packaged in the
* relation attribute
*/
String o = field.getValue();
dcSchema.addRelation("bibtex/" + field.getKey() + '/' + o);
}
/*
* ? -> Format
*
* Unmapped
*
* dc:format MIMEType Internal The file format used when saving the
* resource. Tools and applications should set this property to the save
* format of the data. It may include appropriate qualifiers.
*/
dcSchema.setFormat("application/pdf");
/*
* entrytype -> Type
*
* Field: dc:type
*
* Type: bag open Choice
*
* Category: External
*
* Description: A document type; for example, novel, poem, or working
* paper.
*
* Bibtex-Fields used: entrytype
*/
TypedBibEntry typedEntry = new TypedBibEntry(entry, BibDatabaseMode.BIBTEX);
String o = typedEntry.getTypeForDisplay();
if (!o.isEmpty()) {
dcSchema.addType(o);
}
}
use of org.jabref.model.entry.BibEntry in project jabref by JabRef.
the class XMPUtil method getBibtexEntryFromDocumentInformation.
/**
* Helper function for retrieving a BibEntry from the
* PDDocumentInformation in a PDF file.
*
* To understand how to get hold of a PDDocumentInformation have a look in
* the test cases for XMPUtil.
*
* The BibEntry is build by mapping individual fields in the document
* information (like author, title, keywords) to fields in a bibtex entry.
*
* @param di The document information from which to build a BibEntry.
* @return The bibtex entry found in the document information.
*/
public static Optional<BibEntry> getBibtexEntryFromDocumentInformation(PDDocumentInformation di) {
BibEntry entry = new BibEntry();
entry.setType(BibEntry.DEFAULT_TYPE);
String s = di.getAuthor();
if (s != null) {
entry.setField(FieldName.AUTHOR, s);
}
s = di.getTitle();
if (s != null) {
entry.setField(FieldName.TITLE, s);
}
s = di.getKeywords();
if (s != null) {
entry.setField(FieldName.KEYWORDS, s);
}
s = di.getSubject();
if (s != null) {
entry.setField(FieldName.ABSTRACT, s);
}
COSDictionary dict = di.getDictionary();
for (Map.Entry<COSName, COSBase> o : dict.entrySet()) {
String key = o.getKey().getName();
if (key.startsWith("bibtex/")) {
String value = dict.getString(key);
key = key.substring("bibtex/".length());
if (BibEntry.TYPE_HEADER.equals(key)) {
entry.setType(value);
} else {
entry.setField(key, value);
}
}
}
// Return empty Optional if no values were found
return entry.getFieldNames().isEmpty() ? Optional.empty() : Optional.of(entry);
}
Aggregations