Example usage for org.apache.commons.cli OptionBuilder withDescription

List of usage examples for org.apache.commons.cli OptionBuilder withDescription

Introduction

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

Prototype

public static OptionBuilder withDescription(String newDescription) 

Source Link

Document

The next Option created will have the specified description

Usage

From source file:org.dcm4che2.tool.dcmwado.DcmWado.java

private static CommandLine parse(String[] args) {
    Options opts = new Options();
    OptionBuilder.withArgName("suid:Suid:iuid");
    OptionBuilder.hasArgs(3);//from   w  w w .  j  av a2  s.com
    OptionBuilder.withValueSeparator(':');
    OptionBuilder.withDescription(
            "Retrieve object with given Study " + "Instance UID, Series Instance UID and SOP Instance UID.");
    opts.addOption(OptionBuilder.create("uid"));

    OptionBuilder.withArgName("Suid:iuid");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator(':');
    OptionBuilder.withDescription("Series Instance UID and SOP Instance UID "
            + "of the presentation state storage object to be applied to the " + "image.");
    opts.addOption(OptionBuilder.create("pr"));

    opts.addOption("dcm", false, "Request DICOM object. (MIME type: application/dicom)");
    opts.addOption("jpeg", false, "Request JPEG image. (MIME type: image/jpeg)");
    opts.addOption("gif", false, "Request GIF image. (MIME type: image/gif)");
    opts.addOption("png", false, "Request PNG image. (MIME type: image/png)");
    opts.addOption("jp2", false, "Request JPEG 2000 image. (MIME type: image/jp2)");
    opts.addOption("mpeg", false, "Request MPEG video. (MIME type: video/mpeg)");
    opts.addOption("txt", false, "Request plain text document. (MIME type: text/plain)");
    opts.addOption("html", false, "Request HTML document. (MIME type: text/html)");
    opts.addOption("xml", false, "Request XML document. (MIME type: text/xml)");
    opts.addOption("rtf", false, "Request RTF document. (MIME type: text/rtf)");
    opts.addOption("pdf", false, "Request PDF document. (MIME type: application/pdf)");
    opts.addOption("cda1", false,
            "Request CDA Level 1 document. " + "(MIME type: application/x-hl7-cda-level-one+xml)");

    OptionBuilder.withArgName("type");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Request document with the specified MIME type."
            + "Alternative MIME types can be specified by additional -mime options.");
    opts.addOption(OptionBuilder.create("mime"));

    OptionBuilder.withArgName("uid");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Returned object shall be encoded with "
            + "the specified Transfer Syntax. Alternative Transfer Syntaxes "
            + "can be specified by additional -ts options.");
    opts.addOption(OptionBuilder.create("ts"));

    OptionBuilder.withArgName("name");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "Returned object shall be encoded with " + "specified Character set. Alternative Character sets "
                    + "can be specified by additional -charset options.");
    opts.addOption(OptionBuilder.create("charset"));

    opts.addOption("anonymize", false,
            "Remove all patient identification" + "information from returned DICOM Object");

    OptionBuilder.withArgName("type");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "Burn in patient information" + "(-annotation=patient) and/or technique information "
                    + "(-annotation=technique) in returned pixel data.");
    opts.addOption(OptionBuilder.create("annotation"));

    OptionBuilder.withArgName("num");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Maximal number of pixel rows in returned image.");
    opts.addOption(OptionBuilder.create("rows"));

    OptionBuilder.withArgName("num");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Maximal number of pixel columns in returned image.");
    opts.addOption(OptionBuilder.create("columns"));

    OptionBuilder.withArgName("num");
    OptionBuilder.hasArg();
    OptionBuilder
            .withDescription("Return single frame with that number " + "within a multi-frame image object.");
    opts.addOption(OptionBuilder.create("frame"));

    OptionBuilder.withArgName("x1:y1:x2:y2");
    OptionBuilder.hasArgs(4);
    OptionBuilder.withValueSeparator(':');
    OptionBuilder.withDescription("Return rectangular region of image "
            + "matrix specified by top left (x1,y1) and bottom right (x2,y2) "
            + "corner in relative coordinates within the range 0.0 to 1.0.");
    opts.addOption(OptionBuilder.create("window"));

    OptionBuilder.withArgName("center/width");
    OptionBuilder.hasArgs(2);
    OptionBuilder.withValueSeparator('/');
    OptionBuilder
            .withDescription("Specifies center and width of the " + "VOI window to be applied to the image.");
    opts.addOption(OptionBuilder.create("window"));

    OptionBuilder.withArgName("num");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "Quality of the image to be returned " + "within the range 1 to 100, 100 being the best quality.");
    opts.addOption(OptionBuilder.create("quality"));

    OptionBuilder.withArgName("path");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default");
    opts.addOption(OptionBuilder.create("dir"));

    OptionBuilder.withArgName("dirpath");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default");
    opts.addOption(OptionBuilder.create("dir"));

    OptionBuilder.withArgName("file");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Store retrieved object to specified file, "
            + "use SOP Instance UID + format specific file extension as " + "file name by default.");
    opts.addOption(OptionBuilder.create("o"));

    opts.addOption("nostore", false, "Do not store retrieved objects to files.");
    opts.addOption("nokeepalive", false, "Close TCP connection after each response.");
    opts.addOption("noredirect", false, "Disable HTTP redirects.");

    OptionBuilder.withArgName("kB");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription(
            "Size of byte buffer in KB " + "used for copying the retrieved object to disk, 8 KB by default.");
    opts.addOption(OptionBuilder.create("buffersize"));

    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 (MissingOptionException e) {
        exit("dcmwado: Missing required option " + e.getMessage());
        throw new RuntimeException("unreachable");
    } catch (ParseException e) {
        exit("dcmwado: " + e.getMessage());
        throw new RuntimeException("unreachable");
    }
    if (cl.hasOption('V')) {
        Package p = DcmWado.class.getPackage();
        System.out.println("dcmwado v" + p.getImplementationVersion());
        System.exit(0);
    }
    if (cl.hasOption('h') || cl.getArgList().isEmpty()) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE);
        System.exit(0);
    }
    int narg = cl.getArgList().size();
    if (narg == 0)
        exit("Missing url of WADO server");
    if (narg == 1) {
        if (!cl.hasOption("uid")) {
            exit("You must either option -uid <uids> or <file>|<directory> specify");
        }
    } else {
        if (cl.hasOption("uid")) {
            exit("You may not specify option -uid <uids> together with " + "<file>|<directory>.");
        }
    }
    return cl;
}

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

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

    OptionBuilder.withArgName("code");
    OptionBuilder.hasArg();/*from   w  ww .ja  va  2s .  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();
        System.out.println("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.dcm4che2.tool.pdf2dcm.Pdf2Dcm.java

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

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

    OptionBuilder.withArgName("size");
    OptionBuilder.hasArg();
    OptionBuilder.withDescription("Buffer size used for copying PDF to DICOM file, 8192 by default");
    opts.addOption(OptionBuilder.create("bs"));

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

    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");

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

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

    OptionBuilder.withArgName("charset");
    OptionBuilder.hasArg();/*from w ww  .jav  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.jpg2dcm.Jpg2Dcm.java

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

    OptionBuilder.withArgName("code");
    OptionBuilder.hasArg();/*from  w ww  .  ja  va 2s . 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.dspace.app.mediafilter.MediaFilterCLITool.java

public static void main(String[] argv) throws Exception {
    // set headless for non-gui workstations
    System.setProperty("java.awt.headless", "true");

    // create an options object and populate it
    CommandLineParser parser = new PosixParser();

    int status = 0;

    Options options = new Options();

    options.addOption("v", "verbose", false, "print all extracted text and other details to STDOUT");
    options.addOption("q", "quiet", false, "do not print anything except in the event of errors.");
    options.addOption("f", "force", false, "force all bitstreams to be processed");
    options.addOption("i", "identifier", true, "ONLY process bitstreams belonging to identifier");
    options.addOption("m", "maximum", true, "process no more than maximum items");
    options.addOption("h", "help", false, "help");

    //create a "plugin" option (to specify specific MediaFilter plugins to run)
    OptionBuilder.withLongOpt("plugins");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withDescription("ONLY run the specified Media Filter plugin(s)\n" + "listed from '"
            + MEDIA_FILTER_PLUGINS_KEY + "' in dspace.cfg.\n" + "Separate multiple with a comma (,)\n"
            + "(e.g. MediaFilterManager -p \n\"Word Text Extractor\",\"PDF Text Extractor\")");
    Option pluginOption = OptionBuilder.create('p');
    pluginOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args
    options.addOption(pluginOption);//w  ww  .  j a v  a  2 s  .  c  o  m

    //create a "skip" option (to specify communities/collections/items to skip)
    OptionBuilder.withLongOpt("skip");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withDescription(
            "SKIP the bitstreams belonging to identifier\n" + "Separate multiple identifiers with a comma (,)\n"
                    + "(e.g. MediaFilterManager -s \n 123456789/34,123456789/323)");
    Option skipOption = OptionBuilder.create('s');
    skipOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args
    options.addOption(skipOption);

    boolean isVerbose = false;
    boolean isQuiet = false;
    boolean isForce = false; // default to not forced
    String identifier = null; // object scope limiter
    int max2Process = Integer.MAX_VALUE;
    Map<String, List<String>> filterFormats = new HashMap<>();

    CommandLine line = null;
    try {
        line = parser.parse(options, argv);
    } catch (MissingArgumentException e) {
        System.out.println("ERROR: " + e.getMessage());
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("MediaFilterManager\n", options);
        System.exit(1);
    }

    if (line.hasOption('h')) {
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("MediaFilterManager\n", options);

        System.exit(0);
    }

    if (line.hasOption('v')) {
        isVerbose = true;
    }

    isQuiet = line.hasOption('q');

    if (line.hasOption('f')) {
        isForce = true;
    }

    if (line.hasOption('i')) {
        identifier = line.getOptionValue('i');
    }

    if (line.hasOption('m')) {
        max2Process = Integer.parseInt(line.getOptionValue('m'));
        if (max2Process <= 1) {
            System.out.println("Invalid maximum value '" + line.getOptionValue('m') + "' - ignoring");
            max2Process = Integer.MAX_VALUE;
        }
    }

    String filterNames[] = null;
    if (line.hasOption('p')) {
        //specified which media filter plugins we are using
        filterNames = line.getOptionValues('p');

        if (filterNames == null || filterNames.length == 0) { //display error, since no plugins specified
            System.err.println("\nERROR: -p (-plugin) option requires at least one plugin to be specified.\n"
                    + "(e.g. MediaFilterManager -p \"Word Text Extractor\",\"PDF Text Extractor\")\n");
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("MediaFilterManager\n", options);
            System.exit(1);
        }
    } else {
        //retrieve list of all enabled media filter plugins!
        filterNames = DSpaceServicesFactory.getInstance().getConfigurationService()
                .getArrayProperty(MEDIA_FILTER_PLUGINS_KEY);
    }

    MediaFilterService mediaFilterService = MediaFilterServiceFactory.getInstance().getMediaFilterService();
    mediaFilterService.setForce(isForce);
    mediaFilterService.setQuiet(isQuiet);
    mediaFilterService.setVerbose(isVerbose);
    mediaFilterService.setMax2Process(max2Process);

    //initialize an array of our enabled filters
    List<FormatFilter> filterList = new ArrayList<FormatFilter>();

    //set up each filter
    for (int i = 0; i < filterNames.length; i++) {
        //get filter of this name & add to list of filters
        FormatFilter filter = (FormatFilter) CoreServiceFactory.getInstance().getPluginService()
                .getNamedPlugin(FormatFilter.class, filterNames[i]);
        if (filter == null) {
            System.err.println(
                    "\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '"
                            + filterNames[i] + "'");
            System.exit(1);
        } else {
            filterList.add(filter);

            String filterClassName = filter.getClass().getName();

            String pluginName = null;

            //If this filter is a SelfNamedPlugin,
            //then the input formats it accepts may differ for
            //each "named" plugin that it defines.
            //So, we have to look for every key that fits the
            //following format: filter.<class-name>.<plugin-name>.inputFormats
            if (SelfNamedPlugin.class.isAssignableFrom(filter.getClass())) {
                //Get the plugin instance name for this class
                pluginName = ((SelfNamedPlugin) filter).getPluginInstanceName();
            }

            //Retrieve our list of supported formats from dspace.cfg
            //For SelfNamedPlugins, format of key is:
            //  filter.<class-name>.<plugin-name>.inputFormats
            //For other MediaFilters, format of key is:
            //  filter.<class-name>.inputFormats
            String[] formats = DSpaceServicesFactory.getInstance().getConfigurationService()
                    .getArrayProperty(FILTER_PREFIX + "." + filterClassName
                            + (pluginName != null ? "." + pluginName : "") + "." + INPUT_FORMATS_SUFFIX);

            //add to internal map of filters to supported formats
            if (ArrayUtils.isNotEmpty(formats)) {
                //For SelfNamedPlugins, map key is:
                //  <class-name><separator><plugin-name>
                //For other MediaFilters, map key is just:
                //  <class-name>
                filterFormats.put(filterClassName
                        + (pluginName != null ? MediaFilterService.FILTER_PLUGIN_SEPARATOR + pluginName : ""),
                        Arrays.asList(formats));
            }
        } //end if filter!=null
    } //end for

    //If verbose, print out loaded mediafilter info
    if (isVerbose) {
        System.out.println("The following MediaFilters are enabled: ");
        Iterator<String> i = filterFormats.keySet().iterator();
        while (i.hasNext()) {
            String filterName = i.next();
            System.out.println("Full Filter Name: " + filterName);
            String pluginName = null;
            if (filterName.contains(MediaFilterService.FILTER_PLUGIN_SEPARATOR)) {
                String[] fields = filterName.split(MediaFilterService.FILTER_PLUGIN_SEPARATOR);
                filterName = fields[0];
                pluginName = fields[1];
            }

            System.out.println(filterName + (pluginName != null ? " (Plugin: " + pluginName + ")" : ""));
        }
    }

    mediaFilterService.setFilterFormats(filterFormats);
    //store our filter list into an internal array
    mediaFilterService.setFilterClasses(filterList);

    //Retrieve list of identifiers to skip (if any)
    String skipIds[] = null;
    if (line.hasOption('s')) {
        //specified which identifiers to skip when processing
        skipIds = line.getOptionValues('s');

        if (skipIds == null || skipIds.length == 0) { //display error, since no identifiers specified to skip
            System.err.println("\nERROR: -s (-skip) option requires at least one identifier to SKIP.\n"
                    + "Make sure to separate multiple identifiers with a comma!\n"
                    + "(e.g. MediaFilterManager -s 123456789/34,123456789/323)\n");
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("MediaFilterManager\n", options);
            System.exit(0);
        }

        //save to a global skip list
        mediaFilterService.setSkipList(Arrays.asList(skipIds));
    }

    Context c = null;

    try {
        c = new Context();

        // have to be super-user to do the filtering
        c.turnOffAuthorisationSystem();

        // now apply the filters
        if (identifier == null) {
            mediaFilterService.applyFiltersAllItems(c);
        } else // restrict application scope to identifier
        {
            DSpaceObject dso = HandleServiceFactory.getInstance().getHandleService().resolveToObject(c,
                    identifier);
            if (dso == null) {
                throw new IllegalArgumentException("Cannot resolve " + identifier + " to a DSpace object");
            }

            switch (dso.getType()) {
            case Constants.COMMUNITY:
                mediaFilterService.applyFiltersCommunity(c, (Community) dso);
                break;
            case Constants.COLLECTION:
                mediaFilterService.applyFiltersCollection(c, (Collection) dso);
                break;
            case Constants.ITEM:
                mediaFilterService.applyFiltersItem(c, (Item) dso);
                break;
            }
        }

        c.complete();
        c = null;
    } catch (Exception e) {
        status = 1;
    } finally {
        if (c != null) {
            c.abort();
        }
    }
    System.exit(status);
}

From source file:org.dspace.app.mediafilter.MediaFilterManager.java

public static void main(String[] argv) throws Exception {
    // set headless for non-gui workstations
    System.setProperty("java.awt.headless", "true");

    // create an options object and populate it
    CommandLineParser parser = new PosixParser();

    int status = 0;

    Options options = new Options();

    options.addOption("v", "verbose", false, "print all extracted text and other details to STDOUT");
    options.addOption("q", "quiet", false, "do not print anything except in the event of errors.");
    options.addOption("f", "force", false, "force all bitstreams to be processed");
    options.addOption("n", "noindex", false, "do NOT update the search index after filtering bitstreams");
    options.addOption("i", "identifier", true, "ONLY process bitstreams belonging to identifier");
    options.addOption("m", "maximum", true, "process no more than maximum items");
    options.addOption("h", "help", false, "help");

    //create a "plugin" option (to specify specific MediaFilter plugins to run)
    OptionBuilder.withLongOpt("plugins");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withDescription("ONLY run the specified Media Filter plugin(s)\n" + "listed from '"
            + MEDIA_FILTER_PLUGINS_KEY + "' in dspace.cfg.\n" + "Separate multiple with a comma (,)\n"
            + "(e.g. MediaFilterManager -p \n\"Word Text Extractor\",\"PDF Text Extractor\")");
    Option pluginOption = OptionBuilder.create('p');
    pluginOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args
    options.addOption(pluginOption);//w ww.ja va 2s  .  c  o m

    //create a "skip" option (to specify communities/collections/items to skip)
    OptionBuilder.withLongOpt("skip");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withDescription(
            "SKIP the bitstreams belonging to identifier\n" + "Separate multiple identifiers with a comma (,)\n"
                    + "(e.g. MediaFilterManager -s \n 123456789/34,123456789/323)");
    Option skipOption = OptionBuilder.create('s');
    skipOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args
    options.addOption(skipOption);

    CommandLine line = null;
    try {
        line = parser.parse(options, argv);
    } catch (MissingArgumentException e) {
        System.out.println("ERROR: " + e.getMessage());
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("MediaFilterManager\n", options);
        System.exit(1);
    }

    if (line.hasOption('h')) {
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("MediaFilterManager\n", options);

        System.exit(0);
    }

    if (line.hasOption('v')) {
        isVerbose = true;
    }

    isQuiet = line.hasOption('q');

    if (line.hasOption('n')) {
        updateIndex = false;
    }

    if (line.hasOption('f')) {
        isForce = true;
    }

    if (line.hasOption('i')) {
        identifier = line.getOptionValue('i');
    }

    if (line.hasOption('m')) {
        max2Process = Integer.parseInt(line.getOptionValue('m'));
        if (max2Process <= 1) {
            System.out.println("Invalid maximum value '" + line.getOptionValue('m') + "' - ignoring");
            max2Process = Integer.MAX_VALUE;
        }
    }

    String filterNames[] = null;
    if (line.hasOption('p')) {
        //specified which media filter plugins we are using
        filterNames = line.getOptionValues('p');

        if (filterNames == null || filterNames.length == 0) { //display error, since no plugins specified
            System.err.println("\nERROR: -p (-plugin) option requires at least one plugin to be specified.\n"
                    + "(e.g. MediaFilterManager -p \"Word Text Extractor\",\"PDF Text Extractor\")\n");
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("MediaFilterManager\n", options);
            System.exit(1);
        }
    } else {
        //retrieve list of all enabled media filter plugins!
        String enabledPlugins = ConfigurationManager.getProperty(MEDIA_FILTER_PLUGINS_KEY);
        filterNames = enabledPlugins.split(",\\s*");
    }

    //initialize an array of our enabled filters
    List<FormatFilter> filterList = new ArrayList<FormatFilter>();

    //set up each filter
    for (int i = 0; i < filterNames.length; i++) {
        //get filter of this name & add to list of filters
        FormatFilter filter = (FormatFilter) PluginManager.getNamedPlugin(FormatFilter.class, filterNames[i]);
        if (filter == null) {
            System.err.println(
                    "\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '"
                            + filterNames[i] + "'");
            System.exit(1);
        } else {
            filterList.add(filter);

            String filterClassName = filter.getClass().getName();

            String pluginName = null;

            //If this filter is a SelfNamedPlugin,
            //then the input formats it accepts may differ for
            //each "named" plugin that it defines.
            //So, we have to look for every key that fits the
            //following format: filter.<class-name>.<plugin-name>.inputFormats
            if (SelfNamedPlugin.class.isAssignableFrom(filter.getClass())) {
                //Get the plugin instance name for this class
                pluginName = ((SelfNamedPlugin) filter).getPluginInstanceName();
            }

            //Retrieve our list of supported formats from dspace.cfg
            //For SelfNamedPlugins, format of key is:  
            //  filter.<class-name>.<plugin-name>.inputFormats
            //For other MediaFilters, format of key is: 
            //  filter.<class-name>.inputFormats
            String formats = ConfigurationManager.getProperty(FILTER_PREFIX + "." + filterClassName
                    + (pluginName != null ? "." + pluginName : "") + "." + INPUT_FORMATS_SUFFIX);

            //add to internal map of filters to supported formats   
            if (formats != null) {
                //For SelfNamedPlugins, map key is:  
                //  <class-name><separator><plugin-name>
                //For other MediaFilters, map key is just:
                //  <class-name>
                filterFormats.put(
                        filterClassName + (pluginName != null ? FILTER_PLUGIN_SEPARATOR + pluginName : ""),
                        Arrays.asList(formats.split(",[\\s]*")));
            }
        } //end if filter!=null
    } //end for

    //If verbose, print out loaded mediafilter info
    if (isVerbose) {
        System.out.println("The following MediaFilters are enabled: ");
        Iterator<String> i = filterFormats.keySet().iterator();
        while (i.hasNext()) {
            String filterName = i.next();
            System.out.println("Full Filter Name: " + filterName);
            String pluginName = null;
            if (filterName.contains(FILTER_PLUGIN_SEPARATOR)) {
                String[] fields = filterName.split(FILTER_PLUGIN_SEPARATOR);
                filterName = fields[0];
                pluginName = fields[1];
            }

            System.out.println(filterName + (pluginName != null ? " (Plugin: " + pluginName + ")" : ""));
        }
    }

    //store our filter list into an internal array
    filterClasses = (FormatFilter[]) filterList.toArray(new FormatFilter[filterList.size()]);

    //Retrieve list of identifiers to skip (if any)
    String skipIds[] = null;
    if (line.hasOption('s')) {
        //specified which identifiers to skip when processing
        skipIds = line.getOptionValues('s');

        if (skipIds == null || skipIds.length == 0) { //display error, since no identifiers specified to skip
            System.err.println("\nERROR: -s (-skip) option requires at least one identifier to SKIP.\n"
                    + "Make sure to separate multiple identifiers with a comma!\n"
                    + "(e.g. MediaFilterManager -s 123456789/34,123456789/323)\n");
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("MediaFilterManager\n", options);
            System.exit(0);
        }

        //save to a global skip list
        skipList = Arrays.asList(skipIds);
    }

    Context c = null;

    try {
        c = new Context();

        // have to be super-user to do the filtering
        c.turnOffAuthorisationSystem();

        // now apply the filters
        if (identifier == null) {
            applyFiltersAllItems(c);
        } else // restrict application scope to identifier
        {
            DSpaceObject dso = HandleManager.resolveToObject(c, identifier);
            if (dso == null) {
                throw new IllegalArgumentException("Cannot resolve " + identifier + " to a DSpace object");
            }

            switch (dso.getType()) {
            case Constants.COMMUNITY:
                applyFiltersCommunity(c, (Community) dso);
                break;
            case Constants.COLLECTION:
                applyFiltersCollection(c, (Collection) dso);
                break;
            case Constants.ITEM:
                applyFiltersItem(c, (Item) dso);
                break;
            }
        }

        // update search index?
        if (updateIndex) {
            if (!isQuiet) {
                System.out.println("Updating search index:");
            }
            DSIndexer.setBatchProcessingMode(true);
            try {
                DSIndexer.updateIndex(c);
            } finally {
                DSIndexer.setBatchProcessingMode(false);
            }
        }

        c.complete();
        c = null;
    } catch (Exception e) {
        status = 1;
    } finally {
        if (c != null) {
            c.abort();
        }
    }
    System.exit(status);
}

From source file:org.dspace.papaya.mediafilter.PapayaMediaFilterManager.java

public static void main(String[] argv) throws Exception {
    // set headless for non-gui workstations
    System.setProperty("java.awt.headless", "true");

    // create an options object and populate it
    CommandLineParser parser = new PosixParser();

    int status = 0;

    Options options = new Options();

    options.addOption("v", "verbose", false, "print all extracted text and other details to STDOUT");
    options.addOption("q", "quiet", false, "do not print anything except in the event of errors.");
    options.addOption("f", "force", false, "force all bitstreams to be processed");
    options.addOption("i", "identifier", true, "ONLY process bitstreams belonging to identifier");
    options.addOption("m", "maximum", true, "process no more than maximum items");
    options.addOption("h", "help", false, "help");

    //create a "plugin" option (to specify specific MediaFilter plugins to run)
    OptionBuilder.withLongOpt("plugins");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withDescription("ONLY run the specified Media Filter plugin(s)\n" + "listed from '"
            + MEDIA_FILTER_PLUGINS_KEY + "' in dspace.cfg.\n" + "Separate multiple with a comma (,)\n"
            + "(e.g. MediaFilterManager -p \n\"Word Text Extractor\",\"PDF Text Extractor\")");
    Option pluginOption = OptionBuilder.create('p');
    pluginOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args
    options.addOption(pluginOption);//from   w w w.j  a  va2 s .c o m

    //create a "skip" option (to specify communities/collections/items to skip)
    OptionBuilder.withLongOpt("skip");
    OptionBuilder.withValueSeparator(',');
    OptionBuilder.withDescription(
            "SKIP the bitstreams belonging to identifier\n" + "Separate multiple identifiers with a comma (,)\n"
                    + "(e.g. MediaFilterManager -s \n 123456789/34,123456789/323)");
    Option skipOption = OptionBuilder.create('s');
    skipOption.setArgs(Option.UNLIMITED_VALUES); //unlimited number of args
    options.addOption(skipOption);

    CommandLine line = null;
    try {
        line = parser.parse(options, argv);
    } catch (MissingArgumentException e) {
        System.out.println("ERROR: " + e.getMessage());
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("MediaFilterManager\n", options);
        System.exit(1);
    }

    if (line.hasOption('h')) {
        HelpFormatter myhelp = new HelpFormatter();
        myhelp.printHelp("MediaFilterManager\n", options);

        System.exit(0);
    }

    if (line.hasOption('v')) {
        isVerbose = true;
    }

    isQuiet = line.hasOption('q');

    if (line.hasOption('f')) {
        isForce = true;
    }

    if (line.hasOption('i')) {
        identifier = line.getOptionValue('i');
    }

    if (line.hasOption('m')) {
        max2Process = Integer.parseInt(line.getOptionValue('m'));
        if (max2Process <= 1) {
            System.out.println("Invalid maximum value '" + line.getOptionValue('m') + "' - ignoring");
            max2Process = Integer.MAX_VALUE;
        }
    }

    String filterNames[] = null;
    if (line.hasOption('p')) {
        //specified which media filter plugins we are using
        filterNames = line.getOptionValues('p');

        if (filterNames == null || filterNames.length == 0) { //display error, since no plugins specified
            System.err.println("\nERROR: -p (-plugin) option requires at least one plugin to be specified.\n"
                    + "(e.g. MediaFilterManager -p \"Word Text Extractor\",\"PDF Text Extractor\")\n");
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("MediaFilterManager\n", options);
            System.exit(1);
        }
    } else {
        //retrieve list of all enabled media filter plugins!
        String enabledPlugins = ConfigurationManager.getProperty(MEDIA_FILTER_PLUGINS_KEY);
        filterNames = enabledPlugins.split(",\\s*");
    }

    //initialize an array of our enabled filters
    List<FormatFilter> filterList = new ArrayList<FormatFilter>();

    //set up each filter
    for (int i = 0; i < filterNames.length; i++) {
        //get filter of this name & add to list of filters
        FormatFilter filter = (FormatFilter) PluginManager.getNamedPlugin(FormatFilter.class, filterNames[i]);
        if (filter == null) {
            System.err.println(
                    "\nERROR: Unknown MediaFilter specified (either from command-line or in dspace.cfg): '"
                            + filterNames[i] + "'");
            System.exit(1);
        } else {
            filterList.add(filter);

            String filterClassName = filter.getClass().getName();

            String pluginName = null;
            //If this filter is a SelfNamedPlugin,
            //then the input formats it accepts may differ for
            //each "named" plugin that it defines.
            //So, we have to look for every key that fits the
            //following format: filter.<class-name>.<plugin-name>.inputFormats
            if (SelfNamedPlugin.class.isAssignableFrom(filter.getClass())) {
                //Get the plugin instance name for this class
                pluginName = ((SelfNamedPlugin) filter).getPluginInstanceName();
            }

            //Retrieve our list of supported formats from dspace.cfg
            //For SelfNamedPlugins, format of key is:  
            //  filter.<class-name>.<plugin-name>.inputFormats
            //For other MediaFilters, format of key is: 
            //  filter.<class-name>.inputFormats
            String formats = ConfigurationManager.getProperty(FILTER_PREFIX + "." + filterClassName
                    + (pluginName != null ? "." + pluginName : "") + "." + INPUT_FORMATS_SUFFIX);

            //add to internal map of filters to supported formats   
            if (formats != null) {
                //For SelfNamedPlugins, map key is:  
                //  <class-name><separator><plugin-name>
                //For other MediaFilters, map key is just:
                //  <class-name>
                filterFormats.put(
                        filterClassName + (pluginName != null ? FILTER_PLUGIN_SEPARATOR + pluginName : ""),
                        Arrays.asList(formats.split(",[\\s]*")));
            }
        } //end if filter!=null
    } //end for

    //If verbose, print out loaded mediafilter info
    if (isVerbose) {
        System.out.println("The following MediaFilters are enabled: ");
        Iterator<String> i = filterFormats.keySet().iterator();
        while (i.hasNext()) {
            String filterName = i.next();
            System.out.println("Full Filter Name: " + filterName);
            String pluginName = null;
            if (filterName.contains(FILTER_PLUGIN_SEPARATOR)) {
                String[] fields = filterName.split(FILTER_PLUGIN_SEPARATOR);
                filterName = fields[0];
                pluginName = fields[1];
            }

            System.out.println(filterName + (pluginName != null ? " (Plugin: " + pluginName + ")" : ""));
        }
    }

    //store our filter list into an internal array
    filterClasses = (FormatFilter[]) filterList.toArray(new FormatFilter[filterList.size()]);

    //Retrieve list of identifiers to skip (if any)
    String skipIds[] = null;
    if (line.hasOption('s')) {
        //specified which identifiers to skip when processing
        skipIds = line.getOptionValues('s');

        if (skipIds == null || skipIds.length == 0) { //display error, since no identifiers specified to skip
            System.err.println("\nERROR: -s (-skip) option requires at least one identifier to SKIP.\n"
                    + "Make sure to separate multiple identifiers with a comma!\n"
                    + "(e.g. MediaFilterManager -s 123456789/34,123456789/323)\n");
            HelpFormatter myhelp = new HelpFormatter();
            myhelp.printHelp("MediaFilterManager\n", options);
            System.exit(0);
        }

        //save to a global skip list
        skipList = Arrays.asList(skipIds);
    }

    Context c = null;

    try {
        c = new Context();
        // have to be super-user to do the filtering
        c.turnOffAuthorisationSystem();

        // now apply the filters
        if (identifier == null) {
            applyFiltersAllItems(c);
        } else // restrict application scope to identifier
        {
            DSpaceObject dso = HandleManager.resolveToObject(c, identifier);
            if (dso == null) {
                throw new IllegalArgumentException("Cannot resolve " + identifier + " to a DSpace object");
            }

            switch (dso.getType()) {
            case Constants.COMMUNITY:
                applyFiltersCommunity(c, (Community) dso);
                break;
            case Constants.COLLECTION:
                applyFiltersCollection(c, (Collection) dso);
                break;
            case Constants.ITEM:
                applyFiltersItem(c, (Item) dso);
                break;
            }
        }

        c.complete();
        c = null;
    } catch (Exception e) {
        status = 1;
    } finally {
        if (c != null) {
            c.abort();
        }
    }
    System.exit(status);
}

From source file:org.easyrec.plugin.cli.AbstractGeneratorCLI.java

protected AbstractGeneratorCLI() {
    options = new Options();

    OptionBuilder optionBuilder = OptionBuilder.withArgName("tenants");
    optionBuilder.withLongOpt("tenant");
    optionBuilder.isRequired(false);//from   w  w w .  jav  a2s.com
    optionBuilder.hasArg(true);
    optionBuilder.withDescription(
            "Specifiy a tenant to generate rules for. Ranges can be specified e.g. 1 - 3 will generate rules for tenants 1 to 3. Alternatively you can specify a list of tenants like 1,2,4. If omitted rules for all tenants are generated.");

    Option tenantOption = optionBuilder.create('t');

    optionBuilder = OptionBuilder.withLongOpt("uninstall");
    optionBuilder.isRequired(false);
    optionBuilder.hasArg(false);
    optionBuilder.withDescription("When true the generator is uninstalled when execution finished");

    Option uninstallOption = optionBuilder.create('u');

    options.addOption(tenantOption);
    options.addOption(uninstallOption);
}

From source file:org.eclipse.jubula.documentation.gen.TexGen.java

/**
 * @return The command line options//from   w w w  . ja va2  s  .  co m
 */
private static Options createOptions() {
    Options options = new Options();

    OptionBuilder.withArgName("generate type"); //$NON-NLS-1$
    OptionBuilder
            .withDescription("The type of output to generate (i.e. 'actions', 'errors'). Default: 'actions'"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    // Not required. Default to type 'actions'.
    options.addOption(OptionBuilder.create("gt")); //$NON-NLS-1$

    OptionBuilder.withArgName("template directory"); //$NON-NLS-1$
    OptionBuilder.withDescription("The directory which contains the template files"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create("td")); //$NON-NLS-1$

    OptionBuilder.withArgName("output directory"); //$NON-NLS-1$
    OptionBuilder.withDescription("The output directory"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired();
    options.addOption(OptionBuilder.create("od")); //$NON-NLS-1$

    OptionBuilder.withArgName("language"); //$NON-NLS-1$
    OptionBuilder.withDescription("The language, e.g. 'en' or 'de'"); //$NON-NLS-1$
    OptionBuilder.hasArg();
    OptionBuilder.isRequired(false);
    options.addOption(OptionBuilder.create("nl")); //$NON-NLS-1$
    return options;
}