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

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

Introduction

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

Prototype

public static OptionBuilder withLongOpt(String newLongopt) 

Source Link

Document

The next Option created will have the following long option value.

Usage

From source file:org.dcm4che3.tool.json2dcm.Json2Dcm.java

@SuppressWarnings("static-access")
private static void addBulkdataOptions(Options opts) {
    OptionGroup blkGroup = new OptionGroup();
    blkGroup.addOption(//from   w ww  . j a va2 s . co  m
            OptionBuilder.withLongOpt("no-bulkdata").withDescription(rb.getString("no-bulkdata")).create("B"));
    blkGroup.addOption(OptionBuilder.withLongOpt("alloc-bulkdata")
            .withDescription(rb.getString("alloc-bulkdata")).create("b"));
    opts.addOptionGroup(blkGroup);
    opts.addOption(OptionBuilder.withLongOpt("blk-file-dir").hasArg().withArgName("directory")
            .withDescription(rb.getString("blk-file-dir")).create("d"));
    opts.addOption(OptionBuilder.withLongOpt("blk-file-prefix").hasArg().withArgName("prefix")
            .withDescription(rb.getString("blk-file-prefix")).create());
    opts.addOption(OptionBuilder.withLongOpt("blk-file-suffix").hasArg().withArgName("suffix")
            .withDescription(rb.getString("blk-file-suffix")).create());
    opts.addOption("c", "cat-blk-files", false, rb.getString("cat-blk-files"));
    opts.addOption(null, "keep-blk-files", false, rb.getString("keep-blk-files"));
    opts.addOption(OptionBuilder.withLongOpt("blk-spec").hasArg().withArgName("json-file")
            .withDescription(rb.getString("blk-spec")).create("J"));
}

From source file:org.dcm4che3.tool.qidors.QidoRS.java

@SuppressWarnings("static-access")
private static void addOutputOptions(Options opts) {
    opts.addOption(OptionBuilder.withLongOpt("out-dir").hasArg().withArgName("directory")
            .withDescription(rb.getString("out-dir")).create());
    opts.addOption(OptionBuilder.withLongOpt("out-file").hasArg().withArgName("name")
            .withDescription(rb.getString("out-file")).create());
    opts.addOption("J", "json", false, rb.getString("json"));
    opts.addOption(OptionBuilder.withLongOpt("xsl").hasArg().withArgName("xsl-file")
            .withDescription(rb.getString("xsl")).create("x"));
    opts.addOption("I", "indent", false, rb.getString("indent"));
    opts.addOption("K", "no-keyword", false, rb.getString("no-keyword"));
}

From source file:org.dcm4che3.tool.wadors.WadoRS.java

@SuppressWarnings("static-access")
private static void addOutputOptions(Options opts) {
    opts.addOption(OptionBuilder.withLongOpt("out-dir").hasArg().withArgName("directory")
            .withDescription(rb.getString("out-dir")).create());
    opts.addOption(OptionBuilder.withLongOpt("dump-headers").hasArg(false)
            .withDescription(rb.getString("dump-headers")).create());
    opts.addOption(OptionBuilder.withLongOpt("xsl").hasArg().withArgName("xsl-file")
            .withDescription(rb.getString("xsl")).create("x"));
    opts.addOption("I", "indent", false, rb.getString("indent"));
    opts.addOption("K", "no-keyword", false, rb.getString("no-keyword"));
}

From source file:org.dcm4che3.tool.wadouri.WadoURI.java

@SuppressWarnings("static-access")
private static void addOutputOptions(Options opts) {
    opts.addOption(OptionBuilder.withLongOpt("out-dir").hasArg().withArgName("directory")
            .withDescription(rb.getString("out-dir")).create());
    opts.addOption(OptionBuilder.withLongOpt("out-file").hasArg().withArgName("name")
            .withDescription(rb.getString("out-file")).create());
    opts.addOption(OptionBuilder.withLongOpt("xsl").hasArg().withArgName("xsl-file")
            .withDescription(rb.getString("xsl")).create("x"));
    opts.addOption("I", "indent", false, rb.getString("indent"));
    opts.addOption("K", "no-keyword", false, rb.getString("no-keyword"));
}

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  va 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.j a v  a  2  s.  co 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 v a  2 s  . co  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.dspace.rdf.RDFizer.java

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

    options.addOption("h", "help", false, "Print usage information and exit.");
    options.addOption("v", "verbose", false, "Print verbose information to " + "stderr while converting data.");
    options.addOption("n", "dry-run", false,
            "Don't store the converted " + "data in the triple store, don't delete data from the "
                    + "triplestore. Make a dry run, simulation what would happen.");
    options.addOption("o", "stdout", false,
            "Print all converted data to " + "stdout using turtle as serialization.");
    options.addOption("n", "dry-run", false, "Don't send any data or commands "
            + "to the triplestore. Usefull for debugging or in conjunction " + "with --stdout.");
    options.addOption("c", "convert-all", false,
            "Convert all DSpace Objects" + " that are readable for an anonymous user. This may take a long time"
                    + "depending on the number of stored communties, collections and "
                    + "items. Existing information in the triple store will be updated.");

    Option optIdentifiers = OptionBuilder.withLongOpt("identifiers").hasArgs().withArgName("handle")
            .withValueSeparator(' ')
            .withDescription("Only convert these DSpace Objects. If you specify "
                    + "a Community or Collection all of their Items will be "
                    + "converted as well. Separate multiple identifiers with a " + "space.")
            .create('i');
    options.addOption(optIdentifiers);//w w  w .  jav a 2  s. co  m

    Option optDelete = OptionBuilder.withLongOpt("delete").hasArgs().withArgName("hdl:handle | URI")
            .withValueSeparator(' ')
            .withDescription("Delete previously converted data. Specify "
                    + "either the handle of a DSpaceObject in the format "
                    + "'hdl:<handle>' or the URI used to identify the rdf "
                    + "data in the triplestore. If you specify a Community, "
                    + "Collection or Item by its handle all converted "
                    + "information about attached Subcommunities, "
                    + "Collections, Items, Bundles and Bitstreams will be "
                    + "deleted as well. Separate multiple identifiers with " + "a space.")
            .create();
    options.addOption(optDelete);

    Option optDeleteAll = OptionBuilder.withLongOpt("delete-all")
            .withDescription("Delete all converted data from the triplestore.").create();
    options.addOption(optDeleteAll);

    return options;
}

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);/* w w w .  j  a va 2s  .co m*/
    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.eclim.command.Options.java

/**
 * Parses the String representation of an Option to an Option instance.
 *
 * @param option The option String./*from w ww  .j a  v a2s. c  om*/
 * @return The Option.
 */
public Option parseOption(String option) {
    String[] parts = StringUtils.split(option);

    // command can have any additional arguments.
    //if(parts.length == 1 && ANY.equals(parts[0])){
    //}

    if (REQUIRED.equals(parts[0])) {
        OptionBuilder.isRequired();
    }
    if (ARG.equals(parts[3])) {
        OptionBuilder.hasArg();
        //OptionBuilder.withArgName(parts[2]);
    } else if (ANY.equals(parts[3])) {
        OptionBuilder.hasOptionalArgs();
    }
    OptionBuilder.withLongOpt(parts[2]);
    return OptionBuilder.create(parts[1]);
}