Search in sources :

Example 71 with BibDatabase

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

the class BibtexKeyPatternUtilTest method testAndAuthorNames.

@Test
public void testAndAuthorNames() throws ParseException {
    String bibtexString = "@ARTICLE{whatevery, author={Mari D. Herland and Mona-Iren Hauge and Ingeborg M. Helgeland}}";
    Optional<BibEntry> entry = BibtexParser.singleFromString(bibtexString, importFormatPreferences);
    assertEquals("HerlandHaugeHelgeland", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "authors3", ',', new BibDatabase()), true));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 72 with BibDatabase

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

the class BibtexKeyPatternUtilTest method testInstituteOfTechnology.

@Test
public void testInstituteOfTechnology() throws ParseException {
    Optional<BibEntry> entry = BibtexParser.singleFromString("@ARTICLE{kohn, author={{Massachusetts Institute of Technology}}}", importFormatPreferences);
    assertEquals("MIT", BibtexKeyPatternUtil.checkLegalKey(BibtexKeyPatternUtil.makeLabel(entry.get(), "auth", ',', new BibDatabase()), true));
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 73 with BibDatabase

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

the class BibtexDatabaseWriterTest method setUp.

@Before
public void setUp() {
    // Write to a string instead of to a file
    databaseWriter = new BibtexDatabaseWriter<>(StringSaveSession::new);
    database = new BibDatabase();
    metaData = new MetaData();
    bibtexContext = new BibDatabaseContext(database, metaData, new Defaults(BibDatabaseMode.BIBTEX));
    importFormatPreferences = mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS);
}
Also used : Defaults(org.jabref.model.Defaults) MetaData(org.jabref.model.metadata.MetaData) ImportFormatPreferences(org.jabref.logic.importer.ImportFormatPreferences) BibDatabase(org.jabref.model.database.BibDatabase) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) Before(org.junit.Before)

Example 74 with BibDatabase

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

the class OpenDatabaseTest method correctlyParseEncodingWithoutNewline.

/**
     * Test for #669
     */
@Test
public void correctlyParseEncodingWithoutNewline() throws IOException {
    ParserResult result = OpenDatabase.loadDatabase(bibEncodingWithoutNewline, importFormatPreferences);
    Assert.assertEquals(StandardCharsets.US_ASCII, result.getMetaData().getEncoding().get());
    BibDatabase db = result.getDatabase();
    Assert.assertEquals(Optional.of("testPreamble"), db.getPreamble());
    Collection<BibEntry> entries = db.getEntries();
    Assert.assertEquals(1, entries.size());
    BibEntry entry = entries.iterator().next();
    Assert.assertEquals(Optional.of("testArticle"), entry.getCiteKeyOptional());
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) BibDatabase(org.jabref.model.database.BibDatabase) Test(org.junit.Test)

Example 75 with BibDatabase

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

the class ArgumentProcessor method exportMatches.

private boolean exportMatches(List<ParserResult> loaded) {
    String[] data = cli.getExportMatches().split(",");
    //enables blanks within the search term:
    String searchTerm = data[0].replace("\\$", " ");
    //$ stands for a blank
    ParserResult pr = loaded.get(loaded.size() - 1);
    BibDatabaseContext databaseContext = pr.getDatabaseContext();
    BibDatabase dataBase = pr.getDatabase();
    SearchPreferences searchPreferences = new SearchPreferences(Globals.prefs);
    SearchQuery query = new SearchQuery(searchTerm, searchPreferences.isCaseSensitive(), searchPreferences.isRegularExpression());
    List<BibEntry> matches = new DatabaseSearcher(query, dataBase).getMatches();
    //export matches
    if (!matches.isEmpty()) {
        String formatName;
        //read in the export format, take default format if no format entered
        switch(data.length) {
            case 3:
                formatName = data[2];
                break;
            case 2:
                //default ExportFormat: HTML table (with Abstract & BibTeX)
                formatName = "tablerefsabsbib";
                break;
            default:
                System.err.println(Localization.lang("Output file missing").concat(". \n \t ").concat(Localization.lang("Usage")).concat(": ") + JabRefCLI.getExportMatchesSyntax());
                noGUINeeded = true;
                return false;
        }
        //export new database
        IExportFormat format = ExportFormats.getExportFormat(formatName);
        if (format == null) {
            System.err.println(Localization.lang("Unknown export format") + ": " + formatName);
        } else {
            // We have an ExportFormat instance:
            try {
                System.out.println(Localization.lang("Exporting") + ": " + data[1]);
                format.performExport(databaseContext, data[1], databaseContext.getMetaData().getEncoding().orElse(Globals.prefs.getDefaultEncoding()), matches);
            } catch (Exception ex) {
                System.err.println(Localization.lang("Could not export file") + " '" + data[1] + "': " + ExceptionUtils.getStackTrace(ex));
            }
        }
    } else {
        System.err.println(Localization.lang("No search matches."));
    }
    return true;
}
Also used : SearchQuery(org.jabref.logic.search.SearchQuery) ParserResult(org.jabref.logic.importer.ParserResult) SearchPreferences(org.jabref.preferences.SearchPreferences) BibEntry(org.jabref.model.entry.BibEntry) IExportFormat(org.jabref.logic.exporter.IExportFormat) BibDatabaseContext(org.jabref.model.database.BibDatabaseContext) BibDatabase(org.jabref.model.database.BibDatabase) JabRefException(org.jabref.JabRefException) BackingStoreException(java.util.prefs.BackingStoreException) SaveException(org.jabref.logic.exporter.SaveException) IOException(java.io.IOException) ImportException(org.jabref.logic.importer.ImportException) DatabaseSearcher(org.jabref.logic.search.DatabaseSearcher)

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