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

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

Introduction

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

Prototype

public static boolean startsWithIgnoreCase(final CharSequence str, final CharSequence prefix) 

Source Link

Document

Case insensitive check if a CharSequence starts with a specified prefix.

null s are handled without exceptions.

Usage

From source file:com.willwinder.universalgcodesender.uielements.panels.MachineStatusPanel.java

private void setStatusColorForState(String state) {
    if (backend.getSettings().isDisplayStateColor()) {
        java.awt.Color color = null; // default to a transparent background.
        if (state.equals(Localization.getString("mainWindow.status.alarm"))
                || StringUtils.startsWithIgnoreCase(state, "Alarm")) {
            color = Color.RED;//from   w  ww. ja va 2s  . com
        } else if (state.equals(Localization.getString("mainWindow.status.hold"))) {
            color = Color.YELLOW;
        } else if (state.equals(Localization.getString("mainWindow.status.queue"))) {
            color = Color.YELLOW;
        } else if (state.equals(Localization.getString("mainWindow.status.run"))) {
            color = Color.GREEN;
        } else {
            color = Color.WHITE;
        }

        this.activeStateLabel.setBackground(color);
        this.activeStateValueLabel.setBackground(color);
    } else {
        this.activeStateLabel.setBackground(null);
        this.activeStateValueLabel.setBackground(null);
    }
}

From source file:net.eledge.android.europeana.search.model.record.enums.RecordDetails.java

private static String cleanCombineResults(String[] array) {
    List<String> result = new ArrayList<>();
    if (array != null) {
        for (String s : array) {
            if (StringUtils.isNotBlank(s) && !StringUtils.startsWithIgnoreCase(s, "http://")
                    && !StringUtils.startsWithIgnoreCase(s, "https://")) {
                result.add(StringUtils.trim(s));
            }//from   www.  j a v a 2s .  c o m
        }
        return StringUtils.join(result, "; ");
    }
    return null;
}

From source file:com.glaf.base.modules.branch.springmvc.BranchUserController.java

@RequestMapping(params = "method=permission")
public ModelAndView permission(HttpServletRequest request, ModelMap modelMap) {
    RequestUtils.setRequestParameterToAttribute(request);

    List<SysRole> roleList = new ArrayList<SysRole>();
    List<SysRole> roles = sysRoleService.getSysRoleList();
    for (SysRole role : roles) {
        if (StringUtils.isNotEmpty(role.getCode())
                && (StringUtils.startsWithIgnoreCase(role.getCode(), SysConstants.BRANCH_PREFIX)
                        || StringUtils.equals(role.getIsUseBranch(), "Y"))) {
            roleList.add(role);//from   w w w .  jav  a 2s . c  o  m
        }
    }

    request.setAttribute("roleList", roleList);

    String op_view = request.getParameter("op_view");
    if (StringUtils.isEmpty(op_view)) {
        op_view = "user";
    }

    request.setAttribute("op_view", op_view);

    long parentId = 0;
    if (StringUtils.isNotEmpty(request.getParameter("parentId"))) {
        parentId = RequestUtils.getLong(request, "parentId");
    } else {
        SysUser user = com.glaf.base.utils.RequestUtil.getLoginUser(request);
        parentId = user.getDeptId();
    }

    List<Long> deptIds = new ArrayList<Long>();
    List<SysTree> treeList = new ArrayList<SysTree>();
    sysTreeService.loadSysTrees(treeList, parentId, 1);
    if (treeList != null && !treeList.isEmpty()) {
        for (SysTree tree : treeList) {
            if (tree.getDepartment() != null) {
                deptIds.add(tree.getDepartment().getId());
            }
        }
    }

    SysDepartment dept = sysDepartmentService.getSysDepartmentByNodeId(parentId);
    if (dept != null) {
        deptIds.add(dept.getId());
    }

    logger.debug("----deptIds:" + deptIds);

    SysUserQuery query = new SysUserQuery();
    query.deptIds(deptIds);
    List<SysUser> users = sysUserService.getSysUsersByQueryCriteria(0, 1000, query);
    if (users != null && !users.isEmpty()) {
        List<String> actorIds = new ArrayList<String>();
        for (SysUser user : users) {
            actorIds.add(user.getAccount());
        }
        UserRoleQuery userRoleQuery = new UserRoleQuery();
        userRoleQuery.setActorIds(actorIds);
        List<UserRole> userRoles = sysUserService.getRoleUserViews(userRoleQuery);
        if (userRoles != null && !userRoles.isEmpty()) {
            for (SysUser user : users) {
                for (UserRole userRole : userRoles) {
                    if (StringUtils.equals(user.getAccount(), userRole.getActorId())) {
                        user.getRoleCodes().add(userRole.getRoleCode());
                    }
                }
            }
        }
        request.setAttribute("users", users);
    }

    String x_query = request.getParameter("x_query");
    if (StringUtils.equals(x_query, "true")) {
        Map<String, Object> paramMap = RequestUtils.getParameterMap(request);
        String x_complex_query = JsonUtils.encode(paramMap);
        x_complex_query = RequestUtils.encodeString(x_complex_query);
        request.setAttribute("x_complex_query", x_complex_query);
    } else {
        request.setAttribute("x_complex_query", "");
    }

    String x_view = ViewProperties.getString("branch.user.permission");
    if (StringUtils.isNotEmpty(x_view)) {
        return new ModelAndView(x_view, modelMap);
    }

    String view = request.getParameter("view");
    if (StringUtils.isNotEmpty(view)) {
        return new ModelAndView(view, modelMap);
    }

    return new ModelAndView("/modules/branch/user/permission", modelMap);
}

From source file:com.github.erchu.beancp.commons.NameBasedMapConvention.java

private List<BindingSide> getMatchingPropertyByName(final BeanInfo sourceBeanInfo,
        final String atDestinationName, final MemberAccessType destinationMemberAccessType) {
    Optional<PropertyDescriptor> exactMatchResult = Arrays.stream(sourceBeanInfo.getPropertyDescriptors())
            .filter(i -> i.getName().equalsIgnoreCase(atDestinationName)).findFirst();

    if (exactMatchResult.isPresent()) {
        List<BindingSide> result = new LinkedList<>();
        result.add(new PropertyBindingSide(exactMatchResult.get()));

        return result;
    }//w w  w .j  a  va 2  s. c o m

    if (_flateningEnabled) {
        Optional<PropertyDescriptor> partiallyMatchResult = Arrays
                .stream(sourceBeanInfo.getPropertyDescriptors())
                .filter(i -> StringUtils.startsWithIgnoreCase(atDestinationName, i.getName()))
                .sorted((x, y) -> y.getName().length() - x.getName().length()).findFirst();

        if (partiallyMatchResult.isPresent()) {
            BindingSide firstBinding = new PropertyBindingSide(partiallyMatchResult.get());
            Class innerPropertyClass = firstBinding.getValueClass();

            return getInnerMatchingSourceMemberByName(innerPropertyClass, atDestinationName, firstBinding,
                    destinationMemberAccessType);
        } else {
            return null;
        }
    }

    return null;
}

From source file:com.jayway.restassured.internal.http.EncoderRegistry.java

private Closure tryToFindMatchingEncoder(String contentType) {
    final Closure closure;
    if (contentType == null) {
        closure = null;//  ww w  .  j a v  a2s. c  o  m
    } else if (StringUtils.startsWithIgnoreCase(contentType, "text/")
            || StringUtils.containsIgnoreCase(contentType, "+text")) {
        closure = new MethodClosure(this, "encodeText");
    } else {
        closure = null;
    }

    return closure;
}

From source file:com.github.erchu.beancp.commons.NameBasedMapConvention.java

private List<BindingSide> getMatchingFieldByName(final Class sourceClass, final String atDestinationName,
        final MemberAccessType destinationMemberAccessType) {
    Optional<Field> exactMatchResult = Arrays.stream(sourceClass.getFields())
            .filter(i -> i.getName().equalsIgnoreCase(atDestinationName)).findFirst();

    if (exactMatchResult.isPresent()) {
        List<BindingSide> result = new LinkedList<>();
        result.add(new FieldBindingSide(exactMatchResult.get()));

        return result;
    }/*from   w w  w.  j ava 2s  .  c  o m*/

    if (_flateningEnabled) {
        Optional<Field> partiallyMatchResult = Arrays.stream(sourceClass.getFields())
                .filter(i -> StringUtils.startsWithIgnoreCase(atDestinationName, i.getName()))
                .sorted((x, y) -> y.getName().length() - x.getName().length()).findFirst();

        if (partiallyMatchResult.isPresent()) {
            BindingSide firstBinding = new FieldBindingSide(partiallyMatchResult.get());
            Class innerPropertyClass = firstBinding.getValueClass();

            return getInnerMatchingSourceMemberByName(innerPropertyClass, atDestinationName, firstBinding,
                    destinationMemberAccessType);
        } else {
            return null;
        }
    }

    return null;
}

From source file:com.gargoylesoftware.htmlunit.html.HtmlScript.java

/**
 * Returns true if a script with the specified type and language attributes is actually JavaScript.
 * According to <a href="http://www.w3.org/TR/REC-html40/types.html#h-6.7">W3C recommendation</a>
 * are content types case insensitive.<b>
 * IE supports only a limited number of values for the type attribute. For testing you can
 * use http://www.robinlionheart.com/stds/html4/scripts.
 * @param typeAttribute the type attribute specified in the script tag
 * @param languageAttribute the language attribute specified in the script tag
 * @return true if the script is JavaScript
 *//* w ww  .ja  v  a 2  s  .c o  m*/
boolean isJavaScript(String typeAttribute, final String languageAttribute) {
    final BrowserVersion browserVersion = getPage().getWebClient().getBrowserVersion();

    if (browserVersion.hasFeature(HTMLSCRIPT_TRIM_TYPE)) {
        typeAttribute = typeAttribute.trim();
    }

    if (StringUtils.isNotEmpty(typeAttribute)) {
        if ("text/javascript".equalsIgnoreCase(typeAttribute)
                || "text/ecmascript".equalsIgnoreCase(typeAttribute)) {
            return true;
        }

        if ("application/javascript".equalsIgnoreCase(typeAttribute)
                || "application/ecmascript".equalsIgnoreCase(typeAttribute)
                || "application/x-javascript".equalsIgnoreCase(typeAttribute)) {
            return true;
        }
        return false;
    }

    if (StringUtils.isNotEmpty(languageAttribute)) {
        return StringUtils.startsWithIgnoreCase(languageAttribute, "javascript");
    }
    return true;
}

From source file:com.erudika.scoold.utils.ScooldUtils.java

public boolean canAccessSpace(Profile authUser, String targetSpaceId) {
    if (authUser == null) {
        return isDefaultSpacePublic();
    }//from   w w  w . j  a v a  2 s .  c o  m
    if (StringUtils.isBlank(targetSpaceId)) {
        // can user access the default space (blank)
        return isDefaultSpacePublic() || isMod(authUser) || !authUser.hasSpaces();
    }
    boolean isMemberOfSpace = false;
    for (String space : authUser.getSpaces()) {
        if (StringUtils.startsWithIgnoreCase(space, getSpaceId(targetSpaceId) + ":")) {
            isMemberOfSpace = true;
            break;
        }
    }
    return isMemberOfSpace;
}

From source file:com.norconex.collector.http.url.impl.GenericLinkExtractor.java

private boolean isValidNewURL(String newURL) {
    if (StringUtils.isBlank(newURL)) {
        return false;
    }/*  ww  w  .  j av a  2 s  .c o m*/
    if (StringUtils.startsWithIgnoreCase(newURL, "mailto:")) {
        return false;
    }
    if (StringUtils.startsWithIgnoreCase(newURL, "javascript:")) {
        return false;
    }
    return true;
}

From source file:com.sonicle.webtop.mail.MailAccount.java

public String getShortFolderName(String fullname) {
    String shortname = fullname;// ww w  . ja v a  2 s. c o  m
    if (StringUtils.startsWithIgnoreCase(fullname, folderPrefix)) {
        shortname = fullname.substring(folderPrefix.length());
    }
    return shortname;
}