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

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

Introduction

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

Prototype

public static boolean isNumeric(final CharSequence cs) 

Source Link

Document

Checks if the CharSequence contains only Unicode digits.

Usage

From source file:org.apache.syncope.client.console.panels.AbstractSearchPanel.java

public String buildFIQL() {
    LOG.debug("Generating FIQL from List<SearchClause>: {}", searchClauses);

    if (searchClauses.isEmpty() || searchClauses.get(0).getType() == null) {
        return StringUtils.EMPTY;
    }//from ww w  .  j  a  v  a 2  s .  c  om

    AbstractFiqlSearchConditionBuilder builder = getSearchConditionBuilder();

    CompleteCondition prevCondition;
    CompleteCondition condition = null;
    for (int i = 0; i < searchClauses.size(); i++) {
        prevCondition = condition;

        switch (searchClauses.get(i).getType()) {
        case ENTITLEMENT:
            condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
                    ? ((GroupFiqlSearchConditionBuilder) builder)
                            .hasEntitlements(searchClauses.get(i).getProperty())
                    : ((GroupFiqlSearchConditionBuilder) builder)
                            .hasNotEntitlements(searchClauses.get(i).getProperty());
            break;

        case MEMBERSHIP:
            Long groupId = NumberUtils.toLong(searchClauses.get(i).getProperty().split(" ")[0]);
            condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
                    ? ((UserFiqlSearchConditionBuilder) builder).inGroups(groupId)
                    : ((UserFiqlSearchConditionBuilder) builder).notInGroups(groupId);
            break;

        case RESOURCE:
            condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
                    ? builder.hasResources(searchClauses.get(i).getProperty())
                    : builder.hasNotResources(searchClauses.get(i).getProperty());
            break;

        case ATTRIBUTE:
            SyncopeProperty property = builder.is(searchClauses.get(i).getProperty());
            switch (searchClauses.get(i).getComparator()) {
            case IS_NULL:
                condition = builder.isNull(searchClauses.get(i).getProperty());
                break;

            case IS_NOT_NULL:
                condition = builder.isNotNull(searchClauses.get(i).getProperty());
                break;

            case LESS_THAN:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.lessThan(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalBefore(searchClauses.get(i).getValue());
                break;

            case LESS_OR_EQUALS:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.lessOrEqualTo(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalNotAfter(searchClauses.get(i).getValue());
                break;

            case GREATER_THAN:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.greaterThan(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalAfter(searchClauses.get(i).getValue());
                break;

            case GREATER_OR_EQUALS:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.greaterOrEqualTo(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalNotBefore(searchClauses.get(i).getValue());
                break;

            case NOT_EQUALS:
                condition = property.notEqualTo(searchClauses.get(i).getValue());
                break;

            case EQUALS:
            default:
                condition = property.equalTo(searchClauses.get(i).getValue());
                break;
            }
        default:
            break;
        }

        if (i > 0) {
            if (searchClauses.get(i).getOperator() == SearchClause.Operator.AND) {
                condition = builder.and(prevCondition, condition);
            }
            if (searchClauses.get(i).getOperator() == SearchClause.Operator.OR) {
                condition = builder.or(prevCondition, condition);
            }
        }
    }

    String fiql = condition == null ? StringUtils.EMPTY : condition.query();
    LOG.debug("Generated FIQL: {}", fiql);
    return fiql;
}

From source file:org.apache.syncope.console.pages.panels.AbstractSearchPanel.java

public String buildFIQL() {
    LOG.debug("Generating FIQL from List<SearchClause>: {}", searchClauses);

    if (searchClauses.isEmpty() || searchClauses.get(0).getType() == null) {
        return StringUtils.EMPTY;
    }//from ww  w  . j a  va 2  s .  c o  m

    SyncopeFiqlSearchConditionBuilder builder = getSearchConditionBuilder();

    CompleteCondition prevCondition;
    CompleteCondition condition = null;
    for (int i = 0; i < searchClauses.size(); i++) {
        prevCondition = condition;

        switch (searchClauses.get(i).getType()) {
        case ENTITLEMENT:
            condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
                    ? ((RoleFiqlSearchConditionBuilder) builder)
                            .hasEntitlements(searchClauses.get(i).getProperty())
                    : ((RoleFiqlSearchConditionBuilder) builder)
                            .hasNotEntitlements(searchClauses.get(i).getProperty());
            break;

        case MEMBERSHIP:
            Long roleId = NumberUtils.toLong(searchClauses.get(i).getProperty().split(" ")[0]);
            condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
                    ? ((UserFiqlSearchConditionBuilder) builder).hasRoles(roleId)
                    : ((UserFiqlSearchConditionBuilder) builder).hasNotRoles(roleId);
            break;

        case RESOURCE:
            condition = searchClauses.get(i).getComparator() == SearchClause.Comparator.EQUALS
                    ? builder.hasResources(searchClauses.get(i).getProperty())
                    : builder.hasNotResources(searchClauses.get(i).getProperty());
            break;

        case ATTRIBUTE:
            SyncopeProperty property = builder.is(searchClauses.get(i).getProperty());
            switch (searchClauses.get(i).getComparator()) {
            case IS_NULL:
                condition = builder.isNull(searchClauses.get(i).getProperty());
                break;

            case IS_NOT_NULL:
                condition = builder.isNotNull(searchClauses.get(i).getProperty());
                break;

            case LESS_THAN:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.lessThan(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalBefore(searchClauses.get(i).getValue());
                break;

            case LESS_OR_EQUALS:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.lessOrEqualTo(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalNotAfter(searchClauses.get(i).getValue());
                break;

            case GREATER_THAN:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.greaterThan(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalAfter(searchClauses.get(i).getValue());
                break;

            case GREATER_OR_EQUALS:
                condition = StringUtils.isNumeric(searchClauses.get(i).getProperty())
                        ? property.greaterOrEqualTo(NumberUtils.toDouble(searchClauses.get(i).getValue()))
                        : property.lexicalNotBefore(searchClauses.get(i).getValue());
                break;

            case NOT_EQUALS:
                condition = property.notEqualTo(searchClauses.get(i).getValue());
                break;

            case EQUALS:
            default:
                condition = property.equalTo(searchClauses.get(i).getValue());
                break;
            }
        default:
            break;
        }

        if (i > 0) {
            if (searchClauses.get(i).getOperator() == SearchClause.Operator.AND) {
                condition = builder.and(prevCondition, condition);
            }
            if (searchClauses.get(i).getOperator() == SearchClause.Operator.OR) {
                condition = builder.or(prevCondition, condition);
            }
        }
    }

    String fiql = condition == null ? StringUtils.EMPTY : condition.query();
    LOG.debug("Generated FIQL: {}", fiql);
    return fiql;
}

From source file:org.apache.syncope.ide.netbeans.view.ServerDetailsView.java

private List<String> validate(final JTextField schemeTxt, final JTextField hostTxt, final JTextField portTxt,
        final JTextField userNameTxt) {

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

    if (StringUtils.isBlank(schemeTxt.getText()) || (!StringUtils.equals(schemeTxt.getText(), "http")
            && !StringUtils.equals(schemeTxt.getText(), "https"))) {
        res.add("scheme");
    }/*from   w  w  w. j a v a 2  s . c o m*/
    if (StringUtils.isBlank(hostTxt.getText())) {
        res.add("host");
    }
    if (StringUtils.isBlank(portTxt.getText()) || !StringUtils.isNumeric(portTxt.getText())) {
        res.add("port");
    }
    if (StringUtils.isBlank(userNameTxt.getText())) {
        res.add("username");
    }
    return res;
}

From source file:org.apache.usergrid.security.PasswordPolicyImpl.java

public Collection<String> policyCheck(String password, int minLength, int minUppercase, int minDigits,
        int minSpecialChars) {

    List<String> violations = new ArrayList<>(3);

    // check length
    if (password == null || password.length() < minLength) {
        violations.add(PasswordPolicy.ERROR_LENGTH_POLICY + ": must be at least " + minLength + " characters");
    }//  w  w  w . j  a v a2 s  . c o m

    // count upper case
    if (minUppercase > 0) {
        int upperCaseCount = 0;
        for (char c : password.toCharArray()) {
            if (StringUtils.isAllUpperCase(String.valueOf(c))) {
                upperCaseCount++;
            }
        }
        if (upperCaseCount < minUppercase) {
            violations.add(PasswordPolicy.ERROR_UPPERCASE_POLICY + ": requires " + minUppercase
                    + " uppercase characters");
        }
    }

    // count digits case
    if (minDigits > 0) {
        int digitCount = 0;
        for (char c : password.toCharArray()) {
            if (StringUtils.isNumeric(String.valueOf(c))) {
                digitCount++;
            }
        }
        if (digitCount < minDigits) {
            violations.add(PasswordPolicy.ERROR_DIGITS_POLICY + ": requires " + minDigits + " digits");
        }
    }

    // count special characters
    if (minSpecialChars > 0) {
        int specialCharCount = 0;
        for (char c : password.toCharArray()) {
            if (passwordPolicyFig.getAllowedSpecialChars().contains(String.valueOf(c))) {
                specialCharCount++;
            }
        }
        if (specialCharCount < minSpecialChars) {
            violations.add(PasswordPolicy.ERROR_SPECIAL_CHARS_POLICY + ": requires " + minSpecialChars
                    + " special characters");
        }
    }

    return violations;
}

From source file:org.apereo.portal.portlet.rendering.PortletRendererImpl.java

/**
 * Construct a {@link PortletRenderResult} from information in the {@link HttpServletRequest}.
 * The second argument is how long the render action took.
 * //  www .ja va 2  s.com
 * @param httpServletRequest
 * @param renderTime
 * @return an appropriate {@link PortletRenderResult}, never null
 */
protected PortletRenderResult constructPortletRenderResult(HttpServletRequest httpServletRequest,
        long renderTime) {
    final String title = (String) httpServletRequest.getAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_TITLE);
    final String newItemCountString = (String) httpServletRequest
            .getAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_NEW_ITEM_COUNT);
    final int newItemCount;
    if (newItemCountString != null && StringUtils.isNumeric(newItemCountString)) {
        newItemCount = Integer.parseInt(newItemCountString);
    } else {
        newItemCount = 0;
    }
    final String link = (String) httpServletRequest.getAttribute(IPortletRenderer.ATTRIBUTE__PORTLET_LINK);

    return new PortletRenderResult(title, link, newItemCount, renderTime);
}

From source file:org.bitstrings.maven.plugins.splasher.LoadAlphaNumImages.java

@Override
public Map<String, ?> resourceMap(DrawingContext context) throws MojoExecutionException {
    for (String range : StringUtils.split(ranges, ',')) {
        try {/*from   www  . ja  v  a 2 s  .c o  m*/
            String[] members = StringUtils.split(range, '-');

            if (ArrayUtils.isEmpty(members) || members.length > 2) {
                throw new MojoExecutionException("Invalid range [" + range + "].");
            }

            if (StringUtils.isNumeric(members[0])) {
                if (members.length == 1) {
                    final int from = Integer.parseInt(members[0]);

                    return numericRangeResources(from, from, context);
                } else {
                    return numericRangeResources(Integer.parseInt(members[0]), Integer.parseInt(members[1]),
                            context);
                }
            } else {
                if (members.length == 1) {
                    final char from = members[0].charAt(0);

                    return charRangeResources(from, from, context);
                } else {
                    return charRangeResources(members[0].charAt(0), members[1].charAt(0), context);
                }
            }
        } catch (NumberFormatException e) {
            throw new MojoExecutionException("Unable to parse range " + range + ".");
        }
    }

    return null;
}

From source file:org.blocks4j.commons.metrics3.MetricCounterBackup.java

public synchronized long get(String name) {
    String normalized = normalize(name);

    try {/*from  ww  w. ja  v a  2  s.co m*/
        File input = new File(base, normalized);
        if (!input.exists()) {
            return 0;
        }
        List<String> lines = FileUtils.readLines(input);
        if (lines.isEmpty()) {
            return 0;
        }
        String raw = lines.get(0);
        if (StringUtils.isBlank(raw) || !StringUtils.isNumeric(raw)) {
            return 0;
        }
        return Long.parseLong(raw);
    } catch (Exception e) {
        log.error("error while reading from file [" + base.getName() + System.getProperty("file.separator")
                + normalized + "]", e);
        return 0;
    }
}

From source file:org.cgiar.ccafs.ap.interceptor.ValidateActivityParameterInterceptor.java

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    LOG.debug("=> ValidateActivityParameterInterceptor");
    String actionName = ServletActionContext.getActionMapping().getName();
    // if user is not in section that list the activities.
    if (!actionName.equals("activities")) {
        Map<String, Object> parameters = invocation.getInvocationContext().getParameters();
        // Validate if project parameter exists in the URL.
        if (parameters.get(APConstants.ACTIVITY_REQUEST_ID) != null) {
            String activityParameter = ((String[]) parameters.get(APConstants.ACTIVITY_REQUEST_ID))[0];
            // Validate if the parameter is a number.
            if (StringUtils.isNumeric(activityParameter)) {
                int activityID = Integer.parseInt(activityParameter);
                // If activity doesn't exist.
                if (!activityManager.existActivity(activityID)) {
                    return BaseAction.NOT_FOUND;
                } else {
                    // If activity exists, continue!
                    return invocation.invoke();
                }/*from ww  w.  java  2 s .c  o  m*/
            } else {
                // If parameter is not a number.
                return BaseAction.NOT_FOUND;
            }
        } else {
            // if parameter does not exist.
            return BaseAction.NOT_FOUND;
        }
    } else {
        // So far, if user is in the activities list section, do nothing!
        return invocation.invoke();
    }
}

From source file:org.cgiar.ccafs.ap.interceptor.ValidateDeliverableParameterInterceptor.java

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    LOG.debug("=> ValidateDeliverableParameterInterceptor");
    // String actionName = ServletActionContext.getActionMapping().getName();

    Map<String, Object> parameters = invocation.getInvocationContext().getParameters();
    // Validate if deliverable parameter exists in the URL.
    if (parameters.get(APConstants.DELIVERABLE_REQUEST_ID) != null) {
        String deliverableParameter = ((String[]) parameters.get(APConstants.DELIVERABLE_REQUEST_ID))[0];
        // Validate if the parameter is a number.
        if (StringUtils.isNumeric(deliverableParameter)) {
            int deliverableID = Integer.parseInt(deliverableParameter);
            // If the deliverable doesn't exist.
            if (!deliverableManager.existDeliverable(deliverableID)) {
                return BaseAction.NOT_FOUND;
            } else {
                // If deliverable exists, continue!
                return invocation.invoke();
            }/*from w w  w .  ja  v  a 2  s  .  c o  m*/
        } else {
            // If parameter is not a number.
            return BaseAction.NOT_FOUND;
        }
    } else {
        // if parameter does not exist.
        return BaseAction.NOT_FOUND;
    }
}

From source file:org.cgiar.ccafs.ap.interceptor.ValidateHighlightParameterInterceptor.java

@Override
public String intercept(ActionInvocation invocation) throws Exception {
    LOG.debug("=> ValidateHighlightParameterInterceptor");
    // String actionName = ServletActionContext.getActionMapping().getName();

    Map<String, Object> parameters = invocation.getInvocationContext().getParameters();
    // Validate if deliverable parameter exists in the URL.
    if (parameters.get(APConstants.HIGHLIGHT_REQUEST_ID) != null) {
        String deliverableParameter = ((String[]) parameters.get(APConstants.HIGHLIGHT_REQUEST_ID))[0];
        // Validate if the parameter is a number.
        if (StringUtils.isNumeric(deliverableParameter)) {
            int deliverableID = Integer.parseInt(deliverableParameter);
            // If the deliverable doesn't exist.
            if (!highlightManager.existHighLight(deliverableID)) {
                return BaseAction.NOT_FOUND;
            } else {
                // If deliverable exists, continue!
                return invocation.invoke();
            }/*from   w  w w. j a  va2s  .  c  o  m*/
        } else {
            // If parameter is not a number.
            return BaseAction.NOT_FOUND;
        }
    } else {
        // if parameter does not exist.
        return BaseAction.NOT_FOUND;
    }
}