Example usage for org.apache.commons.cli CommandLine getArgList

List of usage examples for org.apache.commons.cli CommandLine getArgList

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getArgList.

Prototype

public List getArgList() 

Source Link

Document

Retrieve any left-over non-recognized options and arguments

Usage

From source file:org.dcm4che3.tool.jpg2dcm.Jpg2Dcm.java

public static void main(String[] args) {
    try {//from w ww  . j  av  a  2  s .c o m
        CommandLine cl = parse(args);
        Jpg2Dcm jpg2Dcm = new Jpg2Dcm();
        if (cl.hasOption(LONG_OPT_CHARSET)) {
            jpg2Dcm.setCharset(cl.getOptionValue(LONG_OPT_CHARSET));
        }
        if (cl.hasOption(LONG_OPT_UID_PREFIX)) {
            UIDUtils.setRoot(cl.getOptionValue(LONG_OPT_UID_PREFIX));
        }
        if (cl.hasOption(LONG_OPT_MPEG)) {
            jpg2Dcm.setTransferSyntax(UID.MPEG2);
        }
        if (cl.hasOption(LONG_OPT_TRANSFER_SYNTAX)) {
            jpg2Dcm.setTransferSyntax(cl.getOptionValue(LONG_OPT_TRANSFER_SYNTAX));
        }
        jpg2Dcm.setNoAPPn(cl.hasOption(LONG_OPT_NO_APPN));

        @SuppressWarnings("rawtypes")
        List argList = cl.getArgList();
        File jpgFile = new File((String) argList.get(0));
        File dcmFile = new File((String) argList.get(1));
        long start = System.currentTimeMillis();
        jpg2Dcm.convert(cl, jpgFile, dcmFile);
        long fin = System.currentTimeMillis();
        LOG.info("Encapsulated " + jpgFile + " to " + dcmFile + " in " + (fin - start) + "ms.");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.dcm4che3.tool.jpg2dcm.Jpg2Dcm.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();

    OptionBuilder.withArgName("code");
    OptionBuilder.hasArg();//from   w  ww .j av a2  s.  c  o m
    OptionBuilder.withDescription(OPT_CHARSET_DESC);
    OptionBuilder.withLongOpt(LONG_OPT_CHARSET);
    opts.addOption(OptionBuilder.create());

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(OPT_AUGMENT_CONFIG_DESC);
    opts.addOption(OptionBuilder.create("c"));

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(OPT_REPLACE_CONFIG_DESC);
    opts.addOption(OptionBuilder.create("C"));

    OptionBuilder.withArgName("prefix");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(OPT_UID_PREFIX_DESC);
    OptionBuilder.withLongOpt(LONG_OPT_UID_PREFIX);
    opts.addOption(OptionBuilder.create());

    OptionBuilder.withArgName("uid");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(OPT_TRANSFER_SYNTAX_DESC);
    OptionBuilder.withLongOpt(LONG_OPT_TRANSFER_SYNTAX);
    opts.addOption(OptionBuilder.create());

    opts.addOption(null, LONG_OPT_MPEG, false, OPT_MPEG_DESC);

    opts.addOption(null, LONG_OPT_NO_APPN, false, OPT_NO_APPN_DESC);

    opts.addOption("h", "help", false, OPT_HELP_DESC);
    opts.addOption("V", "version", false, OPT_VERSION_DESC);

    CommandLine cl = null;
    try {
        cl = new PosixParser().parse(opts, args);
    } catch (ParseException e) {
        exit("jpg2dcm: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Jpg2Dcm.class.getPackage();
        LOG.info("jpg2dcm v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().size() != 2) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }

    return cl;
}

From source file:org.dcm4che3.tool.movescu.MoveSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//  w  w w .ja  va2s  . com
        CommandLine cl = parseComandLine(args);
        MoveSCU main = new MoveSCU();
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(main.conn, main.ae, cl);
        CLIUtils.configure(main.conn, cl);
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        configureServiceClass(main, cl);
        configureKeys(main, cl);
        main.setPriority(CLIUtils.priorityOf(cl));
        main.setDestination(destinationOf(cl));
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        main.device.setExecutor(executorService);
        main.device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            List<String> argList = cl.getArgList();
            if (argList.isEmpty())
                main.retrieve();
            else
                for (String arg : argList)
                    main.retrieve(new File(arg));
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("movescu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("movescu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.mppsscu.MppsSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//from  www  .j  a v a2  s .co m
        CommandLine cl = parseComandLine(args);
        Device device = new Device("mppsscu");
        Connection conn = new Connection();
        device.addConnection(conn);
        ApplicationEntity ae = new ApplicationEntity("MPPSSCU");
        device.addApplicationEntity(ae);
        ae.addConnection(conn);
        final MppsSCU main = new MppsSCU(ae);
        configureMPPS(main, cl);
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(conn, main.ae, cl);
        CLIUtils.configure(conn, cl);
        main.remote.setTlsProtocols(conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(conn.getTlsCipherSuites());
        main.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        main.setAttributes(new Attributes());
        CLIUtils.addAttributes(main.attrs, cl.getOptionValues("s"));
        main.setUIDSuffix(cl.getOptionValue("uid-suffix"));
        List<String> argList = cl.getArgList();
        boolean echo = argList.isEmpty();
        if (!echo) {
            System.out.println(rb.getString("scanning"));
            main.scanFiles(argList, true);
        }
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        device.setExecutor(executorService);
        device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            if (echo)
                main.echo();
            else {
                main.createMpps();
                main.updateMpps();
            }
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("mppsscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("mppsscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.qc.QC.java

private static QC initArgs(CommandLine cl) throws MissingArgumentException, IndexOutOfBoundsException {

    String codeComponents = null;
    String parsedURL = (String) cl.getArgList().get(0);
    String operation = (String) cl.getArgList().get(1);

    if (cl.getArgList().size() > 2)
        codeComponents = (String) cl.getArgList().get(2);

    QC qc = new QC(parsedURL, codeComponents != null ? toCode(codeComponents) : null,
            QCOperation.valueOf(operation.toUpperCase()));

    if (cl.getArgList().size() > 3) {
        qc.setTargetStudyUID((String) cl.getArgList().get(3));
    }/*from   www.java  2 s . c o m*/

    return qc;
}

From source file:org.dcm4che3.tool.stowrs.StowRS.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    CommandLine cl = null;
    try {/*  w  ww  .  j a va 2 s  .  co m*/

        cl = parseComandLine(args);
        StowRS instance = new StowRS();
        if (cl.hasOption("m"))
            instance.keys = configureKeys(instance, cl);
        if (!cl.hasOption("u")) {
            throw new IllegalArgumentException("Missing url");
        } else {
            instance.URL = cl.getOptionValue("u");
        }

        if (cl.hasOption("t")) {
            if (!cl.hasOption("ts")) {
                throw new MissingArgumentException("Missing option required option ts when sending metadata");
            } else {
                instance.setTransferSyntax(cl.getOptionValue("ts"));
            }

            String mediaTypeString = cl.getOptionValue("t");
            if ("JSON".equalsIgnoreCase(mediaTypeString)) {
                instance.mediaType = StowMetaDataType.JSON;
            } else if ("XML".equalsIgnoreCase(mediaTypeString)) {
                instance.mediaType = StowMetaDataType.XML;
            } else {
                throw new IllegalArgumentException(
                        "Bad Type " + mediaTypeString + " specified for metadata, specify either XML or JSON");
            }
        } else {
            instance.mediaType = StowMetaDataType.NO_METADATA_DICOM;
        }

        for (Iterator<String> iter = cl.getArgList().iterator(); iter.hasNext();) {
            instance.files.add(new File(iter.next()));
        }

        if (instance.files.isEmpty())
            throw new IllegalArgumentException("Missing files");

        instance.stow();

    } catch (Exception e) {
        if (!cl.hasOption("u")) {
            LOG.error("stowrs: missing required option -u");
            LOG.error("Try 'stowrs --help' for more information.");
            System.exit(2);
        } else {
            LOG.error("Error: \n", e);
            e.printStackTrace();
        }

    }
}

From source file:org.dcm4che3.tool.syslog.Syslog.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//from   w w  w. j av  a  2  s .  c  o m
        CommandLine cl = parseComandLine(args);
        Syslog main = new Syslog();
        configureConnect(main.remote, cl);
        main.setProtocol(toProtocol(cl));
        configureAuditLogger(main.auditLogger, cl);
        main.setDelayBetweenMessages(CLIUtils.getIntOption(cl, "delay", 0));
        configureBind(main.conn, cl);
        CLIUtils.configure(main.conn, cl);
        try {
            main.init();
            main.sendFiles(cl.getArgList());
            main.waitForNoQueuedMessages();
        } finally {
            main.close();
        }
    } catch (ParseException e) {
        System.err.println("syslog: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("syslog: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4chee.xds2.src.tool.pnrsnd.PnRSnd.java

private void addDocument(CommandLine cl, PnRRequest pnrReq)
        throws FileNotFoundException, IOException, java.text.ParseException {
    @SuppressWarnings("unchecked")
    List<String> args = cl.getArgList();
    for (int i = 0, len = args.size(); i < len; i++) {
        String docUID = getProperty("doc.UID", i);
        if ("new()".equals(docUID)) {
            docUID = UIDUtils.createUID();
            log.info("### documentUID created:" + docUID);
        }//from   w w w  .  j  a v  a  2 s . co m
        File docFile = new File(args.get(i));
        byte[] buffer = new byte[(int) docFile.length()];
        FileInputStream fis = new FileInputStream(docFile);
        fis.read(buffer);
        DocumentEntry doc = pnrReq.addDocumentEntry(docUID, buffer, getProperty("mime", i));
        addAuthor(doc.addAuthor());
        doc.addConfidentialityCode(new Code(getProperty("confidentialityCode", i)));
        doc.addEventCodeList(new Code(getProperty("eventCode", i)));
        doc.setClassCode(new Code(getProperty("classCode", i)));
        doc.setFormatCode(new Code(getProperty("formatCode", i)));
        doc.setHealthcareFacilityTypeCode(new Code(getProperty("healthcareFacilityTypeCode", i)));
        doc.setPracticeSettingCode(new Code(getProperty("practiceSettingCode", i)));
        doc.setTypeCode(new Code(getProperty("typeCode", i)));
        doc.setCreationTime(Util.toDate(getProperty("creationTime", i)));
        doc.setServiceStartTime(Util.toDate(getProperty("serviceStartTime", i)));
        doc.setServiceStopTime(Util.toDate(getProperty("serviceStopTime", i)));
        doc.setLanguageCode(getProperty("languageCode", i));
        addOptional(doc);
    }
}

From source file:org.dcm4chee.xds2.src.tool.pnrsnd.PnRSnd.java

private static void showCodes(CommandLine cl) {
    @SuppressWarnings("unchecked")
    Collection<String> args = cl.getArgList();
    log.info("Show codes of affinity domain(s):" + args);
    XADCfgRepository rep = new XADCfgRepository(null, "../conf/affinitydomain");
    if (args.isEmpty() || args.contains("*")) {
        args = rep.getAffinityDomains();
    }//  w w  w.ja  v  a2s.  co  m
    for (String domain : args) {
        AffinityDomainCodes adCodes = rep.getAffinityDomainCodes(domain);
        log.info("  Affinity domain:" + domain + " (source:" + adCodes.getAffinityDomain() + "):");
        for (String codeType : adCodes.getCodeTypes()) {
            log.info("CodeType:" + codeType);
            for (Code c : adCodes.getCodes(codeType)) {
                log.info("    " + c);
            }
        }
    }
}

From source file:org.dfotos.rssfilter.App.java

/**
 * Execution begins here.//w ww  .  java 2  s . c o m
 * 
 * @param args Command-line arguments.
 * @throws IOException Something else went wrong.
 */
public static void main(final String[] args) throws IOException {
    String loggingConf = "/logging.properties";
    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    initCmdLineOptions(options);
    CommandLine cmdLine;
    try {
        cmdLine = parser.parse(options, args);
    } catch (ParseException exp) {
        System.err.println(exp.getMessage());
        return;
    }
    if (cmdLine.hasOption("q")) {
        loggingConf = "/logging.q.properties";
    } else if (cmdLine.hasOption("v")) {
        loggingConf = "/logging.v.properties";
    }
    if (cmdLine.hasOption("h")) {
        printHelp(options);
        return;
    }
    if (cmdLine.hasOption("c")) {
        configFileName = cmdLine.getOptionValue("c");
    }
    LogHelper.initLogs(loggingConf);
    try {
        readConfig();
        getData().init();
        if (cmdLine.getArgList().isEmpty()) {
            printHelp(options);
        } else {
            for (final Object arg : cmdLine.getArgList()) {
                execCmd((String) arg);
            }
        }
    } catch (final Throwable ex) {
        LOG.log(Level.SEVERE, "", ex);
    } finally {
        final BeforeExit exit = new BeforeExit();
        try {
            exit.run(new ArrayList<String>(0));
        } catch (final Exception ex) {
            LOG.log(Level.SEVERE, "Exception running CleanupCmd: ", ex);
        }
    }
}