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.hyeb.back.login.LoginController.java

/**
 * //ww  w .j a  v  a 2  s .  com
 */
@RequestMapping(value = "/login")
public String login(ModelMap model, RedirectAttributes redirectAttributes, HttpServletRequest request) {
    /** "?"??? */
    final String PRIVATE_KEY_ATTRIBUTE_NAME = "privateKey";

    //HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();       
    Setting setting = SettingUtils.get();
    KeyPair keyPair = RSAUtils.generateKeyPair();
    RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
    RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
    request.getSession().setAttribute(PRIVATE_KEY_ATTRIBUTE_NAME, privateKey);

    String modulus = Base64.encodeBase64String(publicKey.getModulus().toByteArray());//N
    String exponent = Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray());//e
    String captchaId = UUID.randomUUID().toString();
    boolean isBackCaptcha = ArrayUtils.contains(setting.getCaptchaTypes(), CaptchaType.adminLogin);
    model.addAttribute("modulus", modulus);
    model.addAttribute("exponent", exponent);
    model.addAttribute("captchaId", captchaId);
    model.addAttribute("isBackCaptcha", isBackCaptcha);
    String messageStr = null;
    String loginFailure = (String) request
            .getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
    if (loginFailure != null) {
        if (loginFailure.equals("org.apache.shiro.authc.pam.UnsupportedTokenException")) {//??
            messageStr = "admin.captcha.invalid";
        } else if (loginFailure.equals("org.apache.shiro.authc.UnknownAccountException")) {//
            messageStr = "admin.login.unknownAccount";
        } else if (loginFailure.equals("org.apache.shiro.authc.DisabledAccountException")) {//?
            messageStr = "admin.login.disabledAccount";//
        } else if (loginFailure.equals("org.apache.shiro.authc.LockedAccountException")) {//?
            messageStr = "admin.login.lockedAccount";
        } else if (loginFailure.equals("org.apache.shiro.authc.IncorrectCredentialsException")) {//??

            if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) {
                messageStr = "admin.login.accountLockCount";//?{0}???
            } else {
                messageStr = "admin.login.incorrectCredentials";//???
            }
        } else if (loginFailure.equals("org.apache.shiro.authc.AuthenticationException")) {//
            messageStr = "admin.login.authentication";//??
        }
        if (messageStr != null) {
            Message message = Message.warn(messageStr);
            addFlashMessage(redirectAttributes, message);
        }
    }
    Subject subject = SecurityUtils.getSubject();
    if (subject.isAuthenticated()) {
        return "redirect:/back/main/main";
    } else {
        return "/back/login/login";
    }

}

From source file:edu.isistan.carcha.annotator.AnnotationRemover.java

@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
    List<TOP> tops = new ArrayList<TOP>(JCasUtil.selectAll(jCas));
    for (TOP t : tops) {
        if (!ArrayUtils.contains(annotationToKeep, t.getType().getName()))
            t.removeFromIndexes();//from  ww  w  .j  ava 2s .  c om
    }
}

From source file:com.codebutler.farebot.activities.ReadingTagActivity.java

private void resolveIntent(Intent intent) {
    final TextView textView = (TextView) findViewById(R.id.textView);

    try {/*from   www  . j  a va  2 s. c o m*/
        Bundle extras = intent.getExtras();

        final Tag tag = (Tag) extras.getParcelable("android.nfc.extra.TAG");
        ;
        final String[] techs = tag.getTechList();

        new AsyncTask<Void, String, MifareCard>() {
            Exception mException;

            @Override
            protected MifareCard doInBackground(Void... params) {
                try {
                    if (ArrayUtils.contains(techs, "android.nfc.tech.NfcB"))
                        return CEPASCard.dumpTag(tag.getId(), tag);
                    else if (ArrayUtils.contains(techs, "android.nfc.tech.IsoDep"))
                        return DesfireCard.dumpTag(tag.getId(), tag);
                    else
                        throw new UnsupportedTagException(techs, Utils.getHexString(tag.getId()));
                } catch (Exception ex) {
                    mException = ex;
                    return null;
                }
            }

            @Override
            protected void onPostExecute(MifareCard card) {
                if (mException != null) {
                    if (mException instanceof UnsupportedTagException) {
                        UnsupportedTagException ex = (UnsupportedTagException) mException;
                        new AlertDialog.Builder(ReadingTagActivity.this).setTitle("Unsupported Tag")
                                .setMessage(ex.getMessage()).setCancelable(false)
                                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface arg0, int arg1) {
                                        finish();
                                    }
                                }).show();
                    } else {
                        Utils.showErrorAndFinish(ReadingTagActivity.this, mException);
                    }
                    return;
                }

                try {
                    String cardXml = Utils.xmlNodeToString(card.toXML().getOwnerDocument());

                    ContentValues values = new ContentValues();
                    values.put(CardsTableColumns.TYPE, card.getCardType().toInteger());
                    values.put(CardsTableColumns.TAG_SERIAL, Utils.getHexString(card.getTagId()));
                    values.put(CardsTableColumns.DATA, cardXml);
                    values.put(CardsTableColumns.SCANNED_AT, card.getScannedAt().getTime());

                    Uri uri = getContentResolver().insert(CardProvider.CONTENT_URI_CARD, values);
                    startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    finish();
                } catch (Exception ex) {
                    Utils.showErrorAndFinish(ReadingTagActivity.this, ex);
                }
            }

            @Override
            protected void onProgressUpdate(String... values) {
                textView.setText(values[0]);
            }

        }.execute();

    } catch (Exception ex) {
        Utils.showErrorAndFinish(this, ex);
    }
}

From source file:net.sourceforge.atunes.kernel.modules.player.PlayerEngineSelector.java

/**
 * Selects player engine//from   w  w  w  .j  av a  2s  . c  om
 * 
 * @return player engine or null
 */
IPlayerEngine selectPlayerEngine() {
    List<AbstractPlayerEngine> availableEngines = getAvailableEngines();
    if (availableEngines.isEmpty()) {
        return null;
    }

    engineNames = getEngineNames(availableEngines);
    Logger.info("List of availables engines : ", ArrayUtils.toString(engineNames));

    // Get engine of application state (default or selected by user)
    String selectedEngine = statePlayer.getPlayerEngine();

    // If selected engine is not available then try default engine or
    // another one
    if (!ArrayUtils.contains(engineNames, selectedEngine)) {
        Logger.info(selectedEngine, " is not availaible");
        selectedEngine = selectDefaultEngine(availableEngines);
    }

    for (AbstractPlayerEngine engine : availableEngines) {
        if (engine.getEngineName().equals(selectedEngine)) {
            return engine;
        }
    }

    return null;
}

From source file:com.google.gdt.eclipse.designer.smart.parser.ClassLoaderValidator.java

/**
 * @return the description of invalid version, or <code>null</code> if version in valid.
 *//* w  w w .java  2  s . c  o m*/
private static String getWrongVersionDescription(final ClassLoader classLoader) {
    return ExecutionUtils.runObject(new RunnableObjectEx<String>() {
        public String runObject() throws Exception {
            Class<?> classVersion = classLoader.loadClass("com.smartgwt.client.Version");
            String version = (String) ReflectionUtils.invokeMethod(classVersion, "getVersion()");
            if (ArrayUtils.contains(VALID_VERSIONS, version)) {
                initializeSmartGWT(classLoader);
                return null;
            }
            return version;
        }
    }, "See logged exception");
}

From source file:ch.uzh.ifi.attempto.chartparser.Category.java

/**
 * Returns true if this category is a special category. Special categories are references, scope
 * openers, and position operators./*  www.  j  a va  2 s.  c  o m*/
 * 
 * @return true if this category is a special category.
 */
public boolean isSpecialCategory() {
    return ArrayUtils.contains(specialCategories, name);
}

From source file:com.pureinfo.srm.reports.table.MyTabeleDataHelper.java

public static Map getRowMap(Class _contentClass, SQLCondition _condition, String _sGroupProp,
        String[] _caredValues) throws PureException {
    IContentMgr mgr = ArkContentHelper.getContentMgrOf(_contentClass);
    List params = new ArrayList();
    IObjects datas = null;// ww  w  .j av a2s . c  om
    IStatement query = null;
    Map row = null;
    try {
        String sCondion = "";
        if (_condition != null)
            sCondion = _condition.toSQL(params);
        String strSQL = "SELECT COUNT(*) AS _COUNT, {this." + _sGroupProp + "} FROM {this}"
                + (sCondion == null || sCondion.trim().length() < 1 ? "" : " WHERE ") + sCondion
                + " GROUP BY {this." + _sGroupProp + '}';
        query = mgr.createQuery(strSQL, 0);
        if (!params.isEmpty()) {
            query.setParameters(0, params);
        }
        datas = query.executeQuery();
        row = new HashMap(datas.getSize());
        do {
            DolphinObject data = datas.next();
            if (data == null) {
                break;
            }
            row.put(data.getProperty(_sGroupProp), data.getProperty("_COUNT"));
        } while (true);
    } finally {
        params.clear();
        DolphinHelper.clear(datas, query);
    }
    if (_caredValues != null) {
        int caredTotal = 0;
        int total = 0;
        for (Iterator iter = row.entrySet().iterator(); iter.hasNext();) {
            Map.Entry entry = (Map.Entry) iter.next();
            String sName = (String) entry.getKey();
            Number num = (Number) entry.getValue();
            if (ArrayUtils.contains(_caredValues, sName)) {
                caredTotal += num.intValue();
            }
            total += num.intValue();
        }
        row.put(OTHER, new Integer(total - caredTotal));
        row.put(TOTAL, new Integer(total));
    }
    return row;
}

From source file:com.linkedin.bowser.core.objects.TupleObject.java

@Override
public boolean contains(NQLObject o) {
    return ArrayUtils.contains(_tuple, o);
}

From source file:com.healthcit.analytics.dao.CouchDBDaoUtils.java

/**
 * Constructs a URL-encoded String of request parameters from a set of parameter key/value pairs.
 * @param paramKeys/*from  www  .  j a v  a  2s .com*/
 * @param paramValues
 * @return
 */
@SuppressWarnings("unchecked")
public static String constructParameterList(HttpServletRequest request) {
    Enumeration<String> requestParamNames = request.getParameterNames();

    List<String> names = new ArrayList<String>();

    List<String> values = new ArrayList<String>();

    while (requestParamNames.hasMoreElements()) {
        String element = requestParamNames.nextElement();

        if (ArrayUtils.contains(STANDARD_COUCHDB_PARAM_NAMES, element)) {
            names.add(element);

            values.add(request.getParameter(element));
        }
    }

    StringBuffer str = new StringBuffer();

    if (names != null && names.size() == values.size()) {
        for (int i = 0; i < names.size(); ++i) {
            if (i > 0)
                str.append("&");

            String key = names.get(i);

            String value = values.get(i);

            str.append(key);

            str.append("=");

            try {
                str.append(URLEncoder.encode(value, UTF8));
            } catch (UnsupportedEncodingException e) {
            }
        }
    }
    return str.toString();
}

From source file:net.shopxx.controller.admin.LoginController.java

@RequestMapping
public String index(HttpServletRequest request, ModelMap model) {
    String loginToken = WebUtils.getCookie(request, Admin.LOGIN_TOKEN_COOKIE_NAME);
    if (!StringUtils.equalsIgnoreCase(loginToken, adminService.getLoginToken())) {
        return "redirect:/";
    }/*from  w  ww. java  2 s.  co m*/
    if (adminService.isAuthenticated()) {
        return "redirect:common/main.jhtml";
    }
    Message failureMessage = null;
    String loginFailure = (String) request
            .getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
    if (StringUtils.isNotEmpty(loginFailure)) {
        if (loginFailure.equals("net.shopxx.exception.IncorrectCaptchaException")) {
            failureMessage = Message.error("admin.captcha.invalid");
        } else if (loginFailure.equals("org.apache.shiro.authc.UnknownAccountException")) {
            failureMessage = Message.error("admin.login.unknownAccount");
        } else if (loginFailure.equals("org.apache.shiro.authc.DisabledAccountException")) {
            failureMessage = Message.error("admin.login.disabledAccount");
        } else if (loginFailure.equals("org.apache.shiro.authc.LockedAccountException")) {
            failureMessage = Message.error("admin.login.lockedAccount");
        } else if (loginFailure.equals("org.apache.shiro.authc.IncorrectCredentialsException")) {
            Setting setting = SystemUtils.getSetting();
            if (ArrayUtils.contains(setting.getAccountLockTypes(), Setting.AccountLockType.admin)) {
                failureMessage = Message.error("admin.login.accountLockCount", setting.getAccountLockCount());
            } else {
                failureMessage = Message.error("admin.login.incorrectCredentials");
            }
        } else if (loginFailure.equals("net.shopxx.exception.IncorrectLicenseException")) {
            failureMessage = Message.error("admin.login.incorrectLicense");
        } else if (loginFailure.equals("org.apache.shiro.authc.AuthenticationException")) {
            failureMessage = Message.error("admin.login.authentication");
        }
    }
    RSAPublicKey publicKey = rsaService.generateKey(request);
    model.addAttribute("modulus", Base64.encodeBase64String(publicKey.getModulus().toByteArray()));
    model.addAttribute("exponent", Base64.encodeBase64String(publicKey.getPublicExponent().toByteArray()));
    model.addAttribute("captchaId", UUID.randomUUID().toString());
    model.addAttribute("failureMessage", failureMessage);
    return "/admin/login/index";
}