Search in sources :

Example 61 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class OOBibStyleTest method testInstitutionAuthor.

@Test
public void testInstitutionAuthor() throws IOException {
    OOBibStyle style = new OOBibStyle(StyleLoader.DEFAULT_NUMERICAL_STYLE_PATH, layoutFormatterPreferences);
    BibDatabase database = new BibDatabase();
    Layout l = style.getReferenceFormat("article");
    l.setPostFormatter(new OOPreFormatter());
    BibEntry entry = new BibEntry();
    entry.setType("article");
    entry.setField("author", "{JabRef Development Team}");
    entry.setField("title", "JabRef Manual");
    entry.setField("year", "2016");
    database.insertEntry(entry);
    assertEquals("<b>JabRef Development Team</b> (<b>2016</b>). <i>JabRef Manual</i>,  .", l.doLayout(entry, database));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) Layout(org.jabref.logic.layout.Layout) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 62 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class BibDatabaseContextTest method testTypeBasedOnDefaultBibtex.

@Test
public void testTypeBasedOnDefaultBibtex() {
    BibDatabaseContext bibDatabaseContext = new BibDatabaseContext(new BibDatabase(), new MetaData(), new Defaults(BibDatabaseMode.BIBTEX));
    assertEquals(BibDatabaseMode.BIBTEX, bibDatabaseContext.getMode());
    bibDatabaseContext.setMode(BibDatabaseMode.BIBLATEX);
    assertEquals(BibDatabaseMode.BIBLATEX, bibDatabaseContext.getMode());
}
Also used : MetaData(org.jabref.model.metadata.MetaData) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 63 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class CiteKeyBasedFileFinderTest method setUp.

@Before
public void setUp() throws IOException {
    when(prefs.getFieldContentParserPreferences()).thenReturn(new FieldContentParserPreferences());
    BibDatabase database = BibtexTestData.getBibtexDatabase(prefs);
    entry = database.getEntries().iterator().next();
    rootDir = temporaryFolder.getRoot().toPath();
    Path subDir = Files.createDirectory(rootDir.resolve("Organization Science"));
    Path pdfSubDir = Files.createDirectory(rootDir.resolve("pdfs"));
    Files.createFile(subDir.resolve("HipKro03 - Hello.pdf"));
    Files.createFile(rootDir.resolve("HipKro03 - Hello.pdf"));
    Path pdfSubSubDir = Files.createDirectory(pdfSubDir.resolve("sub"));
    Files.createFile(pdfSubSubDir.resolve("HipKro03-sub.pdf"));
    Files.createDirectory(rootDir.resolve("2002"));
    Path dir2003 = Files.createDirectory(rootDir.resolve("2003"));
    Files.createFile(dir2003.resolve("Paper by HipKro03.pdf"));
    Path dirTest = Files.createDirectory(rootDir.resolve("test"));
    Files.createFile(dirTest.resolve(".TEST"));
    Files.createFile(dirTest.resolve("TEST["));
    Files.createFile(dirTest.resolve("TE.ST"));
    Files.createFile(dirTest.resolve("foo.dat"));
    Path graphicsDir = Files.createDirectory(rootDir.resolve("graphicsDir"));
    Path graphicsSubDir = Files.createDirectories(graphicsDir.resolve("subDir"));
    Files.createFile(graphicsSubDir.resolve("HipKro03test.jpg"));
    Files.createFile(graphicsSubDir.resolve("HipKro03test.png"));
}
Also used : Path(java.nio.file.Path) FieldContentParserPreferences(org.jabref.logic.bibtex.FieldContentParserPreferences) BibDatabase(org.jabref.model.database.BibDatabase) Before(org.junit.Before)

Example 64 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class OOBibStyle method getAuthorYearParenthesisMarker.

/**
     * This method produces (Author, year) style citation strings in many different forms.
     *
     * @param entries           The list of BibEntry to get fields from.
     * @param database          A map of BibEntry-BibDatabase pairs.
     * @param uniquifiers       Optional parameter to separate similar citations. Elements can be null if not needed.
     * @return The formatted citation.
     */
private String getAuthorYearParenthesisMarker(List<BibEntry> entries, Map<BibEntry, BibDatabase> database, String[] uniquifiers, int[] unlimAuthors) {
    // The bibtex field providing author names, e.g. "author" or "editor".
    String authorField = getStringCitProperty(AUTHOR_FIELD);
    // The maximum number of authors to write out in full without using etal. Set to
    int maxA = getIntCitProperty(MAX_AUTHORS);
    // -1 to always write out all authors.
    // The String to separate authors from year, e.g. "; ".
    String yearSep = getStringCitProperty(YEAR_SEPARATOR);
    // The opening parenthesis.
    String startBrace = getStringCitProperty(BRACKET_BEFORE);
    // The closing parenthesis.
    String endBrace = getStringCitProperty(BRACKET_AFTER);
    // The String to separate citations from each other.
    String citationSeparator = getStringCitProperty(CITATION_SEPARATOR);
    // The bibtex field providing the year, e.g. "year".
    String yearField = getStringCitProperty(YEAR_FIELD);
    // The String to add between the two last author names, e.g. " & ".
    String andString = getStringCitProperty(AUTHOR_LAST_SEPARATOR);
    StringBuilder sb = new StringBuilder(startBrace);
    for (int j = 0; j < entries.size(); j++) {
        BibEntry currentEntry = entries.get(j);
        // Check if this entry has been nulled due to grouping with the previous entry(ies):
        if (currentEntry == null) {
            continue;
        }
        if (j > 0) {
            sb.append(citationSeparator);
        }
        BibDatabase currentDatabase = database.get(currentEntry);
        int unlimA = unlimAuthors == null ? -1 : unlimAuthors[j];
        int maxAuthors = unlimA > 0 ? unlimA : maxA;
        String author = getCitationMarkerField(currentEntry, currentDatabase, authorField);
        String authorString = createAuthorList(author, maxAuthors, andString, yearSep);
        sb.append(authorString);
        String year = getCitationMarkerField(currentEntry, currentDatabase, yearField);
        if (year != null) {
            sb.append(year);
        }
        if ((uniquifiers != null) && (uniquifiers[j] != null)) {
            sb.append(uniquifiers[j]);
        }
    }
    sb.append(endBrace);
    return sb.toString();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase)

Example 65 with BibDatabase

use of org.jabref.model.database.BibDatabase in project jabref by JabRef.

the class OOBibStyle method getAuthorYearInTextMarker.

/**
     * This method produces "Author (year)" style citation strings in many different forms.
     *
     * @param entries     The list of BibEntry to get fields from.
     * @param database    A map of BibEntry-BibDatabase pairs.
     * @param uniquefiers Optional parameters to separate similar citations. Can be null if not needed.
     * @return The formatted citation.
     */
private String getAuthorYearInTextMarker(List<BibEntry> entries, Map<BibEntry, BibDatabase> database, String[] uniquefiers, int[] unlimAuthors) {
    // The bibtex field providing author names, e.g. "author" or "editor".
    String authorField = getStringCitProperty(AUTHOR_FIELD);
    // The maximum number of authors to write out in full without using etal. Set to
    int maxA = getIntCitProperty(MAX_AUTHORS);
    // -1 to always write out all authors.
    // The String to separate authors from year, e.g. "; ".
    String yearSep = getStringCitProperty(IN_TEXT_YEAR_SEPARATOR);
    // The opening parenthesis.
    String startBrace = getStringCitProperty(BRACKET_BEFORE);
    // The closing parenthesis.
    String endBrace = getStringCitProperty(BRACKET_AFTER);
    // The String to separate citations from each other.
    String citationSeparator = getStringCitProperty(CITATION_SEPARATOR);
    // The bibtex field providing the year, e.g. "year".
    String yearField = getStringCitProperty(YEAR_FIELD);
    // The String to add between the two last author names, e.g. " & ".
    String andString = getStringCitProperty(AUTHOR_LAST_SEPARATOR_IN_TEXT);
    if (andString == null) {
        // Use the default one if no explicit separator for text is defined
        andString = getStringCitProperty(AUTHOR_LAST_SEPARATOR);
    }
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < entries.size(); i++) {
        BibEntry currentEntry = entries.get(i);
        // Check if this entry has been nulled due to grouping with the previous entry(ies):
        if (currentEntry == null) {
            continue;
        }
        BibDatabase currentDatabase = database.get(currentEntry);
        int unlimA = unlimAuthors == null ? -1 : unlimAuthors[i];
        int maxAuthors = unlimA > 0 ? unlimA : maxA;
        if (i > 0) {
            sb.append(citationSeparator);
        }
        String author = getCitationMarkerField(currentEntry, currentDatabase, authorField);
        String authorString = createAuthorList(author, maxAuthors, andString, yearSep);
        sb.append(authorString);
        sb.append(startBrace);
        String year = getCitationMarkerField(currentEntry, currentDatabase, yearField);
        if (year != null) {
            sb.append(year);
        }
        if ((uniquefiers != null) && (uniquefiers[i] != null)) {
            sb.append(uniquefiers[i]);
        }
        sb.append(endBrace);
    }
    return sb.toString();
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase)

Aggregations

BibDatabase (org.jabref.model.database.BibDatabase)88 BibEntry (org.jabref.model.entry.BibEntry)60 Test (org.junit.Test)44 ParserResult (org.jabref.logic.importer.ParserResult)20 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)15 BibDatabaseContext (org.jabref.model.database.BibDatabaseContext)15 BibtexParser (org.jabref.logic.importer.fileformat.BibtexParser)13 MetaData (org.jabref.model.metadata.MetaData)12 IOException (java.io.IOException)10 Defaults (org.jabref.model.Defaults)9 Before (org.junit.Before)9 File (java.io.File)8 InputStreamReader (java.io.InputStreamReader)8 InputStream (java.io.InputStream)7 PropertyVetoException (com.sun.star.beans.PropertyVetoException)6 UnknownPropertyException (com.sun.star.beans.UnknownPropertyException)6 WrappedTargetException (com.sun.star.lang.WrappedTargetException)6 LinkedHashMap (java.util.LinkedHashMap)5 BasePanel (org.jabref.gui.BasePanel)5