use of org.jabref.gui.importer.fetcher.EntryFetcher in project jabref by JabRef.
the class ArgumentProcessor method fetch.
/**
* Run an entry fetcher from the command line.
* <p>
* Note that this only works headlessly if the EntryFetcher does not show any GUI.
*
* @param fetchCommand A string containing both the fetcher to use (id of EntryFetcherExtension minus Fetcher) and
* the search query, separated by a :
* @return A parser result containing the entries fetched or null if an error occurred.
*/
private Optional<ParserResult> fetch(String fetchCommand) {
if ((fetchCommand == null) || !fetchCommand.contains(":") || (fetchCommand.split(":").length != 2)) {
System.out.println(Localization.lang("Expected syntax for --fetch='<name of fetcher>:<query>'"));
System.out.println(Localization.lang("The following fetchers are available:"));
return Optional.empty();
}
String[] split = fetchCommand.split(":");
String engine = split[0];
EntryFetchers fetchers = new EntryFetchers(Globals.journalAbbreviationLoader);
EntryFetcher fetcher = null;
for (EntryFetcher e : fetchers.getEntryFetchers()) {
if (engine.equalsIgnoreCase(e.getClass().getSimpleName().replace("Fetcher", ""))) {
fetcher = e;
}
}
if (fetcher == null) {
System.out.println(Localization.lang("Could not find fetcher '%0'", engine));
System.out.println(Localization.lang("The following fetchers are available:"));
for (EntryFetcher e : fetchers.getEntryFetchers()) {
System.out.println(" " + e.getClass().getSimpleName().replace("Fetcher", "").toLowerCase(Locale.ENGLISH));
}
return Optional.empty();
}
String query = split[1];
System.out.println(Localization.lang("Running query '%0' with fetcher '%1'.", query, engine) + " " + Localization.lang("Please wait..."));
Collection<BibEntry> result = new ImportInspectionCommandLine().query(query, fetcher);
if (result.isEmpty()) {
System.out.println(Localization.lang("Query '%0' with fetcher '%1' did not return any results.", query, engine));
return Optional.empty();
}
return Optional.of(new ParserResult(result));
}
Aggregations