Example usage for org.springframework.util StringUtils hasLength

List of usage examples for org.springframework.util StringUtils hasLength

Introduction

In this page you can find the example usage for org.springframework.util StringUtils hasLength.

Prototype

public static boolean hasLength(@Nullable String str) 

Source Link

Document

Check that the given String is neither null nor of length 0.

Usage

From source file:com.inspiresoftware.lib.dto.geda.config.AnnotationDrivenGeDABeanDefinitionParser.java

protected void setupListenerProperty(final MutablePropertyValues valuesArgs, final String property,
        final String listenerName) {
    if (StringUtils.hasLength(listenerName)) {
        valuesArgs.addPropertyValue(property, new RuntimeBeanReference(listenerName));
    }/*from   w  ww .ja  va  2 s .co m*/

}

From source file:org.mitre.provenance.openid.OpenId4JavaProxyConsumer.java

public OpenIDAuthenticationToken endConsumption(HttpServletRequest request) throws OpenIDConsumerException {
    // extract the parameters from the authentication response
    // (which comes in as a HTTP request from the OpenID provider)
    ParameterList openidResp = new ParameterList(request.getParameterMap());

    // retrieve the previously stored discovery information
    DiscoveryInformation discovered = (DiscoveryInformation) request.getSession()
            .getAttribute(DISCOVERY_INFO_KEY);

    if (discovered == null) {
        throw new OpenIDConsumerException(
                "DiscoveryInformation is not available. Possible causes are lost session or replay attack");
    }/*from  w  w w.  j a v a2s .c  o m*/

    List<OpenIDAttribute> attributesToFetch = (List<OpenIDAttribute>) request.getSession()
            .getAttribute(ATTRIBUTE_LIST_KEY);

    request.getSession().removeAttribute(DISCOVERY_INFO_KEY);
    request.getSession().removeAttribute(ATTRIBUTE_LIST_KEY);

    // extract the receiving URL from the HTTP request
    StringBuffer receivingURL = request.getRequestURL();
    String queryString = request.getQueryString();

    if (StringUtils.hasLength(queryString)) {
        receivingURL.append("?").append(request.getQueryString());
    }

    // verify the response
    VerificationResult verification;

    try {
        verification = consumerManager.verify(receivingURL.toString(), openidResp, discovered);
    } catch (MessageException e) {
        throw new OpenIDConsumerException("Error verifying openid response", e);
    } catch (DiscoveryException e) {
        throw new OpenIDConsumerException("Error verifying openid response", e);
    } catch (AssociationException e) {
        throw new OpenIDConsumerException("Error verifying openid response", e);
    }

    // examine the verification result and extract the verified identifier
    Identifier verified = verification.getVerifiedId();

    if (verified == null) {
        Identifier id = discovered.getClaimedIdentifier();
        return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.FAILURE,
                id == null ? "Unknown" : id.getIdentifier(),
                "Verification status message: [" + verification.getStatusMsg() + "]",
                Collections.<OpenIDAttribute>emptyList());
    }

    List<OpenIDAttribute> attributes = fetchAxAttributes(verification.getAuthResponse(), attributesToFetch);

    return new OpenIDAuthenticationToken(OpenIDAuthenticationStatus.SUCCESS, verified.getIdentifier(),
            "some message", attributes);
}

From source file:com.googlecode.ehcache.annotations.config.AnnotationDrivenEhCacheBeanDefinitionParser.java

/**
 * Setup the default cache interceptor //from   w ww .  j  av a 2 s  .com
 * 
 * @return A reference to the default cache interceptor.
 */
protected RuntimeBeanReference setupDefaultCacheableInterceptor(Element element, ParserContext parserContext,
        Object elementSource) {
    //If the default cache resolver factory was specified simply return a bean reference for that
    final String defaultCacheableInterceptor = element.getAttribute(XSD_ATTR__DEFAULT_CACHEABLE_INTECEPTOR);
    if (StringUtils.hasLength(defaultCacheableInterceptor)) {
        return new RuntimeBeanReference(defaultCacheableInterceptor);
    }

    //Use no reference
    return null;
}

From source file:org.openmrs.web.controller.visit.VisitFormController.java

/**
 * Processes requests to end a visit/*from   ww w . j av  a2 s.  c  o  m*/
 * @param visit the visit object to updated
 * @param stopDate which contains the stopDate or null for current time
 * @param request the {@link WebRequest} object
 * @return the url to forward/redirect to
 */
@RequestMapping(method = RequestMethod.POST, value = "/admin/visits/endVisit")
public String endVisit(@ModelAttribute(value = "visit") Visit visit,
        @RequestParam(value = "stopDate", required = false) String stopDate, HttpServletRequest request) {

    if (!StringUtils.hasLength(stopDate)) {
        Context.getVisitService().endVisit(visit, null);
    } else {
        try {
            Context.getVisitService().endVisit(visit, Context.getDateTimeFormat().parse(stopDate));
            request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "Visit.saved");
            return "redirect:" + "/patientDashboard.form?patientId=" + visit.getPatient().getPatientId();
        } catch (ParseException pe) {
            request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "error.date");
        } catch (APIException e) {
            request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, e.getMessage());
        }
    }

    return VISIT_FORM;
}

From source file:org.springmodules.validation.bean.conf.loader.xml.DefaultXmlBeanValidationConfigurationLoader.java

/**
 * Loads the validation configuration from the given document that was created from the given resource.
 *
 * @see AbstractXmlBeanValidationConfigurationLoader#loadConfigurations(org.w3c.dom.Document, String)
 */// w  ww  .java  2 s .c om
protected Map loadConfigurations(Document document, String resourceName) {
    Map configurations = new HashMap();
    Element validationDefinition = document.getDocumentElement();
    String packageName = validationDefinition.getAttribute(PACKAGE_ATTR);
    NodeList nodes = validationDefinition.getElementsByTagNameNS(DEFAULT_NAMESPACE_URL, CLASS_TAG);
    for (int i = 0; i < nodes.getLength(); i++) {
        Element classDefinition = (Element) nodes.item(i);
        String className = classDefinition.getAttribute(NAME_ATTR);
        className = (StringUtils.hasLength(packageName)) ? packageName + "." + className : className;
        Class clazz;
        try {
            clazz = ClassUtils.forName(className);
        } catch (ClassNotFoundException cnfe) {
            logger.error("Could not load class '" + className + "' as defined in '" + resourceName + "'", cnfe);
            continue;
        }
        configurations.put(clazz, handleClassDefinition(clazz, classDefinition));
    }
    return configurations;
}

From source file:org.springmodules.validation.valang.predicates.GenericTestPredicate.java

/**
 * <p>The evaluate method takes the result of both functions and tests with the operator.
 *
 * @param target the target bean/* w w  w.  j  a va2 s.  c  o m*/
 * @return the result of the test
 */
public boolean evaluate(Object target) {
    Object leftValue = getLeftFunction().getResult(target);
    Object rightValue = null;
    boolean dates = false;
    boolean numbers = false;

    if (getRightFunction() != null) {
        rightValue = getRightFunction().getResult(target);
    }

    if (leftValue instanceof Number) {
        leftValue = new BigDecimal(leftValue.toString());
    }
    if (rightValue instanceof Number) {
        rightValue = new BigDecimal(rightValue.toString());
    }

    dates = leftValue instanceof Date && rightValue instanceof Date;
    numbers = leftValue instanceof BigDecimal && rightValue instanceof BigDecimal;

    if (getOperator() instanceof Operator.NullOperator) {
        return leftValue == null;
    } else if (getOperator() instanceof Operator.NotNullOperator) {
        return leftValue != null;
    } else if (getOperator() instanceof Operator.EqualsOperator) {
        if (leftValue instanceof BigDecimal && rightValue instanceof BigDecimal) {
            return ((BigDecimal) leftValue).compareTo((BigDecimal) rightValue) == 0;
        } else if (dates) {
            return ((Date) leftValue).getTime() == ((Date) rightValue).getTime();
        } else {
            return leftValue.equals(rightValue);
        }
    } else if (getOperator() instanceof Operator.NotEqualsOperator) {
        if (leftValue instanceof BigDecimal && rightValue instanceof BigDecimal) {
            return ((BigDecimal) leftValue).compareTo((BigDecimal) rightValue) != 0;
        } else if (dates) {
            return ((Date) leftValue).getTime() != ((Date) rightValue).getTime();
        } else {
            return !leftValue.equals(rightValue);
        }
    } else if (getOperator() instanceof Operator.LessThanOperator) {
        if (dates) {
            return ((Date) leftValue).getTime() < ((Date) rightValue).getTime();
        } else if (numbers) {
            return ((BigDecimal) leftValue).compareTo((BigDecimal) rightValue) < 0;
        } else {
            throw new ValangException("< operator only supports two date or two number values!", getLine(),
                    getColumn());
        }
    } else if (getOperator() instanceof Operator.LessThanOrEqualOperator) {
        if (dates) {
            return ((Date) leftValue).getTime() <= ((Date) rightValue).getTime();
        } else if (numbers) {
            return ((BigDecimal) leftValue).compareTo((BigDecimal) rightValue) <= 0;
        } else {
            throw new ValangException("<= operator only supports two date or two number values!", getLine(),
                    getColumn());
        }
    } else if (getOperator() instanceof Operator.MoreThanOperator) {
        if (dates) {
            return ((Date) leftValue).getTime() > ((Date) rightValue).getTime();
        } else if (numbers) {
            return ((BigDecimal) leftValue).compareTo((BigDecimal) rightValue) > 0;
        } else {
            throw new ValangException("> operator only supports two date or two number values!", getLine(),
                    getColumn());
        }
    } else if (getOperator() instanceof Operator.MoreThanOrEqualOperator) {
        if (dates) {
            return ((Date) leftValue).getTime() >= ((Date) rightValue).getTime();
        } else if (numbers) {
            return ((BigDecimal) leftValue).compareTo((BigDecimal) rightValue) >= 0;
        } else {
            throw new IllegalArgumentException(">= operator only supports two date or two number values!");
        }
    } else if (getOperator() instanceof Operator.InOperator) {
        Collection predicates = new ArrayList();
        for (Iterator iter = getIterator(rightValue); iter.hasNext();) {
            Object o = iter.next();
            if (o instanceof Function) {
                predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR,
                        (Function) o, getLine(), getColumn()));
            } else {
                predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR,
                        new LiteralFunction(o), getLine(), getColumn()));
            }
        }
        if (predicates.isEmpty()) {
            throw new IllegalStateException("IN expression contains no elements!");
        } else if (predicates.size() == 1) {
            predicates.add(FalsePredicate.getInstance());
        }
        return AnyPredicate.getInstance(predicates).evaluate(target);
    } else if (getOperator() instanceof Operator.NotInOperator) {
        Collection predicates = new ArrayList();
        for (Iterator iter = getIterator(rightValue); iter.hasNext();) {
            Object o = iter.next();
            if (o instanceof Function) {
                predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR,
                        (Function) o, getLine(), getColumn()));
            } else {
                predicates.add(getPredicate(new LiteralFunction(leftValue), OperatorConstants.EQUALS_OPERATOR,
                        new LiteralFunction(o), getLine(), getColumn()));
            }
        }
        if (predicates.isEmpty()) {
            throw new IllegalStateException("NOT IN expression contains no elements!");
        } else if (predicates.size() == 1) {
            predicates.add(FalsePredicate.getInstance());
        }
        return !AnyPredicate.getInstance(predicates).evaluate(target);
    } else if (getOperator() instanceof Operator.BetweenOperator) {
        Object[] array = getArray(rightValue);
        Predicate predicate1 = getPredicate(new LiteralFunction(leftValue),
                OperatorConstants.MORE_THAN_OR_EQUAL_OPERATOR, (Function) array[0], getLine(), getColumn());
        Predicate predicate2 = getPredicate(new LiteralFunction(leftValue),
                OperatorConstants.LESS_THAN_OR_EQUAL_OPERATOR, (Function) array[1], getLine(), getColumn());
        return AndPredicate.getInstance(predicate1, predicate2).evaluate(target);
    } else if (getOperator() instanceof Operator.NotBetweenOperator) {
        Object[] array = getArray(rightValue);
        Predicate predicate1 = getPredicate(new LiteralFunction(leftValue),
                OperatorConstants.MORE_THAN_OR_EQUAL_OPERATOR, (Function) array[0], getLine(), getColumn());
        Predicate predicate2 = getPredicate(new LiteralFunction(leftValue),
                OperatorConstants.LESS_THAN_OR_EQUAL_OPERATOR, (Function) array[1], getLine(), getColumn());
        return !AndPredicate.getInstance(predicate1, predicate2).evaluate(target);
    } else if (getOperator() instanceof Operator.HasLengthOperator) {
        return StringUtils.hasLength(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.HasNoLengthOperator) {
        return !StringUtils.hasLength(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.HasTextOperator) {
        return StringUtils.hasText(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.HasNoTextOperator) {
        return !StringUtils.hasText(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsBlankOperator) {
        return isBlank(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsNotBlankOperator) {
        return !isBlank(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsWordOperator) {
        return isWord(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsNotWordOperator) {
        return !isWord(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsLowerCaseOperator) {
        return isLowerCase(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsNotLowerCaseOperator) {
        return !isLowerCase(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsUpperCaseOperator) {
        return isUpperCase(leftValue != null ? leftValue.toString() : null);
    } else if (getOperator() instanceof Operator.IsNotUpperCaseOperator) {
        return !isUpperCase(leftValue != null ? leftValue.toString() : null);
    }

    throw new IllegalStateException(
            "Operator class [" + getOperator().getClass().getName() + "] not supported!");
}

From source file:org.mifos.androidclient.main.CustomerDetailsActivity.java

private void runCustomerDetailsTask() {
    if (mCustomer == null || !StringUtils.hasLength(mCustomer.getGlobalCustNum())) {
        mUIUtils.displayLongMessage(getString(R.string.toast_customer_id_not_available));
        return;/*  w w  w. ja v  a  2  s  .  c o  m*/
    }
    if (mCustomerDetailsTask == null || mCustomerDetailsTask.getStatus() != AsyncTask.Status.RUNNING) {
        mCustomerDetailsTask = new CustomerDetailsTask(this, getString(R.string.dialog_getting_customer_data),
                getString(R.string.dialog_loading_message));
        mCustomerDetailsTask.execute(mCustomer);
    }
}

From source file:com.starit.diamond.server.service.ConfigService.java

private void checkParameter(String dataId, String group) {
    if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim()))
        throw new ConfigServiceException("dataId");

    if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim()))
        throw new ConfigServiceException("group");
}

From source file:org.springmodules.validation.bean.conf.loader.xml.handler.AbstractPropertyValidationElementHandler.java

/**
 * Extracts the validation rule error message from the given element. Expects a "message" attribute to indicate the
 * error message. If no such attribute exisits, returns {@link #extractErrorCode(org.w3c.dom.Element)} instead.
 *
 * @param element The element that represents the validation rule.
 * @return The validation rule error message.
 *//*  ww w . j  a  va2s.  c o  m*/
protected String extractMessage(Element element) {
    String message = element.getAttribute(AbstractPropertyValidationElementHandler.MESSAGE_ATTR);
    return (StringUtils.hasLength(message)) ? message : null;
}

From source file:com.taobao.diamond.server.controller.BaseStoneController.java

@RequestMapping(params = "method=deleteConfig", method = RequestMethod.POST)
public String deleteConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("content") String content) {
    response.setCharacterEncoding("GBK");

    boolean checkSuccess = true;
    String errorMessage = "";
    if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;//from   ww  w . j a  va 2 s.c  o m
        errorMessage = "DataId";
    }
    if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!StringUtils.hasLength(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        try {
            response.sendError(INVALID_PARAM, errorMessage);
        } catch (IOException e) {
            log.error("response", e);
        }
        return "536";
    }

    this.removeConfigInfo(dataId, group, content);

    return "200";
}