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:fr.xebia.springframework.orm.jpa.vendor.XHibernateJpaVendorAdapter.java

@Override
public Map<String, Object> getJpaPropertyMap() {
    Map<String, Object> jpaPropertyMap = super.getJpaPropertyMap();
    if (StringUtils.hasLength(hbm2ddlAuto)) {
        jpaPropertyMap.put(Environment.HBM2DDL_AUTO, getHbm2ddlAuto());
    }/* w  w  w . j  av  a2 s  .  c o m*/
    return jpaPropertyMap;
}

From source file:sample.data.jpa.service.CityServiceImpl.java

@Override
public Page<City> findCities(CitySearchCriteria criteria, Pageable pageable) {

    Assert.notNull(criteria, "Criteria must not be null");
    String name = criteria.getName();

    if (!StringUtils.hasLength(name)) {
        //         return this.cityRepository.findAll();
    }/*from   w  w  w  .j a v a 2s . c om*/

    String country = "";
    int splitPos = name.lastIndexOf(",");

    if (splitPos >= 0) {
        country = name.substring(splitPos + 1);
        name = name.substring(0, splitPos);
    }

    return this.cityRepository.findByNameContainingAndCountryContainingAllIgnoringCase(name.trim(),
            country.trim(), pageable);
}

From source file:org.openmrs.module.feedback.web.StatusFormController.java

@Override
protected String formBackingObject(HttpServletRequest request) throws Exception {
    Object o = Context.getService(FeedbackService.class);
    FeedbackService service = (FeedbackService) o;
    String feedbackStatusId = request.getParameter("feedbackStatusId");
    String text = "Not Used";
    String status = request.getParameter("status");

    if (!StringUtils.hasLength(feedbackStatusId)
            || (service.getStatus(Integer.parseInt(feedbackStatusId)) == null)) { /* Just for the statistics */
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.status.deleted");
        text = feedbackStatusId;/*from  ww w.  j a  v a2s . c  om*/
    }

    /* Delete the data incase delete has been selected by the user */
    else if ((feedbackStatusId != null) && "1".equals(request.getParameter("delete"))) {
        Status s = service.getStatus(Integer.parseInt(feedbackStatusId));

        service.deleteStatus(s);
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.status.deleted");
        text = feedbackStatusId;
    }

    /* Saves the data incase save has been selected by the user */
    else if ((feedbackStatusId != null) && "1".equals(request.getParameter("save"))) {
        Status s = service.getStatus(Integer.parseInt(feedbackStatusId));

        s.setStatus(status);
        service.saveStatus(s);
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "feedback.notification.status.saved");
        text = feedbackStatusId;
    }

    log.debug("Returning hello world text: " + text);

    return text;
}

From source file:org.grails.datastore.mapping.simpledb.util.SimpleDBTemplateImpl.java

public SimpleDBTemplateImpl(String accessKey, String secretKey) {
    Assert.isTrue(StringUtils.hasLength(accessKey) && StringUtils.hasLength(secretKey),
            "Please provide accessKey and secretKey");

    sdb = new AmazonSimpleDBClient(new BasicAWSCredentials(accessKey, secretKey));
}

From source file:com.google.code.ssm.aop.support.builder.NamespaceBuilder.java

@Override
protected void build(final AnnotationData data, final Annotation annotation,
        final Class<? extends Annotation> expectedAnnotationClass, final Method targetMethod) throws Exception {
    final String namespace = invokeMethod(annotation, expectedAnnotationClass, "namespace");
    if (AnnotationConstants.DEFAULT_STRING.equals(namespace) || !StringUtils.hasLength(namespace)) {
        throwException("Namespace for annotation [%s] must be defined on [%s]", expectedAnnotationClass,
                targetMethod);// w  w  w  .  j  a v a  2 s. c  om
    }

    data.setNamespace(namespace);
}

From source file:org.brekka.stillingar.spring.config.AnnotationConfigBeanDefinitionParser.java

@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    String serviceRef = element.getAttribute("service-ref");
    builder.addConstructorArgValue(":" + serviceRef);
    builder.addConstructorArgReference(serviceRef);
    String marker = element.getAttribute("marker");
    if (StringUtils.hasLength(marker)) {
        Class<?> theClass = ClassUtils.resolveClassName(marker, Thread.currentThread().getContextClassLoader());
        if (!theClass.isAnnotation()) {
            throw new ConfigurationException(String.format("The class '%s' is not an annotation", marker));
        }/*ww  w  .  ja  v  a  2s.c o m*/
        builder.addPropertyValue("markerAnnotation", theClass);
    }
}

From source file:com.google.code.ssm.aop.support.builder.AssignedKeyBuilder.java

@Override
protected void build(final AnnotationData data, final Annotation annotation,
        final Class<? extends Annotation> expectedAnnotationClass, final Method targetMethod) throws Exception {
    final String assignKey = invokeMethod(annotation, expectedAnnotationClass, "assignedKey");
    if (AnnotationConstants.DEFAULT_STRING.equals(assignKey) || !StringUtils.hasLength(assignKey)) {
        throwException("AssignedKey for annotation [%s] must be defined on [%s]", expectedAnnotationClass,
                targetMethod);//  w ww  . ja  v  a 2  s. co  m
    }

    data.setAssignedKey(assignKey);
}

From source file:grails.plugin.cache.web.ContentCacheParameters.java

public String getActionName() {
    if (actionName == null) {
        actionName = grailsWebRequest.getActionName();
        if (!StringUtils.hasLength(actionName) && controllerClass != null) {
            actionName = controllerClass.getDefaultAction();
        }/*w  ww .  j  av  a2 s  .com*/
    }
    return actionName;
}

From source file:com.dianping.cache.servlet.CacheMessageSenderServlet.java

/**
 * Get building message parameters, and then send this message to JMS
 * server.//w  w  w.  j  a va 2  s .co m
 */
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    PrintWriter out = resp.getWriter();
    try {
        String type = req.getParameter(MESSAGE_TYPE);
        String value = req.getParameter(MESSAGE_VALUE);

        if (!StringUtils.hasLength(type) || !StringUtils.hasLength(value)) {
            out.println(
                    "Cache message format should like this: http://host:port/cache-message/send.action?type=1&value=test");
        }
        int messageType = parseInt(type);
        if (Constants.KEYTYPE_VERSION_UPDATE_MESSAGE == messageType) {
            cacheManageService.clearByCategory(value);
        } else if (Constants.SINGLE_CACHE_REMOVE_MESSAGE == messageType) {
            cacheManageService.clearByKey("web", value);
            cacheManageService.clearByKey("memcached", value);
        }
        out.println("Send message successfully!");
    } finally {
        out.close();
    }
}

From source file:org.openmrs.module.feedback.web.SeverityFormController.java

@Override
protected String formBackingObject(HttpServletRequest request) throws Exception {
    String text = "";
    Object o = Context.getService(FeedbackService.class);
    FeedbackService service = (FeedbackService) o;
    String SeverityId = request.getParameter("feedbackSeverityId");
    String sortWeight = request.getParameter("sortWeight");
    String severity = request.getParameter("severity");

    if (!StringUtils.hasLength(SeverityId) || (service.getSeverity(Integer.parseInt(
            SeverityId)) == null)) { /* Just for statistics that the elemented is deleted already or do not exists */
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.severity.deleted");
    }/*ww w.j a v a 2  s.  c  o m*/

    /* This is to tell that the item will be deleted incase delete is submitted */
    else if ((SeverityId != null) && "1".equals(request.getParameter("delete"))) {
        Severity s = service.getSeverity(Integer.parseInt(SeverityId));

        service.deleteSeverity(s);
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.severity.deleted");
        text = SeverityId;
    }

    /* save the severity */
    else if ((SeverityId != null) && "1".equals(request.getParameter("save"))) {
        Severity s = service.getSeverity(Integer.parseInt(SeverityId));

        /** This makes sure that the Severity value always remain less then or equal to 50 */
        s.setSeverity(severity);

        if (isInt(sortWeight)) {
            s.setSortWeight(Integer.parseInt(sortWeight));
        } else {
            request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                    "feedback.notification.number.error");
            text = SeverityId;

            return text;
        }

        service.saveSeverity(s);
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                "feedback.notification.severity.added");
        text = SeverityId;
    }

    log.debug("Returning hello world text: " + text);

    return text;
}