Search in sources :

Example 1 with OutputPrinter

use of org.jabref.logic.importer.OutputPrinter in project jabref by JabRef.

the class ArgumentProcessor method importFile.

private static Optional<ParserResult> importFile(String argument) {
    String[] data = argument.split(",");
    String address = data[0];
    Path file;
    if (address.startsWith("http://") || address.startsWith("https://") || address.startsWith("ftp://")) {
        // Download web resource to temporary file
        try {
            file = new URLDownload(address).toTemporaryFile();
        } catch (IOException e) {
            System.err.println(Localization.lang("Problem downloading from %1", address) + e.getLocalizedMessage());
            return Optional.empty();
        }
    } else {
        if (OS.WINDOWS) {
            file = Paths.get(address);
        } else {
            file = Paths.get(address.replace("~", System.getProperty("user.home")));
        }
    }
    String importFormat;
    if (data.length > 1) {
        importFormat = data[1];
    } else {
        importFormat = "*";
    }
    Optional<ParserResult> importResult = importFile(file, importFormat);
    importResult.ifPresent(result -> {
        OutputPrinter printer = new SystemOutputPrinter();
        if (result.hasWarnings()) {
            printer.showMessage(result.getErrorMessage());
        }
    });
    return importResult;
}
Also used : Path(java.nio.file.Path) ParserResult(org.jabref.logic.importer.ParserResult) IOException(java.io.IOException) URLDownload(org.jabref.logic.net.URLDownload) OutputPrinter(org.jabref.logic.importer.OutputPrinter)

Aggregations

IOException (java.io.IOException)1 Path (java.nio.file.Path)1 OutputPrinter (org.jabref.logic.importer.OutputPrinter)1 ParserResult (org.jabref.logic.importer.ParserResult)1 URLDownload (org.jabref.logic.net.URLDownload)1