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

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

Introduction

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

Prototype

public static boolean contains(boolean[] array, boolean valueToFind) 

Source Link

Document

Checks if the value is in the given array.

Usage

From source file:com.adobe.acs.commons.workflow.bulk.execution.model.Workspace.java

/**
 * Removes the payload group from the list of active payload groups.
 *
 * @param payloadGroup the payload group to remove from the active list.
 *///from  ww w .j a va2 s .  c om
public void removeActivePayloadGroup(PayloadGroup payloadGroup) {
    if (payloadGroup != null && ArrayUtils.contains(activePayloadGroups, payloadGroup.getDereferencedPath())) {
        activePayloadGroups = (String[]) ArrayUtils.removeElement(activePayloadGroups,
                payloadGroup.getDereferencedPath());
        properties.put(PN_ACTIVE_PAYLOAD_GROUPS, activePayloadGroups);
    }
}

From source file:com.gzj.tulip.jade.context.spring.JadeBeanFactoryPostProcessor.java

public String getStatementWrapperProvider(ConfigurableListableBeanFactory beanFactory) {
    if (statmentWrapperProviderName == null) {
        String[] names = beanFactory.getBeanNamesForType(StatementWrapperProvider.class);
        if (names.length == 0) {
            statmentWrapperProviderName = "none";
        } else if (names.length == 1) {
            statmentWrapperProviderName = names[0];
        } else {// w ww .jav a2  s. c  o m
            String topPriority = "jade.statmentWrapperProvider";
            if (ArrayUtils.contains(names, topPriority)) {
                statmentWrapperProviderName = topPriority;
            } else {
                throw new IllegalStateException(
                        "required not more than 1 StatmentWrapperProvider, but found " + names.length);
            }
        }
    }
    return "none".equals(statmentWrapperProviderName) ? null : statmentWrapperProviderName;
}

From source file:de.juwimm.cms.gui.admin.PanUnitGroupPerUser.java

private synchronized void saveChanges(int row) {
    if (this.unitPickData.isModified() || this.groupPickData.isModified()) {
        try {//  w  ww  .  j  a v  a  2 s  .  c  o  m
            tblUser.setEnabled(false);
            UserValue user = getSelectedUser(row);

            GroupValue[] groups = comm.getGroups4User(user.getUserName());
            DropDownHolder[] groupList = null;
            if (groups != null) {
                groupList = new DropDownHolder[groups.length];
                for (int i = groups.length - 1; i >= 0; i--) {
                    groupList[i] = new DropDownHolder(groups[i], groups[i].getGroupName());
                }
            }
            UnitValue[] units = comm.getUnits4User(user.getUserName());
            DropDownHolder[] unitList = null;
            if (units != null) {
                unitList = new DropDownHolder[units.length];
                for (int i = units.length - 1; i >= 0; i--) {
                    unitList[i] = new DropDownHolder(units[i], units[i].getName());
                }
            }

            for (int i = 0; i < groupList.length; i++) {
                if (!this.groupPickData.getLstLeftModel().contains(groupList[i])) {
                    try {
                        comm.removeUserFromGroup(((GroupValue) groupList[i].getObject()), user.getUserName());
                    } catch (Exception exe) {
                        log.error("Error removing user from group: ", exe);
                    }
                }
            }
            for (int i = 0; i < this.groupPickData.getLstLeftModel().getSize(); i++) {
                GroupValue group = (GroupValue) ((DropDownHolder) this.groupPickData.getLstLeftModel()
                        .getElementAt(i)).getObject();
                if (!ArrayUtils.contains(groups, group)) {
                    try {
                        comm.addUserToGroup(group, user.getUserName());
                    } catch (Exception exe) {
                        log.error("Error adding user to group: ", exe);
                    }
                }
            }

            if (!comm.isUserInRole(user, UserRights.SITE_ROOT)) {
                for (int i = 0; i < unitList.length; i++) {
                    if (!this.unitPickData.getLstLeftModel().contains(unitList[i])) {
                        try {
                            comm.removeUserFromUnit(((UnitValue) unitList[i].getObject()), user.getUserName());
                        } catch (Exception exe) {
                            log.error("Error removing unser from unit: ", exe);
                        }
                    }
                }
                for (int i = 0; i < this.unitPickData.getLstLeftModel().getSize(); i++) {
                    UnitValue unit = (UnitValue) ((DropDownHolder) this.unitPickData.getLstLeftModel()
                            .getElementAt(i)).getObject();
                    if (!ArrayUtils.contains(units, unit)) {
                        try {
                            comm.addUser2Unit(user, unit);
                        } catch (Exception exe) {
                            log.error("Error adding user to unit: ", exe);
                        }
                    }
                }
            }
        } catch (Exception exe) {
            log.error(exe);
        }
    }
    this.unitPickData.setModified(false);
    this.groupPickData.setModified(false);
    tblUser.setEnabled(true);
}

From source file:com.ecyrd.jspwiki.auth.authorize.GroupManager.java

/**
 * <p>// w  ww  .j  ava2  s.  c o  m
 * Extracts group name and members from passed parameters and populates an
 * existing Group with them. The Group will either be a copy of an existing
 * Group (if one can be found), or a new, unregistered Group (if not).
 * Optionally, this method can throw a WikiSecurityException if the Group
 * does not yet exist in the GroupManager cache.
 * </p>
 * <p>
 * The <code>group</code> parameter in the HTTP request contains the Group
 * name to look up and populate. The <code>members</code> parameter
 * contains the member list. If these differ from those in the existing
 * group, the passed values override the old values.
 * </p>
 * <p>
 * This method does not commit the new Group to the GroupManager cache. To
 * do that, use {@link #setGroup(WikiSession, Group)}.
 * </p>
 * @param name the name of the group to construct
 * @param memberLine the line of text containing the group membership list
 * @param create whether this method should create a new, empty Group if one
 *            with the requested name is not found. If <code>false</code>,
 *            groups that do not exist will cause a
 *            <code>NoSuchPrincipalException</code> to be thrown
 * @return a new, populated group
 * @see com.ecyrd.jspwiki.auth.authorize.Group#RESTRICTED_GROUPNAMES
 * @throws WikiSecurityException if the group name isn't allowed, or if
 * <code>create</code> is <code>false</code>
 * and the Group named <code>name</code> does not exist
 */
public final Group parseGroup(String name, String memberLine, boolean create) throws WikiSecurityException {
    // If null name parameter, it's because someone's creating a new group
    if (name == null) {
        if (create) {
            name = "MyGroup";
        } else {
            throw new WikiSecurityException("Group name cannot be blank.");
        }
    } else if (ArrayUtils.contains(Group.RESTRICTED_GROUPNAMES, name)) {
        // Certain names are forbidden
        throw new WikiSecurityException("Illegal group name: " + name);
    }
    name = name.trim();

    // Normalize the member line
    if (InputValidator.isBlank(memberLine)) {
        memberLine = "";
    }
    memberLine = memberLine.trim();

    // Create or retrieve the group (may have been previously cached)
    Group group = new Group(name, m_engine.getApplicationName());
    try {
        Group existingGroup = getGroup(name);

        // If existing, clone it
        group.setCreator(existingGroup.getCreator());
        group.setCreated(existingGroup.getCreated());
        group.setModifier(existingGroup.getModifier());
        group.setLastModified(existingGroup.getLastModified());
        for (Principal existingMember : existingGroup.members()) {
            group.add(existingMember);
        }
    } catch (NoSuchPrincipalException e) {
        // It's a new group.... throw error if we don't create new ones
        if (!create) {
            throw new NoSuchPrincipalException("Group '" + name + "' does not exist.");
        }
    }

    // If passed members not empty, overwrite
    String[] members = extractMembers(memberLine);
    if (members.length > 0) {
        group.clear();
        for (String member : members) {
            group.add(new WikiPrincipal(member));
        }
    }

    return group;
}

From source file:com.bstek.dorado.web.loader.DoradoLoader.java

public synchronized void preload(ServletContext servletContext, boolean processOriginContextConfigLocation)
        throws Exception {
    if (preloaded) {
        throw new IllegalStateException("Dorado base configurations already loaded.");
    }//from  w w w  . j a  v  a 2  s.  c  o m
    preloaded = true;

    // ?
    ConsoleUtils.outputLoadingInfo("Initializing " + DoradoAbout.getProductTitle() + " engine...");
    ConsoleUtils.outputLoadingInfo("[Vendor: " + DoradoAbout.getVendor() + "]");

    ConfigureStore configureStore = Configure.getStore();
    doradoHome = System.getenv("DORADO_HOME");

    // ?DoradoHome
    String intParam;
    intParam = servletContext.getInitParameter("doradoHome");
    if (intParam != null) {
        doradoHome = intParam;
    }
    if (doradoHome == null) {
        doradoHome = DEFAULT_DORADO_HOME;
    }

    configureStore.set(HOME_PROPERTY, doradoHome);
    ConsoleUtils.outputLoadingInfo("[Home: " + StringUtils.defaultString(doradoHome, "<not assigned>") + "]");

    // ResourceLoader
    ResourceLoader resourceLoader = new ServletContextResourceLoader(servletContext) {
        @Override
        public Resource getResource(String resourceLocation) {
            if (resourceLocation != null && resourceLocation.startsWith(HOME_LOCATION_PREFIX)) {
                resourceLocation = ResourceUtils.concatPath(doradoHome,
                        resourceLocation.substring(HOME_LOCATION_PREFIX_LEN));
            }
            return super.getResource(resourceLocation);
        }
    };

    String runMode = null;
    if (StringUtils.isNotEmpty(doradoHome)) {
        String configureLocation = HOME_LOCATION_PREFIX + "configure.properties";
        loadConfigureProperties(configureStore, resourceLoader, configureLocation, false);
    }

    runMode = configureStore.getString("core.runMode");

    if (StringUtils.isNotEmpty(runMode)) {
        loadConfigureProperties(configureStore, resourceLoader,
                CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true);

        if (StringUtils.isNotEmpty(doradoHome)) {
            loadConfigureProperties(configureStore, resourceLoader,
                    HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true);
        }
    }

    ConsoleUtils.outputConfigureItem("core.runMode");
    ConsoleUtils.outputConfigureItem("core.addonLoadMode");

    File tempDir;
    String tempDirPath = configureStore.getString("core.tempDir");
    if (StringUtils.isNotBlank(tempDirPath)) {
        tempDir = new File(tempDirPath);
    } else {
        tempDir = new File(WebUtils.getTempDir(servletContext), ".dorado");
    }

    boolean supportsTempFile = configureStore.getBoolean("core.supportsTempFile");
    TempFileUtils.setSupportsTempFile(supportsTempFile);
    if (supportsTempFile) {
        if ((tempDir.exists() && tempDir.isDirectory()) || tempDir.mkdir()) {
            TempFileUtils.setTempDir(tempDir);
        }
        ConsoleUtils.outputLoadingInfo("[TempDir: " + TempFileUtils.getTempDir().getPath() + "]");
    } else {
        ConsoleUtils.outputLoadingInfo("Temp file is forbidden.");
    }

    // 
    File storeDir;
    String storeDirSettring = configureStore.getString("core.storeDir");
    if (StringUtils.isNotEmpty(storeDirSettring)) {
        storeDir = new File(storeDirSettring);
        File testFile = new File(storeDir, ".test");
        if (!testFile.mkdirs()) {
            throw new IllegalStateException(
                    "Store directory [" + storeDir.getAbsolutePath() + "] is not writable in actually.");
        }
        testFile.delete();
    } else {
        storeDir = new File(tempDir, "dorado-store");
        configureStore.set("core.storeDir", storeDir.getAbsolutePath());
    }
    ConsoleUtils.outputConfigureItem("core.storeDir");

    // gothrough packages
    String addonLoadMode = Configure.getString("core.addonLoadMode");
    String[] enabledAddons = StringUtils.split(Configure.getString("core.enabledAddons"), ",; \n\r");
    String[] disabledAddon = StringUtils.split(Configure.getString("core.disabledAddon"), ",; \n\r");

    Collection<PackageInfo> packageInfos = PackageManager.getPackageInfoMap().values();
    int addonNumber = 0;
    for (PackageInfo packageInfo : packageInfos) {
        String packageName = packageInfo.getName();
        if (packageName.equals("dorado-core")) {
            continue;
        }

        if (addonNumber > 9999) {
            packageInfo.setEnabled(false);
        } else if (StringUtils.isEmpty(addonLoadMode) || "positive".equals(addonLoadMode)) {
            packageInfo.setEnabled(!ArrayUtils.contains(disabledAddon, packageName));
        } else {
            // addonLoadMode == negative
            packageInfo.setEnabled(ArrayUtils.contains(enabledAddons, packageName));
        }

        if (packageInfo.isEnabled()) {
            addonNumber++;
        }
    }

    // print packages
    int i = 0;
    for (PackageInfo packageInfo : packageInfos) {
        ConsoleUtils.outputLoadingInfo(
                StringUtils.rightPad(String.valueOf(++i) + '.', 4) + "Package [" + packageInfo.getName() + " - "
                        + StringUtils.defaultIfBlank(packageInfo.getVersion(), "<Unknown Version>") + "] found."
                        + ((packageInfo.isEnabled() ? "" : " #DISABLED# ")));
    }

    // load packages
    for (PackageInfo packageInfo : packageInfos) {
        if (!packageInfo.isEnabled()) {
            pushLocations(contextLocations, packageInfo.getComponentLocations());
            continue;
        }

        PackageListener packageListener = packageInfo.getListener();
        if (packageListener != null) {
            packageListener.beforeLoadPackage(packageInfo, resourceLoader);
        }

        PackageConfigurer packageConfigurer = packageInfo.getConfigurer();

        if (StringUtils.isNotEmpty(packageInfo.getPropertiesLocations())) {
            for (String location : org.springframework.util.StringUtils.tokenizeToStringArray(
                    packageInfo.getPropertiesLocations(),
                    ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS)) {
                loadConfigureProperties(configureStore, resourceLoader, location, false);
            }
        }

        String[] locations;
        if (packageConfigurer != null) {
            locations = packageConfigurer.getPropertiesConfigLocations(resourceLoader);
            if (locations != null) {
                for (String location : locations) {
                    loadConfigureProperties(configureStore, resourceLoader, location, false);
                }
            }
        }

        // ?Spring?
        pushLocations(contextLocations, packageInfo.getContextLocations());
        if (packageConfigurer != null) {
            locations = packageConfigurer.getContextConfigLocations(resourceLoader);
            if (locations != null) {
                for (String location : locations) {
                    pushLocation(contextLocations, location);
                }
            }
        }

        pushLocations(servletContextLocations, packageInfo.getServletContextLocations());
        if (packageConfigurer != null) {
            locations = packageConfigurer.getServletContextConfigLocations(resourceLoader);
            if (locations != null) {
                for (String location : locations) {
                    pushLocation(servletContextLocations, location);
                }
            }
        }

        packageInfo.setLoaded(true);
    }

    // ?dorado-homepropertiesaddon
    if (StringUtils.isNotEmpty(doradoHome)) {
        String configureLocation = HOME_LOCATION_PREFIX + "configure.properties";
        loadConfigureProperties(configureStore, resourceLoader, configureLocation, true);
        if (StringUtils.isNotEmpty(runMode)) {
            loadConfigureProperties(configureStore, resourceLoader,
                    CORE_PROPERTIES_LOCATION_PREFIX + "configure-" + runMode + ".properties", true);
            loadConfigureProperties(configureStore, resourceLoader,
                    HOME_LOCATION_PREFIX + "configure-" + runMode + ".properties", true);
        }
    }

    Resource resource;

    // context
    if (processOriginContextConfigLocation) {
        intParam = servletContext.getInitParameter(CONTEXT_CONFIG_LOCATION);
        if (intParam != null) {
            pushLocations(contextLocations, intParam);
        }
    }

    resource = resourceLoader.getResource(HOME_CONTEXT_XML);
    if (resource.exists()) {
        pushLocations(contextLocations, HOME_CONTEXT_XML);
    }

    if (StringUtils.isNotEmpty(runMode)) {
        String extHomeContext = HOME_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT;
        resource = resourceLoader.getResource(extHomeContext);
        if (resource.exists()) {
            pushLocations(contextLocations, extHomeContext);
        }
    }

    // servlet-context
    intParam = servletContext.getInitParameter(SERVLET_CONTEXT_CONFIG_LOCATION);
    if (intParam != null) {
        pushLocations(servletContextLocations, intParam);
    }
    resource = resourceLoader.getResource(HOME_SERVLET_CONTEXT_XML);
    if (resource.exists()) {
        pushLocations(servletContextLocations, HOME_SERVLET_CONTEXT_XML);
    }

    if (StringUtils.isNotEmpty(runMode)) {
        String extHomeContext = HOME_SERVLET_CONTEXT_PREFIX + '-' + runMode + CONTEXT_FILE_EXT;
        resource = resourceLoader.getResource(extHomeContext);
        if (resource.exists()) {
            pushLocations(servletContextLocations, extHomeContext);
        }
    }

    ConsoleUtils.outputConfigureItem(RESOURCE_LOADER_PROPERTY);
    ConsoleUtils.outputConfigureItem(BYTE_CODE_PROVIDER_PROPERTY);

    String contextLocationsFromProperties = configureStore.getString(CONTEXT_CONFIG_PROPERTY);
    if (contextLocationsFromProperties != null) {
        pushLocations(contextLocations, contextLocationsFromProperties);
    }
    configureStore.set(CONTEXT_CONFIG_PROPERTY, StringUtils.join(getRealResourcesPath(contextLocations), ';'));
    ConsoleUtils.outputConfigureItem(CONTEXT_CONFIG_PROPERTY);

    String serlvetContextLocationsFromProperties = configureStore.getString(SERVLET_CONTEXT_CONFIG_PROPERTY);
    if (serlvetContextLocationsFromProperties != null) {
        pushLocations(servletContextLocations, serlvetContextLocationsFromProperties);
    }
    configureStore.set(SERVLET_CONTEXT_CONFIG_PROPERTY,
            StringUtils.join(getRealResourcesPath(servletContextLocations), ';'));
    ConsoleUtils.outputConfigureItem(SERVLET_CONTEXT_CONFIG_PROPERTY);

    // ?WebContext
    DoradoContext context = DoradoContext.init(servletContext, false);
    Context.setFailSafeContext(context);
}

From source file:net.sf.firemox.clickable.target.card.MCard.java

/**
 * Indicates if propertyBIG contains completely propertyMatched. <br>
 * /*from   w w w  .  j a  v a2  s . co m*/
 * @param propertyBIG
 *          are the set of properties.
 * @param propertyMatched
 *          is the property we match.
 * @return true if propertyBIG contains completely propertyMatched. <br>
 */
public static boolean hasProperty(int[] propertyBIG, int propertyMatched) {
    return ArrayUtils.contains(propertyBIG, propertyMatched);
}

From source file:com.agimatec.validation.jsr303.Jsr303MetaBeanFactory.java

private boolean processValid(MetaProperty prop, AccessStrategy access) {
    if (prop != null/* && prop.getMetaBean() == null*/) {
        AccessStrategy[] strategies = prop.getFeature(Features.Property.REF_CASCADE);
        if (strategies == null) {
            strategies = new AccessStrategy[] { access };
            prop.putFeature(Features.Property.REF_CASCADE, strategies);
        } else {//from   w  w w.  j  ava 2s  .  c o m
            if (!ArrayUtils.contains(strategies, access)) {
                AccessStrategy[] strategies_new = new AccessStrategy[strategies.length + 1];
                System.arraycopy(strategies, 0, strategies_new, 0, strategies.length);
                strategies_new[strategies.length] = access;
                prop.putFeature(Features.Property.REF_CASCADE, strategies_new);
            }
        }
        return true;
    }
    return false;
}

From source file:com.activecq.samples.workflow.impl.LocalizedTagTitleExtractorProcessWorkflow.java

/**
 * Derive the locale from the parent path segments (/content/us/en/..)
 *
 * @param resource//  w w  w. jav  a  2 s .  c  o m
 * @return
 */
private Locale getLocaleFromPath(final Resource resource) {
    final String[] segments = StringUtils.split(resource.getPath(), PATH_DELIMITER);

    String country = "";
    String language = "";

    for (final String segment : segments) {
        if (ArrayUtils.contains(Locale.getISOCountries(), segment)) {
            country = segment;
        } else if (ArrayUtils.contains(Locale.getISOLanguages(), segment)) {
            language = segment;
        }
    }

    if (StringUtils.isNotBlank(country) && StringUtils.isNotBlank(language)) {
        return LocaleUtils.toLocale(country + "-" + language);
    } else if (StringUtils.isNotBlank(country)) {
        return LocaleUtils.toLocale(country);
    } else if (StringUtils.isNotBlank(language)) {
        return LocaleUtils.toLocale(language);
    }

    return null;
}

From source file:com.athena.chameleon.engine.Starter.java

/**
 * <pre>/*ww  w  . j av a 2  s .  co  m*/
 * ? ? ?  ?? ? 
 * </pre>
 * 
 * @param fqfn
 * @return
 */
private static boolean isValidApplicationExtension(String fqfn) {
    return ArrayUtils.contains(SUPPORT_DEPLOY_FORMAT, fqfn.substring(fqfn.lastIndexOf(".") + 1).toLowerCase());
}

From source file:com.ultrapower.eoms.common.plugin.ecside.view.html.FormBuilder.java

    public void userDefinedParameters() {
        Map parameterMap = model.getRegistry().getParameterMap();
        //from   w  ww . j a v a 2  s  .c  om
       String includeParameters=table.getIncludeParameters();
       String excludeParameters=table.getExcludeParameters();
       
//       includeParameters=StringUtils.isNotBlank(includeParameters)?","+includeParameters+",":null;
//       excludeParameters=StringUtils.isNotBlank(excludeParameters)?","+excludeParameters+",":null;
       
        Set keys = parameterMap.keySet();
        String[] keyField=new String[]{
              ECSideConstants.EASY_DATA_ACCESS_FLAG,
              ECSideConstants.EASY_DATA_LIST_FLAG,
              ECSideConstants.EASY_DATA_EXPORT_FLAG
        };

        for (Iterator iter = keys.iterator(); iter.hasNext();) {
            String name = (String) iter.next();

            if (name.startsWith(model.getTableHandler().prefixWithTableId())
                  || excludeParameters!=null && isInParameters(excludeParameters,name) 
                  || includeParameters!=null && !isInParameters(includeParameters,name)
                  || ArrayUtils.contains(keyField, name)
                  ){
                continue;
            }

            String values[] = (String[]) parameterMap.get(name);
            if (values == null || values.length == 0) {
                html.newline();
                html.input("hidden").name(name).xclose();
            } else {
                for (int i = 0; i < values.length; i++) {
                    html.newline();
                    html.input("hidden").name(name).value(values[i]).xclose();
                }
            }
        }
    }