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.dcm4che2.tool.rgb2ybr.Rgb2Ybr.java

public static void main(String[] args) {
    try {/*from www  . j  a v a2 s . co m*/
        CommandLine cl = parse(args);
        List argList = cl.getArgList();
        File ifile = new File((String) argList.get(0));
        File ofile = new File((String) argList.get(1));
        Rgb2Ybr rgb2ybr = new Rgb2Ybr();
        rgb2ybr.setPartial(cl.hasOption("p"));
        rgb2ybr.setInvers(cl.hasOption("i"));
        rgb2ybr.setOutput(ofile);
        long start = System.currentTimeMillis();
        rgb2ybr.convert(ifile);
        long fin = System.currentTimeMillis();
        System.out.println("Convert " + ifile + " to " + ofile + " in " + (fin - start) + "ms.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.dcm4che2.tool.txt2dcmsr.Txt2DcmSR.java

public static void main(String[] args) {
    try {//from   w  ww  .  j  av  a  2  s  .c  om
        CommandLine cl = parse(args);
        Txt2DcmSR txt2dcmsr = new Txt2DcmSR();
        if (cl.hasOption("ivrle")) {
            txt2dcmsr.setTransferSyntax(UID.ImplicitVRLittleEndian);
        }
        if (cl.hasOption("cs")) {
            txt2dcmsr.setCharset(cl.getOptionValue("cs"));
        }
        if (cl.hasOption("c")) {
            txt2dcmsr.loadConfiguration(new File(cl.getOptionValue("c")));
        }
        if (cl.hasOption("uid")) {
            UIDUtils.setRoot(cl.getOptionValue("uid"));
        }
        txt2dcmsr.setParagraphs(cl.hasOption("para"));
        List argList = cl.getArgList();
        File txtFile = new File((String) argList.get(0));
        File dcmFile = new File((String) argList.get(1));
        long start = System.currentTimeMillis();
        txt2dcmsr.convert(txtFile, dcmFile);
        long fin = System.currentTimeMillis();
        System.out.println("Convert " + txtFile + " to " + dcmFile + " in " + (fin - start) + "ms.");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.dcm4che2.tool.txt2dcmsr.Txt2DcmSR.java

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

    OptionBuilder.withArgName("charset");
    OptionBuilder.hasArg();/*from   ww w. ja v  a  2 s. c o m*/
    OptionBuilder.withDescription("Specific Character Set, ISO_IR 100 by default");
    opts.addOption(OptionBuilder.create("cs"));

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Configuration file specifying DICOM attribute values");
    opts.addOption(OptionBuilder.create("c"));

    OptionBuilder.withArgName("prefix");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Generate UIDs with given prefix," + "1.2.40.0.13.1.<host-ip> by default.");
    opts.addOption(OptionBuilder.create("uid"));

    opts.addOption("para", false, "Separate text in paragraphs according line delimiters");

    opts.addOption("ivrle", false, "use Implicit VR Little Endian instead "
            + "Explicit VR Little Endian Transfer Syntax for DICOM encoding.");
    opts.addOption("h", "help", false, "print this message");

    opts.addOption("V", "version", false, "print the version information and exit");
    CommandLine cl = null;
    try {
        cl = new GnuParser().parse(opts, args);
    } catch (ParseException e) {
        exit("txt2dcmsr: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = Txt2DcmSR.class.getPackage();
        System.out.println("txt2dcmsr 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.common.DetectEndOfOptionsPosixParser.java

@Override
public CommandLine parse(Options opts, String[] args, Properties props, boolean stopAtNonOption)
        throws ParseException {
    int i = args.length;
    while (--i >= 0 && !"--".equals(args[i]))
        ;/* w w w . j  av  a 2  s . c  o m*/
    CommandLine cl = super.parse(opts, i < 0 ? args : Arrays.copyOf(args, i), props, stopAtNonOption);
    if (i >= 0)
        while (++i < args.length)
            cl.getArgList().add(args[i]);
    return cl;
}

From source file:org.dcm4che3.tool.dcm2json.Dcm2Json.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from   w  w w  .j av a  2 s.co  m*/
        CommandLine cl = parseComandLine(args);
        Dcm2Json main = new Dcm2Json();
        main.setIndent(cl.hasOption("I"));
        configureBulkdata(main, cl);
        String fname = fname(cl.getArgList());
        if (fname.equals("-")) {
            main.convert(new DicomInputStream(System.in), System.out);
        } else {
            main.convert(new File(fname), System.out);
        }
    } catch (ParseException e) {
        System.err.println("dcm2xml: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("dcm2xml: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.dcm2xml.Dcm2Xml.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//  ww w. j  a v  a 2  s  .com
        CommandLine cl = parseComandLine(args);
        Dcm2Xml main = new Dcm2Xml();
        if (cl.hasOption("x"))
            main.setXSLTURL(toURL(cl.getOptionValue("x")));
        main.setIndent(cl.hasOption("I"));
        main.setIncludeKeyword(!cl.hasOption("K"));
        main.setIncludeNamespaceDeclaration(cl.hasOption("xmlns"));
        if (cl.hasOption("xml11"))
            main.setXMLVersion(XML_1_1);
        configureBulkdata(main, cl);
        String fname = fname(cl.getArgList());
        if (fname.equals("-")) {
            main.convert(new DicomInputStream(System.in), System.out);
        } else {
            main.convert(new File(fname), System.out);
        }
    } catch (ParseException e) {
        System.err.println("dcm2xml: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("dcm2xml: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.dcmdict.DcmDict.java

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

        if (cl.hasOption("private-creator")) {
            String creator = cl.getOptionValue("private-creator");
            main.dict = ElementDictionary.getElementDictionary(creator);
        } else {
            main.dict = ElementDictionary.getStandardElementDictionary();
        }
        main.queryKeys = (LinkedList<String>) cl.getArgList();
        if (hasAbbreviation(main.queryKeys)) {
            buildCamelCaseMap(main);
        }
        buildMatches(main);
        if (!main.matches.isEmpty()) {
            printMatches(main);
        }
        if (!main.queryKeys.isEmpty()) {
            buildSuggestions(main);
            System.out.println(hashtag());
            printSuggestions(main);
        }
    } catch (ParseException e) {
        LOG.error("dcmdict\t" + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.dcmgen.DcmGen.java

public static void main(String[] args) {
    CommandLine cl = null;
    try {/*from w w w.j  av a2 s .  c  o  m*/
        DcmGen main = new DcmGen();
        cl = parseComandLine(args);
        Attributes overrideAttrs = new Attributes();

        if (cl.getArgList().size() < 2) {
            throw new ParseException("Missing required arguments");
        } else {
            if (cl.hasOption("override")) {
                CLIUtils.addAttributes(overrideAttrs, cl.getOptionValues("override"));
            }
            if (cl.getArgs()[0].contains(":"))
                setCounts(cl, main, true);
            else
                setCounts(cl, main, false);
            if (cl.getArgList().size() == 3) {
                main.seedFile = new File(cl.getArgs()[1]);
                main.outputDir = new File(cl.getArgs()[2]);
            } else if (cl.getArgList().size() == 2) {
                main.seedFile = new File(cl.getArgs()[1]);
                main.outputDir = new File("./");
            }

            else {
                throw new ParseException("Too many arguments specified");
            }
            if (main.seriesCount > main.instanceCount) {
                throw new ParseException("Series count can not exceeed instance count");
            }
            main.generateDICOM(overrideAttrs);
        }

    } catch (ParseException e) {
        LOG.error("DcmGen\t" + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.hl7snd.HL7Snd.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/* w  ww .j  a v a 2 s.  c o  m*/
        CommandLine cl = parseComandLine(args);
        HL7Snd main = new HL7Snd();
        configureConnect(main.remote, cl);
        configureBind(main.conn, cl);
        CLIUtils.configure(main.conn, cl);
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        try {
            main.open();
            main.sendFiles(cl.getArgList());
        } finally {
            main.close();
        }
    } catch (ParseException e) {
        System.err.println("hl7snd: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("hl7snd: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.ihe.modality.Modality.java

@SuppressWarnings({ "unchecked" })
public static void main(String[] args) {
    try {/*from   w  ww.j  a  v a2s.com*/
        CommandLine cl = parseComandLine(args);
        if (cl.getArgList().isEmpty())
            throw new MissingOptionException(rb.getString("missing-i-file"));
        final Device device = new Device("modality");
        final Connection conn = new Connection();
        final ApplicationEntity ae = new ApplicationEntity("MODALITY");
        checkOptions(cl);
        CLIUtils.configureBind(conn, ae, cl);
        CLIUtils.configure(conn, cl);
        device.addConnection(conn);
        device.addApplicationEntity(ae);
        ae.addConnection(conn);
        final MppsSCU mppsscu = new MppsSCU(ae);
        final StoreSCU storescu = new StoreSCU(ae);
        final StgCmtSCU stgcmtscu = new StgCmtSCU(ae);
        CLIUtils.configureConnect(mppsscu.getRemoteConnection(), mppsscu.getAAssociateRQ(), cl);
        CLIUtils.configureConnect(stgcmtscu.getRemoteConnection(), stgcmtscu.getAAssociateRQ(), cl);
        CLIUtils.configureConnect(storescu.getRemoteConnection(), storescu.getAAssociateRQ(), cl);
        calledAET = storescu.getAAssociateRQ().getCalledAET();
        mppsscu.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        mppsscu.setCodes(
                CLIUtils.loadProperties(cl.getOptionValue("code-config", "resource:code.properties"), null));
        if (cl.hasOption("dc"))
            mppsscu.setFinalStatus("DISCONTINUED");
        if (cl.hasOption("dc-reason"))
            mppsscu.setDiscontinuationReason(cl.getOptionValue("dc-reason"));
        stgcmtscu.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        stgcmtscu.setStorageDirectory(StgCmtSCU.getStorageDirectory(cl));
        StoreSCU.configureRelatedSOPClass(storescu, cl);
        storescu.setUIDSuffix(StoreSCU.uidSuffixOf(cl));
        Attributes attrs = new Attributes();
        CLIUtils.addAttributes(attrs, cl.getOptionValues("s"));
        mppsscu.setAttributes(attrs);
        storescu.setAttributes(attrs);
        stgcmtscu.setAttributes(attrs);
        setTlsParams(mppsscu.getRemoteConnection(), conn);
        setTlsParams(storescu.getRemoteConnection(), conn);
        setTlsParams(stgcmtscu.getRemoteConnection(), conn);
        String tmpPrefix = "iocmtest-";
        String tmpSuffix = null;
        File tmpDir = null;
        configureTmpFile(storescu, tmpPrefix, tmpSuffix, tmpDir, cl);
        String mppsiuid = UIDUtils.createUID();
        mppsscu.setPPSUID(mppsiuid);
        if (cl.hasOption("kos-title")) {
            List<String> fname = Arrays.asList(mkkos(cl));
            scanFiles(fname, tmpPrefix, tmpSuffix, tmpDir, mppsscu, storescu, stgcmtscu);
        } else {
            stgcmtscu.setUIDSuffix(cl.getOptionValue("uid-suffix"));
            storescu.setUIDSuffix(cl.getOptionValue("uid-suffix"));
            mppsscu.setUIDSuffix(cl.getOptionValue("uid-suffix"));
            scanFiles(cl.getArgList(), tmpPrefix, tmpSuffix, tmpDir, mppsscu, storescu, stgcmtscu);
        }
        ExecutorService executorService = Executors.newCachedThreadPool();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        device.setExecutor(executorService);
        device.setScheduledExecutor(scheduledExecutorService);
        device.bindConnections();
        try {
            boolean sendMpps = cl.hasOption("mpps");
            boolean sendLateMpps = cl.hasOption("mpps-late");
            if (sendMpps || sendLateMpps) {
                sendMpps(mppsscu, sendMpps);
                addReferencedPerformedProcedureStepSequence(mppsiuid, storescu);
            } else {
                nullifyReferencedPerformedProcedureStepSequence(storescu);
            }
            sendObjects(storescu);
            if (sendLateMpps)
                sendMppsNSet(mppsscu);
            if (cl.hasOption("stgcmt"))
                sendStgCmt(stgcmtscu);
        } finally {
            if (conn.isListening()) {
                device.waitForNoOpenConnections();
                device.unbindConnections();
            }
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println(e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}