use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class PdfImporter method doXMPImport.
private void doXMPImport(String fileName, List<BibEntry> res) {
List<BibEntry> localRes = new ArrayList<>();
PdfXmpImporter importer = new PdfXmpImporter(Globals.prefs.getXMPPreferences());
Path filePath = Paths.get(fileName);
ParserResult result = importer.importDatabase(filePath, Globals.prefs.getDefaultEncoding());
if (result.hasWarnings()) {
frame.showMessage(result.getErrorMessage());
}
localRes.addAll(result.getDatabase().getEntries());
BibEntry entry;
if (localRes.isEmpty()) {
// import failed -> generate default entry
LOGGER.info("Import failed");
createNewBlankEntry(fileName).ifPresent(res::add);
return;
}
// only one entry is imported
entry = localRes.get(0);
// insert entry to database and link file
panel.getDatabase().insertEntry(entry);
panel.markBaseChanged();
FileListTableModel tm = new FileListTableModel();
Path toLink = Paths.get(fileName);
// Get a list of file directories:
List<Path> dirsS = panel.getBibDatabaseContext().getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
tm.addEntry(0, new FileListEntry(toLink.getFileName().toString(), FileUtil.shortenFileName(toLink, dirsS).toString(), ExternalFileTypes.getInstance().getExternalFileTypeByName("PDF")));
entry.setField(FieldName.FILE, tm.getStringRepresentation());
res.add(entry);
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class AuxCommandLineTest method test.
@Test
public void test() throws URISyntaxException, IOException {
InputStream originalStream = AuxCommandLineTest.class.getResourceAsStream("origin.bib");
File auxFile = Paths.get(AuxCommandLineTest.class.getResource("paper.aux").toURI()).toFile();
try (InputStreamReader originalReader = new InputStreamReader(originalStream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(importFormatPreferences).parse(originalReader);
AuxCommandLine auxCommandLine = new AuxCommandLine(auxFile.getAbsolutePath(), result.getDatabase());
BibDatabase newDB = auxCommandLine.perform();
Assert.assertNotNull(newDB);
Assert.assertEquals(2, newDB.getEntries().size());
}
}
use of org.jabref.logic.importer.ParserResult in project jabref by JabRef.
the class EntryFromFileCreatorManagerTest method testAddEntrysFromFiles.
@Test
@Ignore
public void testAddEntrysFromFiles() throws FileNotFoundException, IOException {
try (FileInputStream stream = new FileInputStream(ImportDataTest.UNLINKED_FILES_TEST_BIB);
InputStreamReader reader = new InputStreamReader(stream, StandardCharsets.UTF_8)) {
ParserResult result = new BibtexParser(mock(ImportFormatPreferences.class)).parse(reader);
BibDatabase database = result.getDatabase();
List<File> files = new ArrayList<>();
files.add(ImportDataTest.FILE_NOT_IN_DATABASE);
files.add(ImportDataTest.NOT_EXISTING_PDF);
EntryFromFileCreatorManager manager = new EntryFromFileCreatorManager();
List<String> errors = manager.addEntrysFromFiles(files, database, null, true);
/**
* One file doesn't exist, so adding it as an entry should lead to an error message.
*/
Assert.assertEquals(1, errors.size());
boolean file1Found = false;
boolean file2Found = false;
for (BibEntry entry : database.getEntries()) {
String filesInfo = entry.getField("file").get();
if (filesInfo.contains(files.get(0).getName())) {
file1Found = true;
}
if (filesInfo.contains(files.get(1).getName())) {
file2Found = true;
}
}
Assert.assertTrue(file1Found);
Assert.assertFalse(file2Found);
}
}
use of org.jabref.logic.importer.ParserResult 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.ParserResult 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();
}
Aggregations