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));
}
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));
}
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);
}
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());
}
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;
}
Aggregations