Search in sources :

Example 1 with Author

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

the class FormatNameFunction method execute.

@Override
public void execute(BstEntry context) {
    Stack<Object> stack = vm.getStack();
    if (stack.size() < 3) {
        throw new VMException("Not enough operands on stack for operation format.name$");
    }
    Object o1 = stack.pop();
    Object o2 = stack.pop();
    Object o3 = stack.pop();
    if (!(o1 instanceof String) && !(o2 instanceof Integer) && !(o3 instanceof String)) {
        // warning("A string is needed for change.case$");
        stack.push("");
        return;
    }
    String format = (String) o1;
    Integer name = (Integer) o2;
    String names = (String) o3;
    if (names == null) {
        stack.push("");
    } else {
        AuthorList a = AuthorList.parse(names);
        if (name > a.getNumberOfAuthors()) {
            throw new VMException("Author Out of Bounds. Number " + name + " invalid for " + names);
        }
        Author author = a.getAuthor(name - 1);
        stack.push(BibtexNameFormatter.formatName(author, format, vm));
    }
}
Also used : AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

Example 2 with Author

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

the class AuthorOrgSci method format.

@Override
public String format(String fieldText) {
    AuthorList a = AuthorList.parse(fieldText);
    if (a.isEmpty()) {
        return fieldText;
    }
    Author first = a.getAuthor(0);
    StringBuilder sb = new StringBuilder();
    sb.append(first.getLastFirst(true));
    for (int i = 1; i < a.getNumberOfAuthors(); i++) {
        sb.append(", ").append(a.getAuthor(i).getFirstLast(true));
    }
    return sb.toString();
}
Also used : AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

Example 3 with Author

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

the class MSBibEntry method getSpecificAuthors.

private List<MsBibAuthor> getSpecificAuthors(String type, Element authors) {
    List<MsBibAuthor> result = null;
    NodeList nodeLst = authors.getElementsByTagNameNS("*", type);
    if (nodeLst.getLength() <= 0) {
        return result;
    }
    nodeLst = ((Element) nodeLst.item(0)).getElementsByTagNameNS("*", "NameList");
    if (nodeLst.getLength() <= 0) {
        return result;
    }
    NodeList person = ((Element) nodeLst.item(0)).getElementsByTagNameNS("*", "Person");
    if (person.getLength() <= 0) {
        return result;
    }
    result = new LinkedList<>();
    for (int i = 0; i < person.getLength(); i++) {
        NodeList firstName = ((Element) person.item(i)).getElementsByTagNameNS("*", "First");
        NodeList lastName = ((Element) person.item(i)).getElementsByTagNameNS("*", "Last");
        NodeList middleName = ((Element) person.item(i)).getElementsByTagNameNS("*", "Middle");
        StringBuilder sb = new StringBuilder();
        if (firstName.getLength() > 0) {
            sb.append(firstName.item(0).getTextContent());
            sb.append(" ");
        }
        if (middleName.getLength() > 0) {
            sb.append(middleName.item(0).getTextContent());
            sb.append(" ");
        }
        if (lastName.getLength() > 0) {
            sb.append(lastName.item(0).getTextContent());
        }
        AuthorList authorList = AuthorList.parse(sb.toString());
        for (Author author : authorList.getAuthors()) {
            result.add(new MsBibAuthor(author));
        }
    }
    return result;
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

Example 4 with Author

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

the class MSBibConverter method getAuthors.

private static List<MsBibAuthor> getAuthors(String authors) {
    List<MsBibAuthor> result = new ArrayList<>();
    boolean corporate = false;
    //Only one corporate authors is supported
    if (authors.startsWith("{") && authors.endsWith("}")) {
        corporate = true;
    }
    AuthorList authorList = AuthorList.parse(authors);
    for (Author author : authorList.getAuthors()) {
        result.add(new MsBibAuthor(author, corporate));
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author)

Example 5 with Author

use of org.jabref.model.entry.Author 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);
    }
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) TypedBibEntry(org.jabref.logic.TypedBibEntry) TreeSet(java.util.TreeSet) AuthorList(org.jabref.model.entry.AuthorList) Author(org.jabref.model.entry.Author) TypedBibEntry(org.jabref.logic.TypedBibEntry)

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