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.dcm4che.tool.dcm2jpg.Dcm2Jpg.java

public static void main(String[] args) {
    try {//from  w ww.  j  av  a2s . c om
        CommandLine cl = parseComandLine(args);
        Dcm2Jpg main = new Dcm2Jpg();
        main.initImageWriter(cl.getOptionValue("F", "JPEG"), cl.getOptionValue("suffix"),
                cl.getOptionValue("E"), cl.getOptionValue("C"), (Number) cl.getParsedOptionValue("q"));
        if (cl.hasOption("frame"))
            main.setFrame(((Number) cl.getParsedOptionValue("frame")).intValue());
        if (cl.hasOption("c"))
            main.setWindowCenter(((Number) cl.getParsedOptionValue("c")).floatValue());
        if (cl.hasOption("w"))
            main.setWindowWidth(((Number) cl.getParsedOptionValue("w")).floatValue());
        if (cl.hasOption("window"))
            main.setWindowIndex(((Number) cl.getParsedOptionValue("window")).intValue() - 1);
        if (cl.hasOption("voilut"))
            main.setVOILUTIndex(((Number) cl.getParsedOptionValue("voilut")).intValue() - 1);
        if (cl.hasOption("overlays"))
            main.setOverlayActivationMask(parseHex(cl.getOptionValue("overlays")));
        if (cl.hasOption("ovlygray"))
            main.setOverlayGrayscaleValue(parseHex(cl.getOptionValue("ovlygray")));
        main.setPreferWindow(!cl.hasOption("uselut"));
        main.setAutoWindowing(!cl.hasOption("noauto"));
        main.setPresentationState(loadDicomObject((File) cl.getParsedOptionValue("ps")));
        @SuppressWarnings("unchecked")
        final List<String> argList = cl.getArgList();
        int argc = argList.size();
        if (argc < 2)
            throw new ParseException(rb.getString("missing"));
        File dest = new File(argList.get(argc - 1));
        if ((argc > 2 || new File(argList.get(0)).isDirectory()) && !dest.isDirectory())
            throw new ParseException(MessageFormat.format(rb.getString("nodestdir"), dest));
        for (String src : argList.subList(0, argc - 1))
            main.mconvert(new File(src), dest);
    } catch (ParseException e) {
        System.err.println("dcm2jpg: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("dcm2jpg: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

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

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*w ww  . j  a v a2s  .c om*/
        CommandLine cl = parseComandLine(args);
        Dcm2Xml main = new Dcm2Xml();
        if (cl.hasOption("x"))
            main.setXSLT(new File(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.parse(new DicomInputStream(System.in));
        } else {
            DicomInputStream dis = new DicomInputStream(new File(fname));
            try {
                main.parse(dis);
            } finally {
                dis.close();
            }
        }
    } 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.dcm4che.tool.dcmdir.DcmDir.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//from w  ww . ja  v a2 s.  com
        CommandLine cl = parseComandLine(args);
        DcmDir main = new DcmDir();
        main.setInUse(cl.hasOption("in-use"));
        main.setEncodingOptions(CLIUtils.encodingOptionsOf(cl));
        CLIUtils.configure(main.fsInfo, cl);
        main.setOriginalSequenceLength(cl.hasOption("orig-seq-len"));
        if (cl.hasOption("w")) {
            String s = cl.getOptionValue("w");
            try {
                main.setWidth(Integer.parseInt(s));
            } catch (IllegalArgumentException e) {
                throw new ParseException(MessageFormat.format(rb.getString("illegal-width"), s));
            }
        }
        try {
            List<String> argList = cl.getArgList();
            long start = System.currentTimeMillis();
            if (cl.hasOption("l")) {
                main.openForReadOnly(new File(cl.getOptionValue("l")));
                main.list();
            } else if (cl.hasOption("d")) {
                main.open(new File(cl.getOptionValue("d")));
                int num = 0;
                for (String arg : argList)
                    num += main.removeReferenceTo(new File(arg));
                main.close();
                long end = System.currentTimeMillis();
                System.out.println();
                System.out.println(
                        MessageFormat.format(rb.getString("deleted"), num, main.getFile(), (end - start)));
            } else if (cl.hasOption("p")) {
                main.open(new File(cl.getOptionValue("p")));
                int num = main.purge();
                main.close();
                long end = System.currentTimeMillis();
                System.out.println(
                        MessageFormat.format(rb.getString("purged"), num, main.getFile(), (end - start)));
            } else if (cl.hasOption("z")) {
                String fpath = cl.getOptionValue("z");
                File f = new File(fpath);
                File bak = new File(fpath + "~");
                main.compact(f, bak);
                long end = System.currentTimeMillis();
                System.out.println(MessageFormat.format(rb.getString("compacted"), f, bak.length(), f.length(),
                        (end - start)));
            } else {
                if (cl.hasOption("c")) {
                    main.create(new File(cl.getOptionValue("c")));
                } else if (cl.hasOption("u")) {
                    main.open(new File(cl.getOptionValue("u")));
                }
                main.setRecordFactory(new RecordFactory());
                int num = 0;
                for (String arg : argList)
                    num += main.addReferenceTo(new File(arg));
                main.close();
                long end = System.currentTimeMillis();
                System.out.println();
                System.out.println(
                        MessageFormat.format(rb.getString("added"), num, main.getFile(), (end - start)));
            }
        } finally {
            main.close();
        }
    } catch (ParseException e) {
        System.err.println("dcmdir: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (IOException e) {
        System.err.println("dcmdir: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.dcmdump.DcmDump.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*  ww w .j a v  a  2 s . c  o m*/
        CommandLine cl = parseComandLine(args);
        DcmDump main = new DcmDump();
        if (cl.hasOption("w")) {
            String s = cl.getOptionValue("w");
            try {
                main.setWidth(Integer.parseInt(s));
            } catch (IllegalArgumentException e) {
                throw new ParseException(MessageFormat.format(rb.getString("illegal-width"), s));
            }
        }
        String fname = fname(cl.getArgList());
        if (fname.equals("-")) {
            main.parse(new DicomInputStream(System.in));
        } else {
            DicomInputStream dis = new DicomInputStream(new File(fname));
            try {
                main.parse(dis);
            } finally {
                dis.close();
            }
        }
    } catch (ParseException e) {
        System.err.println("dcmdump: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (IOException e) {
        System.err.println("dcmdump: " + e.getMessage());
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.dcmvalidate.DcmValidate.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from w  w w .  ja v  a2  s . co  m*/
        CommandLine cl = parseComandLine(args);
        DcmValidate main = new DcmValidate();
        String iodFile = cl.getOptionValue("iod");
        if (iodFile == null)
            throw new MissingOptionException(Arrays.asList("iod"));
        main.setIOD(IOD.load(iodFile));
        List<String> fnames = cl.getArgList();
        if (fnames.isEmpty())
            throw new ParseException(rb.getString("missing"));

        for (String fname : fnames)
            validate(main, new File(fname));

    } catch (ParseException e) {
        System.err.println("DcmValidate: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (IOException e) {
        System.err.println("DcmValidate: " + e.getMessage());
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.emf2sf.Emf2sf.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//from w w  w. j  a  va 2  s .  co m
        CommandLine cl = parseComandLine(args);
        Emf2sf main = new Emf2sf();
        if (cl.hasOption("frame"))
            main.setFrames(toFrames(cl.getOptionValues("frame")));
        main.setPreserveSeriesInstanceUID(cl.hasOption("not-chseries"));
        main.setOutputDirectory(new File(cl.getOptionValue("out-dir", ".")));
        if (cl.hasOption("out-file"))
            main.setOutputFileFormat(cl.getOptionValue("out-file"));
        long start = System.currentTimeMillis();
        int n = main.extract(new File(fname(cl.getArgList())));
        long end = System.currentTimeMillis();
        System.out.println();
        System.out.println(MessageFormat.format(rb.getString("extracted"), n, (end - start) / 1000f));
    } catch (ParseException e) {
        System.err.println("emf2sf: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("emf2sf: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.findscu.FindSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from   w w w.  jav  a 2  s  .com*/
        CommandLine cl = parseComandLine(args);
        FindSCU main = new FindSCU();
        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);
        configureOutput(main, cl);
        configureCancel(main, cl);
        main.setPriority(CLIUtils.priorityOf(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.query();
            else
                for (String arg : argList)
                    main.query(new File(arg));
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("findscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("findscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.getscu.GetSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//from   w ww  .  j  a v  a2s  .  c om
        CommandLine cl = parseComandLine(args);
        GetSCU main = new GetSCU();
        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));
        configureStorageDirectory(main, 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("getscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("getscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.hl72xml.HL72Xml.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*  w ww .j av  a2s  . c  o m*/
        CommandLine cl = parseComandLine(args);
        HL72Xml main = new HL72Xml();
        if (cl.hasOption("x")) {
            String s = cl.getOptionValue("x");
            main.setXSLT(new File(s).toURI().toURL());
        }
        main.setCharacterSet(cl.getOptionValue("charset"));
        main.setIndent(cl.hasOption("I"));
        main.setIncludeNamespaceDeclaration(cl.hasOption("xmlns"));
        String fname = fname(cl.getArgList());
        if (fname.equals("-")) {
            main.parse(System.in);
        } else {
            FileInputStream dis = new FileInputStream(fname);
            try {
                main.parse(dis);
            } finally {
                dis.close();
            }
        }
    } catch (ParseException e) {
        System.err.println("hl72xml: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("hl72xml: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.hl7pix.HL7Pix.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from   w  ww.  java2 s.  c  o  m*/
        CommandLine cl = parseComandLine(args);
        HL7Pix main = new HL7Pix();
        configureConnect(main, cl);
        configureBind(main, cl);
        CLIUtils.configure(main.conn, cl);
        main.setCharacterSet(cl.getOptionValue("charset"));
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        List<String> argList = cl.getArgList();
        if (argList.isEmpty())
            throw new ParseException(rb.getString("missing"));
        try {
            main.open();
            main.query(argList.get(0), argList.subList(1, argList.size()).toArray(new String[0]));
        } finally {
            main.close();
        }
    } catch (ParseException e) {
        System.err.println("hl7pix: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("hl7pix: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}