use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class BibtexTestData method getBibtexDatabase.
public static BibDatabase getBibtexDatabase(ImportFormatPreferences importFormatPreferences) throws IOException {
String article = "@ARTICLE{HipKro03,\n" + " author = {Eric von Hippel and Georg von Krogh},\n" + " title = {Open Source Software and the \"Private-Collective\" Innovation Model: Issues for Organization Science},\n" + " journal = {Organization Science},\n" + " year = {2003},\n" + " volume = {14},\n" + " pages = {209--223},\n" + " number = {2},\n" + " address = {Institute for Operations Research and the Management Sciences (INFORMS), Linthicum, Maryland, USA},\n" + " doi = {http://dx.doi.org/10.1287/orsc.14.2.209.14992}," + "\n" + " issn = {1526-5455}," + "\n" + " publisher = {INFORMS}\n" + "}";
BibtexParser parser = new BibtexParser(importFormatPreferences);
ParserResult result = parser.parse(new StringReader(article));
return result.getDatabase();
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class BibEntryAssert method getListFromInputStream.
private static List<BibEntry> getListFromInputStream(InputStream is) throws IOException {
ParserResult result;
try (Reader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
BibtexParser parser = new BibtexParser(mock(ImportFormatPreferences.class, Answers.RETURNS_DEEP_STUBS));
result = parser.parse(reader);
}
Assert.assertNotNull(result);
Assert.assertFalse(result.isEmpty());
return result.getDatabase().getEntries();
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class BibEntryWriterTest method roundTripWithPrecedingCommentTest.
@Test
public void roundTripWithPrecedingCommentTest() throws IOException {
// @formatter:off
String bibtexEntry = "% Some random comment that should stay here" + OS.NEWLINE + "@Article{test," + OS.NEWLINE + " Author = {Foo Bar}," + OS.NEWLINE + " Journal = {International Journal of Something}," + OS.NEWLINE + " Note = {some note}," + OS.NEWLINE + " Number = {1}" + OS.NEWLINE + "}";
// @formatter:on
// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Collection<BibEntry> entries = result.getDatabase().getEntries();
BibEntry entry = entries.iterator().next();
//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();
assertEquals(bibtexEntry, actual);
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class BibEntryWriterTest method roundTripWithAppendedNewlines.
@Test
public void roundTripWithAppendedNewlines() throws IOException {
// @formatter:off
String bibtexEntry = "@Article{test," + OS.NEWLINE + " Author = {Foo Bar}," + OS.NEWLINE + " Journal = {International Journal of Something}," + OS.NEWLINE + " Note = {some note}," + OS.NEWLINE + " Number = {1}" + OS.NEWLINE + "}\n\n";
// @formatter:on
// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Collection<BibEntry> entries = result.getDatabase().getEntries();
BibEntry entry = entries.iterator().next();
//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();
// Only one appending newline is written by the writer, the rest by FileActions. So, these should be removed here.
assertEquals(bibtexEntry.substring(0, bibtexEntry.length() - 1), actual);
}
use of org.jabref.logic.importer.fileformat.BibtexParser in project jabref by JabRef.
the class BibEntryWriterTest method monthFieldSpecialSyntax.
@Test
public void monthFieldSpecialSyntax() throws IOException {
// @formatter:off
String bibtexEntry = "@Article{test," + OS.NEWLINE + " Author = {Foo Bar}," + OS.NEWLINE + " Month = mar," + OS.NEWLINE + " Number = {1}" + OS.NEWLINE + "}";
// @formatter:on
// read in bibtex string
ParserResult result = new BibtexParser(importFormatPreferences).parse(new StringReader(bibtexEntry));
Collection<BibEntry> entries = result.getDatabase().getEntries();
BibEntry entry = entries.iterator().next();
// modify month field
Set<String> fields = entry.getFieldNames();
assertTrue(fields.contains("month"));
assertEquals("#mar#", entry.getField("month").get());
//write out bibtex string
StringWriter stringWriter = new StringWriter();
writer.write(entry, stringWriter, BibDatabaseMode.BIBTEX);
String actual = stringWriter.toString();
assertEquals(bibtexEntry, actual);
}
Aggregations