Search in sources :

Example 11 with Author

use of org.jabref.model.entry.Author in project jabref by JabRef.

the class Authors method format.

@Override
public String format(String fieldText) {
    if (fieldText == null) {
        return "";
    }
    StringBuilder sb = new StringBuilder();
    AuthorList al = AuthorList.parse(fieldText);
    if ((maxAuthors < 0) || (al.getNumberOfAuthors() <= maxAuthors)) {
        for (int i = 0; i < al.getNumberOfAuthors(); i++) {
            Author a = al.getAuthor(i);
            addSingleName(sb, a, (flMode == Authors.FIRST_FIRST) || ((flMode == Authors.LF_FF) && (i > 0)));
            if (i < (al.getNumberOfAuthors() - 2)) {
                sb.append(separator);
            } else if (i < (al.getNumberOfAuthors() - 1)) {
                sb.append(lastSeparator);
            }
        }
    } else {
        for (int i = 0; i < Math.min(al.getNumberOfAuthors() - 1, authorNumberEtAl); i++) {
            if (i > 0) {
                sb.append(separator);
            }
            addSingleName(sb, al.getAuthor(i), flMode == Authors.FIRST_FIRST);
        }
        sb.append(etAlString);
    }
    return sb.toString();
}
Also used : AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

Example 12 with Author

use of org.jabref.model.entry.Author in project jabref by JabRef.

the class CreateDocBookAuthors method addBody.

public void addBody(StringBuilder sb, AuthorList al, String tagName) {
    for (int i = 0; i < al.getNumberOfAuthors(); i++) {
        sb.append('<').append(tagName).append('>');
        Author a = al.getAuthor(i);
        a.getFirst().filter(first -> !first.isEmpty()).ifPresent(first -> sb.append("<firstname>").append(CreateDocBookAuthors.XML_CHARS.format(first)).append("</firstname>"));
        a.getVon().filter(von -> !von.isEmpty()).ifPresent(von -> sb.append("<othername>").append(CreateDocBookAuthors.XML_CHARS.format(von)).append("</othername>"));
        a.getLast().filter(last -> !last.isEmpty()).ifPresent(last -> {
            sb.append("<surname>").append(CreateDocBookAuthors.XML_CHARS.format(last));
            a.getJr().filter(jr -> !jr.isEmpty()).ifPresent(jr -> sb.append(' ').append(CreateDocBookAuthors.XML_CHARS.format(jr)));
            sb.append("</surname>");
        });
        if (i < (al.getNumberOfAuthors() - 1)) {
            sb.append("</").append(tagName).append(">\n       ");
        } else {
            sb.append("</").append(tagName).append('>');
        }
    }
}
Also used : AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author) FieldName(org.jabref.model.entry.FieldName) LayoutFormatter(org.jabref.logic.layout.LayoutFormatter) Author(org.jabref.model.entry.Author)

Example 13 with Author

use of org.jabref.model.entry.Author in project jabref by JabRef.

the class OOBibStyle method getAuthorLastName.

/**
     * Look up the nth author and return the proper last name for citation markers.
     *
     * @param al     The author list.
     * @param number The number of the author to return.
     * @return The author name, or an empty String if inapplicable.
     */
private String getAuthorLastName(AuthorList al, int number) {
    StringBuilder sb = new StringBuilder();
    if (al.getNumberOfAuthors() > number) {
        Author a = al.getAuthor(number);
        a.getVon().filter(von -> !von.isEmpty()).ifPresent(von -> sb.append(von).append(' '));
        sb.append(a.getLast().orElse(""));
    }
    return sb.toString();
}
Also used : SortedSet(java.util.SortedSet) FieldName(org.jabref.model.entry.FieldName) StringUtil(org.jabref.model.strings.StringUtil) BibDatabase(org.jabref.model.database.BibDatabase) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) Layout(org.jabref.logic.layout.Layout) Author(org.jabref.model.entry.Author) Locale(java.util.Locale) LayoutFormatter(org.jabref.logic.layout.LayoutFormatter) Map(java.util.Map) BibEntry(org.jabref.model.entry.BibEntry) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Reader(java.io.Reader) LayoutFormatterPreferences(org.jabref.logic.layout.LayoutFormatterPreferences) InputStreamReader(java.io.InputStreamReader) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) AuthorList(org.jabref.model.entry.AuthorList) List(java.util.List) StringReader(java.io.StringReader) LayoutHelper(org.jabref.logic.layout.LayoutHelper) Optional(java.util.Optional) Log(org.apache.commons.logging.Log) Pattern(java.util.regex.Pattern) LogFactory(org.apache.commons.logging.LogFactory) Collections(java.util.Collections) InputStream(java.io.InputStream) Author(org.jabref.model.entry.Author)

Aggregations

Author (org.jabref.model.entry.Author)13 AuthorList (org.jabref.model.entry.AuthorList)8 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 LayoutFormatter (org.jabref.logic.layout.LayoutFormatter)2 BibEntry (org.jabref.model.entry.BibEntry)2 FieldName (org.jabref.model.entry.FieldName)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1