Search in sources :

Example 6 with AuthorList

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

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

the class CreateDocBookEditors method format.

@Override
public String format(String fieldText) {
    //		<editor><firstname>L.</firstname><surname>Xue</surname></editor>
    StringBuilder sb = new StringBuilder(100);
    AuthorList al = AuthorList.parse(fieldText);
    addBody(sb, al, FieldName.EDITOR);
    return sb.toString();
}
Also used : AuthorList(org.jabref.model.entry.AuthorList)

Example 8 with AuthorList

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

Example 9 with AuthorList

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

the class XMPUtilTest method assertEqualsBibtexEntry.

public void assertEqualsBibtexEntry(BibEntry expected, BibEntry actual) {
    Assert.assertNotNull(expected);
    Assert.assertNotNull(actual);
    Assert.assertEquals(expected.getCiteKeyOptional(), actual.getCiteKeyOptional());
    Assert.assertEquals(expected.getType(), actual.getType());
    for (String field : expected.getFieldNames()) {
        if ("author".equalsIgnoreCase(field) || "editor".equalsIgnoreCase(field)) {
            AuthorList expectedAuthors = AuthorList.parse(expected.getField(field).get());
            AuthorList actualAuthors = AuthorList.parse(actual.getField(field).get());
            Assert.assertEquals(expectedAuthors, actualAuthors);
        } else {
            Assert.assertEquals("comparing " + field, expected.getField(field), actual.getField(field));
        }
    }
    Assert.assertEquals(expected.getFieldNames().size(), actual.getFieldNames().size());
}
Also used : AuthorList(org.jabref.model.entry.AuthorList)

Example 10 with AuthorList

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

the class XMPUtilTest method testResolveStrings2.

/**
     * A better testcase for resolveStrings. Makes sure that also the document information and dublin core are written
     * correctly.
     * <p/>
     * Data was contributed by Philip K.F. Hölzenspies (p.k.f.holzenspies [at] utwente.nl).
     *
     * @throws IOException
     * @throws TransformerException
     */
@Test
public void testResolveStrings2() throws IOException, TransformerException {
    try (BufferedReader fr = Files.newBufferedReader(Paths.get("src/test/resources/org/jabref/util/twente.bib"), StandardCharsets.UTF_8)) {
        ParserResult result = new BibtexParser(importFormatPreferences).parse(fr);
        Assert.assertEquals("Arvind", result.getDatabase().resolveForStrings("#Arvind#"));
        AuthorList originalAuthors = AuthorList.parse("Patterson, David and Arvind and Asanov\\'\\i{}c, Krste and Chiou, Derek and Hoe, James and Kozyrakis, Christos and Lu, S{hih-Lien} and Oskin, Mark and Rabaey, Jan and Wawrzynek, John");
        try {
            XMPUtil.writeXMP(pdfFile, result.getDatabase().getEntryByKey("Patterson06").get(), result.getDatabase(), xmpPreferences);
            // Test whether we the main function can load the bibtex correctly
            BibEntry b = XMPUtil.readXMP(pdfFile, xmpPreferences).get(0);
            Assert.assertNotNull(b);
            Assert.assertEquals(originalAuthors, AuthorList.parse(b.getField("author").get()));
            // Next check from Document Information
            try (PDDocument document = PDDocument.load(pdfFile.getAbsoluteFile())) {
                Assert.assertEquals(originalAuthors, AuthorList.parse(document.getDocumentInformation().getAuthor()));
                b = XMPUtil.getBibtexEntryFromDocumentInformation(document.getDocumentInformation()).get();
                Assert.assertEquals(originalAuthors, AuthorList.parse(b.getField("author").get()));
                // Now check from Dublin Core
                PDDocumentCatalog catalog = document.getDocumentCatalog();
                PDMetadata metaRaw = catalog.getMetadata();
                if (metaRaw == null) {
                    Assert.fail();
                    // To avoid warnings
                    return;
                }
                XMPMetadata meta = new XMPMetadata(XMLUtil.parse(metaRaw.createInputStream()));
                meta.addXMLNSMapping(XMPSchemaBibtex.NAMESPACE, XMPSchemaBibtex.class);
                List<XMPSchema> schemas = meta.getSchemasByNamespaceURI("http://purl.org/dc/elements/1.1/");
                Assert.assertEquals(1, schemas.size());
                XMPSchemaDublinCore dcSchema = (XMPSchemaDublinCore) schemas.iterator().next();
                Assert.assertNotNull(dcSchema);
                Assert.assertEquals("David Patterson", dcSchema.getCreators().get(0));
                Assert.assertEquals("Arvind", dcSchema.getCreators().get(1));
                Assert.assertEquals("Krste Asanov\\'\\i{}c", dcSchema.getCreators().get(2));
                b = XMPUtil.getBibtexEntryFromDublinCore(dcSchema, xmpPreferences).get();
                Assert.assertNotNull(b);
                Assert.assertEquals(originalAuthors, AuthorList.parse(b.getField("author").get()));
            }
        } finally {
            if (!pdfFile.delete()) {
                System.err.println("Cannot delete temporary file");
            }
        }
    }
}
Also used : XMPSchemaDublinCore(org.apache.jempbox.xmp.XMPSchemaDublinCore) ParserResult(org.jabref.logic.importer.ParserResult) BibEntry(org.jabref.model.entry.BibEntry) XMPMetadata(org.apache.jempbox.xmp.XMPMetadata) XMPSchema(org.apache.jempbox.xmp.XMPSchema) BibtexParser(org.jabref.logic.importer.fileformat.BibtexParser) PDDocument(org.apache.pdfbox.pdmodel.PDDocument) BufferedReader(java.io.BufferedReader) AuthorList(org.jabref.model.entry.AuthorList) PDMetadata(org.apache.pdfbox.pdmodel.common.PDMetadata) PDDocumentCatalog(org.apache.pdfbox.pdmodel.PDDocumentCatalog) Test(org.junit.Test)

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