Example usage for org.apache.commons.cli MissingOptionException MissingOptionException

List of usage examples for org.apache.commons.cli MissingOptionException MissingOptionException

Introduction

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

Prototype

public MissingOptionException(List missingOptions) 

Source Link

Document

Constructs a new MissingSelectedException with the specified list of missing options.

Usage

From source file:org.craftercms.commons.crypto.impl.EncryptionTool.java

public static final void main(String... args) {
    Options options = createOptions();/*from ww w  .j  a v  a2  s .  co m*/
    CommandLineParser parser = new DefaultParser();

    try {
        CommandLine line = parser.parse(options, args);

        if (line.hasOption(HELP_OPTION)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("java -jar JARNAME [-e|-d|-e64|-d64 text] [-p password] [-s salt]", options);
        } else if (line.hasOption(ENC_OPTION)) {
            encrypt(line);
        } else if (line.hasOption(DEC_OPTION)) {
            decrypt(line);
        } else if (line.hasOption(ENC_BASE64_OPTION)) {
            encodeBase64(line);
        } else if (line.hasOption(DEC_BASE64_OPTION)) {
            decodeBase64(line);
        } else {
            throw new MissingOptionException(
                    "Either -" + ENC_OPTION + ", -" + DEC_OPTION + ", -" + ENC_BASE64_OPTION + ", -"
                            + DEC_BASE64_OPTION + " or -" + HELP_OPTION + " must be provided");
        }
    } catch (ParseException e) {
        System.err.println("Error parsing command line. Reason:");
        e.printStackTrace(System.err);
    } catch (CryptoException e) {
        System.err.println("Error while executing encryption/decryption. Reason:");
        e.printStackTrace(System.err);
    }
}

From source file:org.craftercms.commons.crypto.impl.EncryptionTool.java

private static TextEncryptor createEncryptor(CommandLine line) throws MissingOptionException, CryptoException {
    List<String> missingOptions = new ArrayList<>();
    String password = null;//from   www  .  j  ava  2s  .co  m
    String salt = null;

    if (line.hasOption(PASS_OPTION)) {
        password = line.getOptionValue(PASS_OPTION);
    } else {
        missingOptions.add("-" + PASS_OPTION);
    }

    if (line.hasOption(SALT_OPTION)) {
        salt = line.getOptionValue(SALT_OPTION);
    } else {
        missingOptions.add("-" + SALT_OPTION);
    }

    if (CollectionUtils.isNotEmpty(missingOptions)) {
        throw new MissingOptionException(missingOptions);
    }

    return new PbkAesTextEncryptor(password, salt);
}

From source file:org.dcm4che.tool.common.CLIUtils.java

public static void configureConnect(Connection conn, AAssociateRQ rq, CommandLine cl) throws ParseException {
    if (!cl.hasOption("c"))
        throw new MissingOptionException(rb.getString("missing-connect-opt"));
    String aeAtHostPort = cl.getOptionValue("c");
    String[] aeHostPort = split(aeAtHostPort, '@', 0);
    if (aeHostPort[1] == null)
        throw new ParseException(rb.getString("invalid-connect-opt"));

    String[] hostPort = split(aeHostPort[1], ':', 0);
    if (hostPort[1] == null)
        throw new ParseException(rb.getString("invalid-connect-opt"));

    rq.setCalledAET(aeHostPort[0]);/*from   w ww .j a  va 2 s.c om*/
    conn.setHostname(hostPort[0]);
    conn.setPort(Integer.parseInt(hostPort[1]));

    conn.setHttpProxy(cl.getOptionValue("proxy"));

    if (cl.hasOption("user"))
        rq.setUserIdentityRQ(cl.hasOption("user-pass")
                ? new UserIdentityRQ(cl.getOptionValue("user"), cl.getOptionValue("user-pass").toCharArray())
                : new UserIdentityRQ(cl.getOptionValue("user"), cl.hasOption("user-rsp")));
}

From source file:org.dcm4che.tool.common.CLIUtils.java

public static void configureBindServer(Connection conn, ApplicationEntity ae, CommandLine cl)
        throws ParseException {
    if (!cl.hasOption("b"))
        throw new MissingOptionException(rb.getString("missing-bind-opt"));
    String aeAtHostPort = cl.getOptionValue("b");
    String[] aeAtHostAndPort = split(aeAtHostPort, ':', 1);
    conn.setPort(Integer.parseInt(aeAtHostAndPort[1]));
    if (aeAtHostAndPort[0] != null) {
        String[] aeHost = split(aeAtHostAndPort[0], '@', 0);
        ae.setAETitle(aeHost[0]);/*from  w  w w  . j  av a  2 s.  c  o  m*/
        if (aeHost[1] != null)
            conn.setHostname(aeHost[1]);
    }
}

From source file:org.dcm4che.tool.dcmqrscp.DcmQRSCP.java

private static void configureDicomFileSet(DcmQRSCP main, CommandLine cl) throws ParseException {
    if (!cl.hasOption("dicomdir"))
        throw new MissingOptionException(rb.getString("missing-dicomdir"));
    main.setDicomDirectory(new File(cl.getOptionValue("dicomdir")));
    main.setFilePathFormat(//w w w .  j a  v  a 2 s  . c  o m
            cl.getOptionValue("filepath", "DICOM/{0020000D,hash}/{0020000E,hash}/{00080018,hash}"));
    main.setRecordFactory(new RecordFactory());
}

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

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from   ww w. j  a  va2  s .  c  o  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.hl7pix.HL7Pix.java

private static void configureConnect(HL7Pix hl7pix, CommandLine cl)
        throws MissingOptionException, ParseException {
    String appAtHostPort = cl.getOptionValue("c");
    if (appAtHostPort == null)
        throw new MissingOptionException(rb.getString("missing-connect-opt"));

    String[] appHostPort = HL7Segment.split(appAtHostPort, '@');
    if (appHostPort.length == 1)
        throw new ParseException(rb.getString("invalid-connect-opt"));

    String[] hostPort = HL7Segment.split(appHostPort[1], ':');
    if (hostPort.length == 1)
        throw new ParseException(rb.getString("invalid-connect-opt"));

    hl7pix.setReceivingApplication(appHostPort[0]);
    hl7pix.remote.setHostname(hostPort[0]);
    hl7pix.remote.setPort(Integer.parseInt(hostPort[1]));
}

From source file:org.dcm4che.tool.hl7rcv.HL7Rcv.java

private static void configureBindServer(Connection conn, CommandLine cl) throws ParseException {
    if (!cl.hasOption("b"))
        throw new MissingOptionException(CLIUtils.rb.getString("missing-bind-opt"));
    String aeAtHostPort = cl.getOptionValue("b");
    String[] hostAndPort = StringUtils.split(aeAtHostPort, ':');
    int portIndex = hostAndPort.length - 1;
    conn.setPort(Integer.parseInt(hostAndPort[portIndex]));
    if (portIndex > 0)
        conn.setHostname(hostAndPort[0]);
}

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

private static void configureConnect(Connection conn, CommandLine cl)
        throws MissingOptionException, ParseException {
    if (!cl.hasOption("c"))
        throw new MissingOptionException(CLIUtils.rb.getString("missing-connect-opt"));

    String[] hostPort = StringUtils.split(cl.getOptionValue("c"), ':');
    if (hostPort.length != 2)
        throw new ParseException(CLIUtils.rb.getString("invalid-connect-opt"));

    conn.setHostname(hostPort[0]);/* w w w.j  a  v a  2 s.  c  om*/
    conn.setPort(Integer.parseInt(hostPort[1]));
}

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

@SuppressWarnings({ "unchecked" })
public static void main(String[] args) {
    try {/*from ww  w .j  a va  2s  .c  o m*/
        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);
    }
}