Example usage for org.apache.commons.lang ArrayUtils isNotEmpty

List of usage examples for org.apache.commons.lang ArrayUtils isNotEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils isNotEmpty.

Prototype

public static boolean isNotEmpty(boolean[] array) 

Source Link

Document

Checks if an array of primitive booleans is not empty or not null.

Usage

From source file:org.codice.ddf.validator.metacard.duplication.DuplicationValidator.java

private Set<ValidationViolation> reportDuplicates(final Metacard metacard) {

    Set<ValidationViolation> violations = new HashSet<>();

    if (ArrayUtils.isNotEmpty(warnOnDuplicateAttributes)) {
        ValidationViolation warnValidation = reportDuplicates(metacard, warnOnDuplicateAttributes,
                ValidationViolation.Severity.WARNING);
        if (warnValidation != null) {
            violations.add(warnValidation);
        }//from   ww  w .  ja  v  a 2s . com
    }
    if (ArrayUtils.isNotEmpty(errorOnDuplicateAttributes)) {
        ValidationViolation errorViolation = reportDuplicates(metacard, errorOnDuplicateAttributes,
                ValidationViolation.Severity.ERROR);
        if (errorViolation != null) {
            violations.add(errorViolation);
        }
    }

    return violations;
}

From source file:org.craftercms.search.service.impl.QueryParams.java

public QueryParams addParam(String name, String value) {
    String[] oldValues = params.get(name);
    String[] values;/*from w  w w  . j a  v a  2s. c  o  m*/

    if (ArrayUtils.isNotEmpty(oldValues)) {
        values = (String[]) ArrayUtils.add(oldValues, value);
    } else {
        values = new String[1];
        values[0] = value;
    }

    params.put(name, values);

    return this;
}

From source file:org.craftercms.search.service.impl.QueryParams.java

public QueryParams addParam(String name, String... values) {
    String[] oldValues = params.get(name);
    if (ArrayUtils.isNotEmpty(oldValues)) {
        values = (String[]) ArrayUtils.addAll(oldValues, values);
    }/*from w w  w.j a  va  2s .c  o m*/

    params.put(name, values);

    return this;
}

From source file:org.craftercms.security.authentication.impl.AuthenticationCookieFactory.java

/**
 * Returns the authentication cookie string value from the request.
 *///from w  w  w.  j  av  a2  s.  c  o  m
protected String getCookieValueFromRequest(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();

    if (ArrayUtils.isNotEmpty(cookies)) {
        for (Cookie cookie : cookies) {
            if (cookie.getName().equals(AuthenticationCookie.COOKIE)) {
                return cookie.getValue();
            }
        }
    }

    return null;
}

From source file:org.craftercms.security.servlet.filters.RequestSecurityFilter.java

/**
 * Returns trues if the request should be excluded from processing.
 *///from ww  w. j  a  va2s .  c  o  m
protected boolean excludeRequest(HttpServletRequest request) {
    if (ArrayUtils.isNotEmpty(urlsToExclude)) {
        for (String pathPattern : urlsToExclude) {
            if (pathMatcher.match(pathPattern, request.getRequestURI())) {
                return true;
            }
        }
    }

    return false;
}

From source file:org.craftercms.security.servlet.filters.RequestSecurityFilter.java

/**
 * Returns trues if the request should be included for processing.
 *//*from   w  ww  .  j  a  v  a  2  s .  c om*/
protected boolean includeRequest(HttpServletRequest request) {
    if (ArrayUtils.isNotEmpty(urlsToInclude)) {
        for (String pathPattern : urlsToInclude) {
            if (pathMatcher.match(pathPattern, request.getRequestURI())) {
                return true;
            }
        }
    }

    return false;
}

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 .  jav a2 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.authenticate.OpenAMAuthentication.java

@Override
public int[] getSpecialGroups(Context context, HttpServletRequest request) throws SQLException {
    if (request != null && request.getSession() != null) {
        int[] groupIds = (int[]) request.getSession().getAttribute(SPECIAL_GROUP_REQUEST_ATTRIBUTE);

        if (ArrayUtils.isNotEmpty(groupIds)) {
            return groupIds;
        }//from   w w w. j av  a  2 s  .  c  o  m
    }

    return new int[0];
}

From source file:org.dspace.authenticate.X509Authentication.java

/**
 * Returns a list of group names that the user should be added to upon
 * successful authentication, configured in dspace.cfg.
 * //from  w  w  w . ja  va2 s .  co m
 * @return List<String> of special groups configured for this authenticator
 */
private List<String> getX509Groups() {
    List<String> groupNames = new ArrayList<String>();

    String[] groups = configurationService.getArrayProperty("authentication-x509.groups");

    if (ArrayUtils.isNotEmpty(groups)) {
        for (String group : groups) {
            groupNames.add(group.trim());
        }
    }

    return groupNames;
}

From source file:org.efaps.esjp.accounting.transaction.Create_Base.java

/**
 * Creates the transaction doc for contact.
 *
 * @param _parameter Parameter as passed by the eFaps API
 * @throws EFapsException on error/*from   w  w w .j  a v a  2s  . c  o  m*/
 */
protected void createTransactionDoc4Contact(final Parameter _parameter) throws EFapsException {
    final Map<String, String> map = new HashMap<>();
    createTransactionDoc4Contact(_parameter, map, "Debit");
    createTransactionDoc4Contact(_parameter, map, "Credit");

    final String[] docOids = _parameter.getParameterValues("document");
    if (ArrayUtils.isNotEmpty(docOids)) {
        for (int i = 0; i < docOids.length; i++) {
            final Instance inst = Instance.get(docOids[i]);
            if (InstanceUtils.isKindOf(inst, CIContacts.ContactAbstract) && map.containsKey(docOids[i])) {
                docOids[i] = map.get(docOids[i]);
            }
        }
    }
}