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.esupportail.twitter.web.TwitterController.java

@RequestMapping(value = { "EDIT" }, params = { "action=setTwitterTweetsNumber" })
public void setTwitterTweetsNumber(
        @RequestParam(value = "twitterTweetsNumber", required = true) String twitterTweetsNumber,
        ActionRequest request, ActionResponse response) throws Exception {

    // validate the submitted data
    if (StringUtils.hasText(twitterTweetsNumber) && StringUtils.hasLength(twitterTweetsNumber)) {
        int twitterTweetsNumberInt = -1;
        try {//from w ww  .  j a  v  a2 s . c o  m
            twitterTweetsNumberInt = (new Integer(twitterTweetsNumber)).intValue();
        } catch (Exception ex) {
        }
        if (twitterTweetsNumberInt > 0) {
            PortletPreferences prefs = request.getPreferences();
            prefs.setValue(PREF_TWITTER_TWEETS_NUMBER, twitterTweetsNumber);
            prefs.store();
        }
    }

    return;
}

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

/**
 * Setup the default cache interceptor //from  www  .  j a v a 2  s.  c o  m
 * 
 * @return A reference to the default cache interceptor.
 */
protected RuntimeBeanReference setupDefaultTriggersRemoveInterceptor(Element element,
        ParserContext parserContext, Object elementSource) {
    //If the default cache resolver factory was specified simply return a bean reference for that
    final String defaultTriggersRemoveInterceptor = element
            .getAttribute(XSD_ATTR__DEFAULT_TRIGGERS_REMOVE_INTECEPTOR);
    if (StringUtils.hasLength(defaultTriggersRemoveInterceptor)) {
        return new RuntimeBeanReference(defaultTriggersRemoveInterceptor);
    }

    //Use no reference
    return null;
}

From source file:com.reactive.hzdfs.cluster.HazelcastInstanceProxy.java

private void setGroupIds(String name, String password) {
    hzConfig.getMemberAttributeConfig().setStringAttribute(Configurator.NODE_INSTANCE_ID, getInstanceId());
    hzConfig.setInstanceName(getInstanceId());
    if (StringUtils.hasText(name)) {
        hzConfig.getGroupConfig().setName(name);
    }/*from www  . ja  v a2 s .c om*/
    if (StringUtils.hasLength(password)) {
        hzConfig.getGroupConfig().setPassword(password);
    }
}

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

/**
 * /* w  w  w. j a va 2 s .co m*/
 * 
 * @param modelMap
 * @return
 */
@RequestMapping(value = "/addUser", method = RequestMethod.POST)
public String addUser(HttpServletRequest request, HttpServletResponse response,
        @RequestParam("userName") String userName, @RequestParam("password") String password,
        ModelMap modelMap) {
    if (!StringUtils.hasLength(userName) || DiamondUtils.hasInvalidChar(userName.trim())) {
        request.getSession().setAttribute("message", "??");
        return "redirect:" + listUser(request, response, modelMap);
    }
    if (!StringUtils.hasLength(password) || DiamondUtils.hasInvalidChar(password.trim())) {
        request.getSession().setAttribute("message", "?");
        return "redirect:/admin/usernew";
    }
    if (this.userService.addUser(userName, password))
        request.getSession().setAttribute("message", "?!");
    else
        request.getSession().setAttribute("message", "!");
    return "redirect:" + listUser(request, response, modelMap);
}

From source file:podd.search.web.SearchCriteriaWeb.java

/**
 * Helper method to populate a search criteria object
 * @param sc/*from  ww w .  j a v a 2  s.  co m*/
 */
private boolean populateSearchCriteria(SearchCriteria sc) {

    // Get the creation date range
    Date startDateCreated = null, endDateCreated = null;
    try {
        SimpleDateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
        if (StringUtils.hasLength(startCreationDate))
            startDateCreated = dateFormatter.parse(startCreationDate);
        if (StringUtils.hasLength(endCreationDate))
            endDateCreated = dateFormatter.parse(endCreationDate);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    // Get the objectTypes              
    Set<String> objectTypeCol = new HashSet<String>();
    if (objectTypes != null) {
        for (String type : objectTypes) {
            objectTypeCol.add(type);
        }
    }

    // Retrieve the list of projects for which access is allowed depending the selected scope
    // TODO: It is known that there could be some performance issues, if the number of public projects becomes too many.
    // A possible solution would be to create a new boolean field in the index called 'public', such that everytime a Project object is
    // saved, this field is updated to reflect its publication status for all objects associated with that project.
    // One of the problems of doing it the suggested way is that a project status that has changed will not immediately take affect, because
    // the index is cached. Perhaps we should flush everytime a PODD project is saved.
    Set<String> inclusiveProjectIds = new HashSet<String>();

    boolean doSearch = false;
    // If the user is administrator, and no scope has been specified, then search all projects by default
    if (authenticatedUser != null && authenticatedUser.getIsAdministrator() && !this.getScopeMyProjects()
            && !this.getScopePublicProjects()) {
        doSearch = true;
    } else {

        if (this.getScopeMyProjects()) {
            inclusiveProjectIds
                    .addAll(projectService.getAuthenticatedUserProjects(authenticatedUser.getUserName()));
        }
        // If the user is anonymous, then search on public projects
        if (authenticatedUser == null || this.getScopePublicProjects()) {
            inclusiveProjectIds.addAll(projectService.getPublicProjects());
        }

        // Only perform search if there is at least one project Id that can be searched
        doSearch = (inclusiveProjectIds.size() > 0) ? true : false;
    }
    LOGGER.info("doSearch=" + doSearch);

    sc.setQueryAllTheseWords(queryAllTheseWords);
    sc.setQueryAnyTheseWords(queryAnyTheseWords);
    sc.setQueryPhrase(queryPhrase);
    sc.setQueryExclude(queryExclude);
    sc.setStart(start);
    sc.setStartCreationDate(startDateCreated);
    sc.setEndCreationDate(endDateCreated);
    sc.setObjectTypes(objectTypeCol);
    sc.setProjectStatus(ProjectStatus.getPoddEntityState(this.getProjectStatus()));
    sc.setPublicationStatus(ProjectPublicationStatus.getStatus(this.getPublicationStatus()));
    sc.setProjectIdsInclusive(inclusiveProjectIds);

    return doSearch;
}

From source file:org.kmnet.com.fw.web.pagination.PaginationInfo.java

/**
 * Returns paginationURL after setting specified page number and display count to it
 * @param pageIndex index of page number (page index is start with 0).
 * @return String Pagination URL with URL page number and display count set to it
 *///from   w  ww .jav  a  2s  . c o  m
public String getPageUrl(int pageIndex) {
    Map<String, Object> attr = createAttributeMap(pageIndex, page.getSize(), page.getSort());
    StringBuilder pageUriBuilder = new StringBuilder(pageUri.expand(attr).encode().toUriString());
    if (StringUtils.hasLength(criteriaQuery)) {
        if (pageUri.getQueryParams().isEmpty()) {
            pageUriBuilder.append("?");
        } else {
            pageUriBuilder.append("&");
        }
        pageUriBuilder.append(criteriaQuery);
    }
    return pageUriBuilder.toString();
}

From source file:no.digipost.api.interceptors.Wss4jInterceptor.java

/**
 * Creates and initializes a request data for the given message context.
 *
 * @param messageContext the message context
 * @return the request data//  ww w  . j  a  v a 2 s  . c o  m
 */
protected RequestData initializeRequestData(final MessageContext messageContext) {
    RequestData requestData = new RequestData();
    requestData.setMsgContext(messageContext);

    // reads securementUsername first from the context then from the property
    String contextUsername = (String) messageContext.getProperty(SECUREMENT_USER_PROPERTY_NAME);
    if (StringUtils.hasLength(contextUsername)) {
        requestData.setUsername(contextUsername);
    } else {
        requestData.setUsername(securementUsername);
    }
    requestData.setAppendSignatureAfterTimestamp(true);
    requestData.setTimeToLive(securementTimeToLive);

    requestData.setWssConfig(wssConfig);
    return requestData;
}