Example usage for org.apache.commons.lang3 StringUtils equalsIgnoreCase

List of usage examples for org.apache.commons.lang3 StringUtils equalsIgnoreCase

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils equalsIgnoreCase.

Prototype

public static boolean equalsIgnoreCase(final CharSequence str1, final CharSequence str2) 

Source Link

Document

Compares two CharSequences, returning true if they represent equal sequences of characters, ignoring case.

null s are handled without exceptions.

Usage

From source file:io.ehdev.json.validation.pojo.validation.JsonValidationEnum.java

private boolean checkNonCaseSensitive(String inputValue) {
    for (String value : enumValues) {
        if (StringUtils.equalsIgnoreCase(value, inputValue))
            return true;
    }/*  ww w. ja v  a 2  s.  c om*/

    return false;
}

From source file:com.threewks.thundr.http.ContentType.java

/**
 * Returns true if the given string content type matches the content type represented by this enum value.
 * //from   w  w w.jav  a2 s.co  m
 * @param contentType
 * @return
 */
public boolean matches(String contentType) {
    return StringUtils.equalsIgnoreCase(this.value, cleanContentType(contentType));
}

From source file:com.yqboots.web.thymeleaf.processor.element.MenuElementProcessor.java

/**
 * {@inheritDoc}//from w  w w.j  a  v  a 2  s . c o  m
 */
@Override
protected List<Node> getMarkupSubstitutes(final Arguments arguments, final Element element) {
    final List<Node> nodes = new ArrayList<>();

    final SpringWebContext context = (SpringWebContext) arguments.getContext();
    final MenuItemManager manager = context.getApplicationContext().getBean(MenuItemManager.class);
    final List<MenuItem> menuItems = manager.getMenuItems();

    final String layoutAttrValue = element.getAttributeValue(ATTR_LAYOUT);
    if (StringUtils.equalsIgnoreCase(layoutAttrValue, LAYOUT_FULL_WIDTH)) {
        Map<String, Map<String, List<MenuItem>>> groups = menuGroupsConverter.convert(menuItems);
        nodes.addAll(new MenuGroupBuilder(arguments).build(groups));
    } else {
        // default layout
        Map<String, List<MenuItem>> groups = menuItemGroupsConverter.convert(menuItems);
        nodes.addAll(new MenuItemGroupBuilder(arguments).build(groups));
    }

    return nodes;
}

From source file:com.nesscomputing.tinyhttp.HttpContentResponseHandler.java

/**
 * Processes the client response./* w  w w.ja v  a 2s . co m*/
 */
public T handle(final HttpRequest request, final HttpResponse response) throws IOException {
    // Find the response stream - the error stream may be valid in cases
    // where the input stream is not.
    InputStream is = null;
    try {
        final HttpEntity httpEntity = response.getEntity();
        if (httpEntity != null) {
            is = httpEntity.getContent();
        }
    } catch (IOException e) {
        log.warn("Could not locate response body stream", e);
        // normal for 401, 403 and 404 responses, for example...
    }

    if (is == null) {
        // Fall back to zero length response.
        is = new NullInputStream(0);
    }

    final Header header = response.getFirstHeader("Content-Encoding");
    if (header != null) {
        final String encoding = StringUtils.trimToEmpty(header.getValue());

        if (StringUtils.equalsIgnoreCase(encoding, "gzip")
                || StringUtils.equalsIgnoreCase(encoding, "x-gzip")) {
            log.debug("Found GZIP stream");
            is = new GZIPInputStream(is);
        } else if (StringUtils.equalsIgnoreCase(encoding, "deflate")) {
            log.debug("Found deflate stream");
            final Inflater inflater = new Inflater(true);
            is = new InflaterInputStream(is, inflater);
        }
    }
    return contentConverter.convert(request, response, is);
}

From source file:edu.umn.se.trap.rule.grantrule.DodNoForeignRule.java

/**
 * @param expenses/*from  w  ww  . java  2s.  c o  m*/
 * @throws TrapException
 */
protected void checkExpenseGrants(Expense expense, List<Expense> expenses) throws TrapException {
    Location location = expense.getLocation();

    /*
     * If a transportation or other expense has the same date as any other
     * type of expense, then it must have the same location.
     */
    if (location == null && (expense.getType().equals(ExpenseType.TRANSPORTATION)
            || expense.getType().equals(ExpenseType.OTHER))) {
        for (Expense ex : expenses) {
            if (!(ex.getType().equals(ExpenseType.TRANSPORTATION) || ex.getType().equals(ExpenseType.OTHER))) {
                if (expense.getDate().equals(ex.getDate())) {
                    location = ex.getLocation();
                }
            }
        }
    }

    if (location != null) {
        if (!StringUtils.equalsIgnoreCase(location.getCountry(), "USA")
                && !StringUtils.equalsIgnoreCase(location.getCountry(), "United States")) {
            GrantSet grantSet = expense.getEligibleGrants();

            if (grantSet == null) {
                throw new TrapException("Invalid TrapForm object: grantSet was null.");
            }

            Set<FormGrant> grants = grantSet.getGrants();

            if (grants == null) {
                throw new TrapException("Invalid TrapForm object: grants was null.");
            }

            Iterator<FormGrant> grantIter = grants.iterator();

            while (grantIter.hasNext()) {
                FormGrant grant = grantIter.next();

                if (StringUtils.equalsIgnoreCase(grant.getFundingOrganization(), "DOD")) {
                    // Remove the grant if it is a DOD grant trying to cover
                    // a
                    // foreign expense
                    grantSet.removeGrant(grant.getAccountName());
                }
            }

        }
    }

}

From source file:com.romeikat.datamessie.core.base.util.StringUtil.java

public boolean containsIgnoreCase(final Collection<String> existingStrings, final String candidateString) {
    for (final String existingString : existingStrings) {
        if (StringUtils.equalsIgnoreCase(existingString, candidateString)) {
            return true;
        }/*  w  ww  .j  a  v a 2s . c o  m*/
    }

    return false;
}

From source file:edu.umn.se.trap.db.orm.DatabaseAccessor.java

public User getUser(String userName) throws TrapException {
    try {/*from www . j  a  v a 2s.  c  o m*/
        List<String> userInfo = userDB.getUserInfo(userName);
        String fullName = userInfo.get(1);
        String email = userInfo.get(2);
        String employeeId = userInfo.get(3);
        String citizenship = userInfo.get(4);
        String visaStatus = userInfo.get(5);
        boolean paidByUniversity = StringUtils.equalsIgnoreCase(userInfo.get(6), "yes");
        return new User(userName, fullName, email, employeeId, citizenship, visaStatus, paidByUniversity);
    } catch (KeyNotFoundException e) {
        throw new TrapException("cannot find user info");
    }

}

From source file:com.inkubator.hrm.web.search.ApprovalDefinitionSearchParameter.java

public String getApproverType() {
    if (StringUtils.equalsIgnoreCase(getKeyParam(), "approverType")) {
        approverType = getParameter();/*from w ww  .j ava 2  s.c om*/
    } else {
        approverType = null;
    }
    return approverType;
}

From source file:com.mgmtp.jfunk.web.util.HtmlValidatorUtil.java

/**
 * Validates an HTML file against the W3C markup validation service.
 * //from  w w w.  j  a va 2s . c  om
 * @param validationResultDir
 *            target directory for validation result file
 * @param props
 *            properties must include the keys {@link WebConstants#W3C_MARKUP_VALIDATION_URL}
 *            and {@link WebConstants#W3C_MARKUP_VALIDATION_LEVEL}
 * @param file
 *            HTML file which will be validated
 */
public static void validateHtml(final File validationResultDir, final Configuration props, final File file)
        throws IOException {
    Preconditions.checkArgument(StringUtils.isNotBlank(props.get(WebConstants.W3C_MARKUP_VALIDATION_URL)));
    InputStream is = null;
    BufferedReader br = null;
    InputStream fis = null;
    try {
        // Post HTML file to markup validation service as multipart/form-data
        URL url = new URL(props.get(WebConstants.W3C_MARKUP_VALIDATION_URL));
        URLConnection uc = url.openConnection();
        MultipartPostRequest request = new MultipartPostRequest(uc);
        fis = new FileInputStream(file);
        /*
         * See http://validator.w3.org/docs/api.html#requestformat for a description of all
         * parameters
         */
        request.setParameter("uploaded_file", file.getPath(), fis);
        is = request.post();

        // Summary of validation is available in the HTTP headers
        String status = uc.getHeaderField(STATUS);
        int errors = Integer.parseInt(uc.getHeaderField(ERRORS));
        LOG.info("Page " + file.getName() + ": Number of HTML validation errors=" + errors);
        int warnings = Integer.parseInt(uc.getHeaderField(WARNINGS));
        LOG.info("Page " + file.getName() + ": Number of HTML validation warnings=" + warnings);

        // Check if result file has to be written
        String level = props.get(WebConstants.W3C_MARKUP_VALIDATION_LEVEL, "ERROR");
        boolean validate = false;
        if (StringUtils.equalsIgnoreCase(level, "WARNING") && (warnings > 0 || errors > 0)) {
            validate = true;
        } else if (StringUtils.equalsIgnoreCase(level, "ERROR") && errors > 0) {
            validate = true;
        } else if (StringUtils.equalsIgnoreCase("Invalid", status)) {
            validate = true;
        }

        if (validate) {
            br = new BufferedReader(new InputStreamReader(is));
            String line = null;
            StringBuffer sb = new StringBuffer();
            while ((line = br.readLine()) != null) {
                sb.append(line);
                sb.append('\n');
            }
            PrintWriter writer = null;
            String fileName = file.getName().substring(0, file.getName().length() - 5)
                    + "_validation_result.html";
            FileUtils.forceMkdir(validationResultDir);
            File validationResultFile = new File(validationResultDir, fileName);
            try {
                writer = new PrintWriter(validationResultFile, "UTF-8");
                writer.write(sb.toString());
                LOG.info("Validation result saved in file " + validationResultFile.getName());
            } catch (IOException ex) {
                LOG.error("Could not write HTML file " + validationResultFile.getName() + "to directory", ex);
            } finally {
                IOUtils.closeQuietly(writer);
            }
        }
    } finally {
        IOUtils.closeQuietly(br);
        IOUtils.closeQuietly(fis);
    }
}

From source file:com.xpn.xwiki.user.impl.xwiki.AbstractXWikiAuthService.java

/**
 * @param username the username to check for superadmin access. Examples: "xwiki:XWiki.superadmin",
 *            "XWiki.superAdmin", "superadmin", etc
 * @return true if the username is that of the superadmin (whatever the case) or false otherwise
 *///from w  ww.ja  va  2  s .c  om
protected boolean isSuperAdmin(String username) {
    // FIXME: this method should probably use a XWikiRightService#isSuperadmin(String) method, see
    // XWikiRightServiceImpl#isSuperadmin(String)

    // Note 1: we use the default document reference resolver here but it doesn't matter since we only care about
    // the resolved page name.
    // Note 2: we use a resolver since the passed username could contain the wiki and/or space too and we want
    // to retrieve only the page name
    DocumentReference documentReference = Utils.getComponent(DocumentReferenceResolver.class).resolve(username);
    return StringUtils.equalsIgnoreCase(documentReference.getName(), XWikiRightService.SUPERADMIN_USER);
}