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.hl7snd.HL7Snd.java

@SuppressWarnings("unchecked")
public static int main(String[] args) {
    int result = -1;
    try {/*from   w ww .  j  av  a  2s .  c  om*/
        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());                
            main.sendHL7Message(cl.getArgList());
            log.info("Order sent successfully.");
            result = 1;
        } finally {
            main.close();
        }
    } catch (ParseException e) {
        log.error("hl7snd: " + e.getMessage());
        log.error(rb.getString("try"));
        result = 0;
        //   System.exit(2);
    } catch (Exception e) {
        log.error("hl7snd: " + e.getMessage());
        log.error("Stack Trace :", e);
        result = 0;
        //   System.exit(2);
    }
    return result;
}

From source file:org.dcm4che.tool.ianscu.IanSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from ww  w . j  a va 2 s .  c  o m*/
        CommandLine cl = parseComandLine(args);
        final IanSCU main = new IanSCU();
        configureIAN(main, cl);
        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());
        main.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        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"));
            DicomFiles.scan(argList, new DicomFiles.Callback() {

                @Override
                public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
                    if (UID.InstanceAvailabilityNotificationSOPClass
                            .equals(fmi.getString(Tag.MediaStorageSOPClassUID))) {
                        return main.addIAN(fmi.getString(Tag.MediaStorageSOPInstanceUID), ds);
                    }
                    return main.addInstance(ds);
                }
            });
        }
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        main.device.setExecutor(executorService);
        main.device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            if (echo)
                main.echo();
            else
                main.sendIans();
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("ianscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("ianscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

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

@SuppressWarnings({ "unchecked" })
public static void main(String[] args) {
    try {//from  w ww. ja  va2 s.c om
        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);
            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);
    }
}

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

@SuppressWarnings("unchecked")
private static String mkkos(CommandLine cl) throws Exception {
    printNextStepMessage("Will now generate a Key Object for files in " + cl.getArgList());
    final MkKOS mkkos = new MkKOS();
    mkkos.setUIDSuffix(cl.getOptionValue("uid-suffix"));
    mkkos.setCodes(CLIUtils.loadProperties(cl.getOptionValue("code-config", "resource:code.properties"), null));
    mkkos.setDocumentTitle(mkkos.toCodeItem(documentTitleOf(cl)));
    mkkos.setKeyObjectDescription(cl.getOptionValue("desc"));
    mkkos.setSeriesNumber(cl.getOptionValue("series-no", "999"));
    mkkos.setInstanceNumber(cl.getOptionValue("inst-no", "1"));
    mkkos.setOutputFile(MkKOS.outputFileOf(cl));
    mkkos.setNoFileMetaInformation(cl.hasOption("F"));
    mkkos.setTransferSyntax(cl.getOptionValue("t", UID.ExplicitVRLittleEndian));
    mkkos.setEncodingOptions(CLIUtils.encodingOptionsOf(cl));
    DicomFiles.scan(cl.getArgList(), new DicomFiles.Callback() {

        @Override//from   w w w.j a v a 2 s  .c o m
        public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
            return mkkos.addInstance(ds);
        }
    });
    System.out.println();
    mkkos.writeKOS();
    System.out.println(MessageFormat.format(rb.getString("stored"), mkkos.getFname()));
    return mkkos.getFname();
}

From source file:org.dcm4che.tool.mkkos.MkKOS.java

@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
    try {//from ww w  .j a  v a  2  s  .  co m
        CommandLine cl = parseComandLine(args);
        final MkKOS main = new MkKOS();
        configure(main, cl);
        System.out.println(rb.getString("scanning"));
        DicomFiles.scan(cl.getArgList(), new DicomFiles.Callback() {

            @Override
            public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
                return main.addInstance(ds);
            }
        });
        System.out.println();
        main.writeKOS();
        System.out.println(MessageFormat.format(rb.getString("stored"), main.fname));
    } catch (ParseException e) {
        System.err.println("mkkos: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.mkkos.MkKOS.java

private static CommandLine parseComandLine(String[] args) throws ParseException {
    Options opts = new Options();
    CLIUtils.addCommonOptions(opts);//from  w w  w .j a v a  2 s. c o  m
    addOptions(opts);
    CommandLine cl = CLIUtils.parseComandLine(args, opts, rb, MkKOS.class);
    if (cl.getArgList().isEmpty())
        throw new ParseException(rb.getString("missing"));
    return cl;
}

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

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*  w  w w .  j  a  v  a  2s. co m*/
        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.setExecutor(executorService);
        main.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.dcm4che.tool.mppsscu.MppsSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*  w ww.j av a  2  s .c om*/
        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"));
            DicomFiles.scan(argList, new DicomFiles.Callback() {

                @Override
                public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
                    if (UID.ModalityPerformedProcedureStepSOPClass
                            .equals(fmi.getString(Tag.MediaStorageSOPClassUID))) {
                        return main.addMPPS(fmi.getString(Tag.MediaStorageSOPInstanceUID), ds);
                    }
                    return main.addInstance(ds);
                }
            });
        }
        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.dcm4che.tool.stgcmtscu.StgCmtSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from  w  w  w  . j a v a2  s. com*/
        CommandLine cl = parseComandLine(args);
        Device device = new Device("stgcmtscu");
        Connection conn = new Connection();
        device.addConnection(conn);
        ApplicationEntity ae = new ApplicationEntity("STGCMTSCU");
        device.addApplicationEntity(ae);
        ae.addConnection(conn);
        final StgCmtSCU stgcmtscu = new StgCmtSCU(ae);
        CLIUtils.configureConnect(stgcmtscu.remote, stgcmtscu.rq, cl);
        CLIUtils.configureBind(conn, stgcmtscu.ae, cl);
        CLIUtils.configure(conn, cl);
        stgcmtscu.remote.setTlsProtocols(conn.getTlsProtocols());
        stgcmtscu.remote.setTlsCipherSuites(conn.getTlsCipherSuites());
        stgcmtscu.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        stgcmtscu.setStatus(CLIUtils.getIntOption(cl, "status", 0));
        stgcmtscu.setSplitTag(getSplitTag(cl));
        stgcmtscu.setKeepAlive(cl.hasOption("keep-alive"));
        stgcmtscu.setStorageDirectory(getStorageDirectory(cl));
        stgcmtscu.setAttributes(new Attributes());
        CLIUtils.addAttributes(stgcmtscu.attrs, cl.getOptionValues("s"));
        stgcmtscu.setUIDSuffix(cl.getOptionValue("uid-suffix"));
        List<String> argList = cl.getArgList();
        boolean echo = argList.isEmpty();
        if (!echo) {
            LOG.info(rb.getString("scanning"));
            DicomFiles.scan(argList, new DicomFiles.Callback() {

                @Override
                public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
                    return stgcmtscu.addInstance(ds);
                }
            });
        }
        ExecutorService executorService = Executors.newCachedThreadPool();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        device.setExecutor(executorService);
        device.setScheduledExecutor(scheduledExecutorService);
        device.bindConnections();
        try {
            stgcmtscu.open();
            if (echo)
                stgcmtscu.echo();
            else
                stgcmtscu.sendRequests();
        } finally {
            stgcmtscu.close();
            if (conn.isListening()) {
                device.waitForNoOpenConnections();
                device.unbindConnections();
            }
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("stgcmtscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("stgcmtscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che2.tool.chess3d.Chess3D.java

public static void main(String[] args) throws ParserConfigurationException, SAXException {
    try {//from   w w w.  j av  a2  s. co  m
        CommandLine cl = parse(args);
        Chess3D extruder = new Chess3D();
        if (cl.hasOption("d")) {
            extruder.setDest(cl.getOptionValue("d"));
        }
        if (cl.hasOption("t")) {
            extruder.setThickness(Float.parseFloat(cl.getOptionValue("thickness")));
        }
        if (cl.hasOption("l")) {
            extruder.setLocation(cl.getOptionValue("l"));
        }
        if (cl.hasOption("x")) {
            extruder.setRectWidth(Integer.parseInt(cl.getOptionValue("x")));
        }
        if (cl.hasOption("y")) {
            extruder.setRectHeight(Integer.parseInt(cl.getOptionValue("y")));
        }
        if (cl.hasOption("X")) {
            extruder.setXRect(Integer.parseInt(cl.getOptionValue("X")));
        }
        if (cl.hasOption("Y")) {
            extruder.setYRect(Integer.parseInt(cl.getOptionValue("Y")));
        }
        if (cl.hasOption("Z")) {
            extruder.setZRect(Integer.parseInt(cl.getOptionValue("Z")));
        }
        if (cl.hasOption("w")) {
            extruder.setWhite((byte) Integer.decode(cl.getOptionValue("w")).intValue());
        }
        if (cl.hasOption("b")) {
            extruder.setBlack((byte) Integer.decode(cl.getOptionValue("b")).intValue());
        }
        if (cl.hasOption("win")) {
            extruder.setWindow(cl.getOptionValue("win"));
        }
        if (cl.hasOption("uid")) {
            UIDUtils.setRoot(cl.getOptionValue("uid"));
        }
        if (cl.hasOption("S")) {
            extruder.setStudyUID(UIDUtils.createUID());
        }
        if (cl.hasOption("s")) {
            extruder.setSeriesUID(UIDUtils.createUID());
        }
        List argList = cl.getArgList();
        int idx = 0;
        File dcmFile = argList.size() > 1 ? new File((String) argList.get(idx++)) : null;
        int slices = Integer.parseInt((String) argList.get(idx));
        long start = System.currentTimeMillis();
        extruder.extrude(dcmFile, slices);
        long fin = System.currentTimeMillis();
        System.out.println("\n3D chess object created in " + (fin - start) + "ms. Chess cuboid: ("
                + extruder.xRect + "," + extruder.yRect + "," + extruder.zRect + "):\n" + "width:"
                + extruder.rectWidth + " height:" + extruder.rectHeight + " slices/field:" + slices + "\n"
                + "Files (all slices):" + (slices * extruder.zRect) + " slices (" + extruder.thickness
                + " mm).\nBlack:" + (extruder.black & 0x0ff) + " White:" + (extruder.white & 0x0ff));
    } catch (IOException e) {
        e.printStackTrace();
    }
}