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:org.openmrs.module.feedback.web.FeedbackPropertiesFormController.java

@Override
protected String formBackingObject(HttpServletRequest request) throws Exception {
    String text = "";
    Boolean feedbackMessage = null;

    /* To make sure that the status is neither NULL nor empty */
    String feedbackNotification = request.getParameter("feedbackNotification");
    String feedbackNotificationEmail = request.getParameter("feedbackNotificationEmail");
    String feedbackAdminNotification = request.getParameter("feedbackAdminNotification");
    String feedbackAdminNotificationEmail = request.getParameter("feedbackAdminNotificationEmail");
    String feedbackUiNotification = request.getParameter("feedbackUiNotification");

    if (StringUtils.hasLength(feedbackNotification)) {
        GlobalProperty globalProperty = new GlobalProperty();

        globalProperty.setProperty("feedback.notification");
        globalProperty.setPropertyValue(feedbackNotification);
        Context.getAdministrationService().setGlobalProperty(globalProperty);
        feedbackMessage = true;//from   w  w  w .j ava2s. c om
    }

    if (StringUtils.hasLength(feedbackAdminNotification)) {
        GlobalProperty globalProperty = new GlobalProperty();

        globalProperty.setProperty("feedback.admin.notification");
        globalProperty.setPropertyValue(feedbackAdminNotification);
        Context.getAdministrationService().setGlobalProperty(globalProperty);
        feedbackMessage = true;
    }

    if (StringUtils.hasLength(feedbackUiNotification)) {
        GlobalProperty globalProperty = new GlobalProperty();

        globalProperty.setProperty("feedback.ui.notification");
        globalProperty.setPropertyValue(feedbackUiNotification);
        Context.getAdministrationService().setGlobalProperty(globalProperty);
        feedbackMessage = true;
    }

    if (StringUtils.hasLength(feedbackNotificationEmail)) {
        if (validate(feedbackNotificationEmail)) {
            GlobalProperty globalProperty = new GlobalProperty();

            globalProperty.setProperty("feedback.notification.email");
            globalProperty.setPropertyValue(feedbackNotificationEmail);
            Context.getAdministrationService().setGlobalProperty(globalProperty);
            feedbackMessage = true;
        } else {
            request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                    "feedback.preference.email.incorrect");

            return text;
        }
    }

    if (StringUtils.hasLength(feedbackAdminNotificationEmail)) {
        if (validate(feedbackAdminNotificationEmail)) {
            GlobalProperty globalProperty = new GlobalProperty();

            globalProperty.setProperty("feedback.admin.notification.email");
            globalProperty.setPropertyValue(feedbackAdminNotificationEmail);
            Context.getAdministrationService().setGlobalProperty(globalProperty);
            feedbackMessage = true;
        } else {
            request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR,
                    "feedback.preference.email.incorrect");

            return text;
        }
    }

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

    if ((feedbackMessage != null) && (feedbackMessage == true)) {
        request.getSession().setAttribute(WebConstants.OPENMRS_MSG_ATTR, "feedback.preference.email.added");
    }

    return text;
}

From source file:io.pivotal.spring.xd.jdbcgpfdist.GPFDistMessageHandler.java

public GPFDistMessageHandler(int port, int flushCount, int flushTime, int batchTimeout, int batchCount,
        int batchPeriod, String delimiter) {
    super();/*from w ww. j a  v  a2  s .c o m*/
    this.port = port;
    this.flushCount = flushCount;
    this.flushTime = flushTime;
    this.batchTimeout = batchTimeout;
    this.batchCount = batchCount;
    this.batchPeriod = batchPeriod;
    this.delimiter = StringUtils.hasLength(delimiter) ? delimiter : null;
}

From source file:org.spring.cache.impl.CoherenceCacheFactoryBean.java

@Override
public void setBeanName(String beanName) {
    if (!StringUtils.hasLength(this.name)) {
        setName(beanName);
    }
}

From source file:com.carser.viamais.vo.TransactionFilter.java

private Predicate[] getPredicates(CriteriaBuilder cb, Root<Transaction> transaction) {
    List<Predicate> predicates = new ArrayList<>();
    if (StringUtils.hasLength(pattern)) {
        String[] words = pattern.split(" ");
        for (String word : words) {
            Predicate model = cb.like(transaction.get(Transaction_.car).get(Car_.model).get(Model_.name),
                    "%" + word + "%");
            Predicate customer = cb.like(transaction.get(Transaction_.customer).get(Customer_.name),
                    "%" + word + "%");
            predicates.add((cb.or(model, customer)));
        }/*from  w  ww  .java  2 s  .com*/
    }
    if (StringUtils.hasLength(rg)) {
        predicates.add(cb.like(transaction.get(Transaction_.customer).get(Customer_.rg), "%" + rg + "%"));
    }
    if (StringUtils.hasLength(cpf)) {
        predicates.add(cb.like(transaction.get(Transaction_.customer).get(Customer_.cpf).as(String.class),
                "%" + cpf + "%"));
    }
    if (StringUtils.hasLength(renavam)) {
        predicates.add(cb.like(transaction.get(Transaction_.car).get(Car_.renavam), "%" + renavam + "%"));
    }
    if (StringUtils.hasLength(plate)) {
        predicates.add(cb.equal(transaction.get(Transaction_.car).get(Car_.licensePlate), plate));
    }
    if (StringUtils.hasLength(chassi)) {
        predicates.add(cb.like(transaction.get(Transaction_.car).get(Car_.chassi), "%" + chassi + "%"));
    }
    Expression<Date> date = cb.function("date", Date.class, transaction.get(Transaction_.transactionDate));
    if (startDate != null) {
        predicates.add(cb.greaterThanOrEqualTo(date, startDate));
    }
    if (finalDate != null) {
        predicates.add(cb.lessThanOrEqualTo(date, finalDate));
    }
    if (StringUtils.hasLength(type)) {
        switch (type) {
        case "sale":
            predicates.add(cb.equal(transaction.get(Transaction_.type), Sale.class.getSimpleName()));
            break;
        case "purchase":
            predicates.add(cb.equal(transaction.get(Transaction_.type), Purchase.class.getSimpleName()));
            break;
        default:
            throw new BusinessException("transaction type not supported");
        }
    }
    if (StringUtils.hasLength(advertiser)) {
        predicates.add(cb.equal(transaction.get(Transaction_.advertiser), advertiser));
    }
    if (StringUtils.hasLength(financial)) {
        predicates.add(cb.like(cb.treat(transaction, Sale.class).get(Sale_.financial), financial));
    }
    if (seller != null) {
        predicates.add(cb.equal(transaction.get(Transaction_.seller).get(Seller_.id), seller));
    }
    return (predicates.toArray(new Predicate[predicates.size()]));
}

From source file:org.talend.daikon.spring.BndToSpringBeanNameGenerator.java

/**
 * Derive a bean name from one of the annotations on the class. First delegate to the super class and if it is not a
 * spring annotation then check for the bnd annotation
 * /*from  ww  w. j a v a2  s. c  o  m*/
 * @param annotatedDef the annotation-aware bean definition
 * @return the bean name, or {@code null} if none is found
 */
@Override
protected String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) {
    String beanName = super.determineBeanNameFromAnnotation(annotatedDef);
    if (beanName != null) {
        return beanName;
    } // else check for BND annotation
    AnnotationMetadata amd = annotatedDef.getMetadata();
    Set<String> types = amd.getAnnotationTypes();
    for (String type : types) {
        AnnotationAttributes attributes = AnnotationAttributes
                .fromMap(amd.getAnnotationAttributes(type, false));
        if (isStereotypeWithBndNameValue(type, amd.getMetaAnnotationTypes(type), attributes)) {
            Object value = attributes.get("name");
            if (value instanceof String) {
                String strVal = (String) value;
                if (StringUtils.hasLength(strVal)) {
                    if (beanName != null && !strVal.equals(beanName)) {
                        throw new IllegalStateException("Stereotype annotations suggest inconsistent "
                                + "component names: '" + beanName + "' versus '" + strVal + "'");
                    }
                    beanName = strVal;
                }
            }
        }
    }
    return beanName;
}

From source file:org.smf4j.spring.RegistrarFactoryBean.java

protected void registerProxy(Registrar r, RegistryNodeProxy nodeProxy, String parentName) {
    String name = nodeProxy.getName();
    if (StringUtils.hasLength(parentName)) {
        name = parentName + "." + name;
    }//w  w  w.j a  va2s .c  o m

    for (RegistryProxy proxy : nodeProxy.getChildren()) {
        if (proxy instanceof RegistryNodeChildProxy) {
            RegistryNodeChildProxy childProxy = (RegistryNodeChildProxy) proxy;
            String beanRef = childProxy.getChild();
            Object obj = applicationContext.getBean(beanRef);
            if (obj instanceof Accumulator) {
                // An accumulator
                RegistryNode node = r.getNode(name);
                node.register(childProxy.getName(), (Accumulator) obj);
            } else if (obj instanceof Calculator) {
                // A Caclulator
                RegistryNode node = r.getNode(name);
                node.register(childProxy.getName(), (Calculator) obj);
            } else {
                throw new RuntimeException(
                        String.format(
                                "[Node: %s, Child: %s] Node child "
                                        + "proxy is neither template, Accumulator, nor " + "Calculator.",
                                name, childProxy.getName()));
            }
        } else if (proxy instanceof RegistryNodeProxy) {
            // An embedded node
            r.getNode(name);
            registerProxy(r, (RegistryNodeProxy) proxy, name);
        }
    }
}

From source file:com.excilys.ebi.bank.util.Asserts.java

public static void hasLength(String text, String messagePattern, Object arg1, Object arg2) {
    if (!StringUtils.hasLength(text)) {
        throw new IllegalArgumentException(MessageFormatter.format(messagePattern, arg1, arg2).getMessage());
    }/*w  w  w  . j av  a  2 s  . com*/
}

From source file:org.cloudfoundry.tools.env.CloudEnvironment.java

/**
 * Returns the controller URL. This method will construct the URL based on the application URL. If the url cannot be
 * determined set a {@code cloudcontroller} environment variable.
 * @return the controller URL./*from w w  w.ja  v  a2  s  .  c o  m*/
 */
public String getControllerUrl() {
    String controllerUrl = getValue(CLOUD_CONTROLLER_VARIABLE_NAME);
    if (StringUtils.hasLength(controllerUrl)) {
        return controllerUrl;
    }

    ApplicationInstanceInfo instanceInfo = getInstanceInfo();
    List<String> uris = instanceInfo == null ? null : instanceInfo.getUris();
    if (uris == null || uris.isEmpty()) {
        return DEFAULT_CONTROLLER_URL;
    }
    String uri = uris.get(0).toLowerCase();
    if (uri.endsWith("cloudfoundry.com")) {
        return DEFAULT_CONTROLLER_URL;
    }
    if (!uri.startsWith("http")) {
        uri = "http://" + uri;
    }
    Matcher matcher = CONTROLLER_PATTERN.matcher(uri);
    if (matcher.matches()) {
        return matcher.group(1) + "api." + matcher.group(2);
    }

    return DEFAULT_CONTROLLER_URL;
}

From source file:com.starit.diamond.server.controller.AdminController.java

/**
 * ??/*from   w  w w  .  j  a v  a 2s  . c  o m*/
 * 
 * @param request
 * @param dataId
 * @param group
 * @param content
 * @param modelMap
 * @return
 */
@RequestMapping(value = "/postConfig", method = RequestMethod.POST)
public String postConfig(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("dataId") String dataId, @RequestParam("group") String group,
        @RequestParam("description") String description, @RequestParam("content") String content,
        ModelMap modelMap) {
    response.setCharacterEncoding("GBK");

    boolean checkSuccess = true;
    String errorMessage = "?";
    if (!StringUtils.hasLength(dataId) || DiamondUtils.hasInvalidChar(dataId.trim())) {
        checkSuccess = false;
        errorMessage = "DataId";
    }
    if (!StringUtils.hasLength(group) || DiamondUtils.hasInvalidChar(group.trim())) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!StringUtils.hasLength(content)) {
        checkSuccess = false;
        errorMessage = "";
    }
    if (!checkSuccess) {
        modelMap.addAttribute("message", errorMessage);
        try {
            response.sendError(FORBIDDEN_403, errorMessage);
        } catch (IOException ioe) {
            log.error(ioe.getMessage(), ioe.getCause());
        }
        return "/admin/confignew";
    }
    String userName = (String) request.getSession().getAttribute("user");
    this.configService.addConfigInfo(dataId, group, userName, content, description);

    request.getSession().setAttribute("message", "???!");
    return "redirect:" + listConfig(request, response, null, null, 1, 10, modelMap);
}

From source file:org.springsource.sinspctr.InspctrServer.java

/**
 * Set the contextPath to serve requests on. Empty string for root.
 *///w  w  w .  j  av a2  s.  c  o  m
public void setContextPath(String contextPath) {
    if (StringUtils.hasLength(contextPath) && !contextPath.startsWith("/")) {
        contextPath = "/" + contextPath;
    }
    this.contextPath = contextPath;
}