use of org.jabref.logic.search.DatabaseSearcher 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