Search in sources :

Example 11 with AuthorList

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

the class CrossRef method toAuthors.

private String toAuthors(JSONArray authors) {
    if (authors == null) {
        return "";
    }
    // input: list of {"given":"A.","family":"Riel","affiliation":[]}
    AuthorList authorsParsed = new AuthorList();
    for (int i = 0; i < authors.length(); i++) {
        JSONObject author = authors.getJSONObject(i);
        authorsParsed.addAuthor(author.optString("given", ""), "", "", author.optString("family", ""), "");
    }
    return authorsParsed.getAsFirstLastNamesWithAnd();
}
Also used : JSONObject(org.json.JSONObject) AuthorList(org.jabref.model.entry.AuthorList)

Example 12 with AuthorList

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

the class NormalizeNamesFormatter method format.

@Override
public String format(String nameList) {
    Objects.requireNonNull(nameList);
    AuthorList authorList = AuthorList.parse(nameList);
    return authorList.getAsLastFirstNamesWithAnd(false);
}
Also used : AuthorList(org.jabref.model.entry.AuthorList)

Example 13 with AuthorList

use of org.jabref.model.entry.AuthorList 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 14 with AuthorList

use of org.jabref.model.entry.AuthorList 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 15 with AuthorList

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

the class CreateDocBookAuthors method format.

@Override
public String format(String fieldText) {
    StringBuilder sb = new StringBuilder(100);
    AuthorList al = AuthorList.parse(fieldText);
    addBody(sb, al, FieldName.AUTHOR);
    return sb.toString();
}
Also used : AuthorList(org.jabref.model.entry.AuthorList)

Aggregations

AuthorList (org.jabref.model.entry.AuthorList)19 Author (org.jabref.model.entry.Author)8 BibEntry (org.jabref.model.entry.BibEntry)4 ArrayList (java.util.ArrayList)2 TreeSet (java.util.TreeSet)2 LayoutFormatter (org.jabref.logic.layout.LayoutFormatter)2 FieldName (org.jabref.model.entry.FieldName)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 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