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.qpark.eip.core.failure.FailureAssert.java

/**
 * Assert that the given String is not empty; that is, it must not be
 * <code>null</code> and not the empty String.
 *
 * <pre class="code">/*ww w.  j a  v a2 s .c om*/
 * Assert.hasLength(name, &quot;Name must not be empty&quot;);
 * </pre>
 *
 * @param text
 *            the String to check
 * @param errorCode
 *            the error code to use if the assertion fails
 * @see StringUtils#hasLength
 */
public static void hasLength(final String text, final String errorCode) {
    if (!StringUtils.hasLength(text)) {
        BaseFailureHandler.throwFailureException(errorCode, text);
    }
}

From source file:org.kmnet.com.fw.common.codelist.validator.AbstractExistInCodeListValidator.java

/**
 * Validate.//from ww w .j  a  v  a 2  s .c om
 * @param value target value.
 * @param constraintContext constraint context.
 * @return if valid value, return true.
 */
@Override
public boolean isValid(T value, ConstraintValidatorContext constraintContext) {
    String code = getCode(value);

    if (!StringUtils.hasLength(code)) {
        return true;
    }
    if (logger.isTraceEnabled()) {
        logger.trace("check if {} exists in {}", code, codeList.getCodeListId());
    }
    return codeList.asMap().containsKey(code);
}

From source file:org.jmxtrans.embedded.samples.cocktail.cocktail.CocktailRepository.java

/**
 * @param ingredientName//from w  ww.  jav a  2 s  .co  m
 * @param cocktailName
 * @return
 */
public Collection<Cocktail> find(@Nullable String ingredientName, @Nullable String cocktailName) {
    SortedSet<Cocktail> result = new TreeSet<Cocktail>();
    for (Cocktail cocktail : cocktails.values()) {
        if (cocktailName == null && ingredientName == null) {
            result.add(cocktail);
        }
        if (StringUtils.hasLength(cocktailName)) {
            if (cocktail.getName().toLowerCase().contains(cocktailName.toLowerCase())) {
                result.add(cocktail);
                break;
            }
        }
        if (ingredientName != null) {
            for (String cocktailIngredient : cocktail.getIngredientNames()) {
                if (cocktailIngredient.toLowerCase().contains(ingredientName.toLowerCase())) {
                    result.add(cocktail);
                    break;
                }
            }
        }

    }
    return result;
}

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

public static void hasLength(String text, String messagePattern, Object arg) {
    if (!StringUtils.hasLength(text)) {
        throw new IllegalArgumentException(MessageFormatter.format(messagePattern, arg).getMessage());
    }// ww w .j a v a 2s.c o m
}

From source file:org.home.petclinic2.validator.PetValidator.java

@Override
public void validate(Object obj, Errors errors) {
    // fail fast if not given a Pet object. This should have already been
    // done via the supports method but since the method is public it
    // doesn't hurt
    if (!(obj instanceof Pet)) {
        throw new IllegalArgumentException(
                "Pet validator was given object that is not of type Pet. obj obj: " + obj);
    }//from  w  w  w.ja  v a  2  s  .c o  m

    Pet pet = (Pet) obj;

    // name validation
    if (!StringUtils.hasLength(pet.getName())) {
        errors.rejectValue("name", "required", "required");
    }

    // type validation
    if (pet.isNew() && pet.getType() == null) {
        errors.rejectValue("type", "required", "required");
    }

    // type validation
    if (pet.getBirthDate() == null) {
        errors.rejectValue("birthDate", "required", "required");
    }
}

From source file:org.openspaces.esb.mule.eventcontainer.OpenSpacesMessageDispatcher.java

public OpenSpacesMessageDispatcher(OutboundEndpoint endpoint) throws CreateException {
    super(endpoint);
    ApplicationContext applicationContext = ((OpenSpacesConnector) getConnector()).getApplicationContext();
    if (applicationContext == null) {
        throw new CreateException(CoreMessages.connectorWithProtocolNotRegistered(connector.getProtocol()),
                this);
    }/*from   w w w  .ja v  a2s .  c  om*/
    initWritingAttributes(endpoint);
    String spaceId = endpoint.getEndpointURI().getPath();
    if (!StringUtils.hasLength(spaceId)) {
        spaceId = endpoint.getEndpointURI().getAddress();
    } else {
        if (spaceId.startsWith("/")) {
            spaceId = spaceId.substring(1);
        }
    }
    gigaSpace = (GigaSpace) applicationContext.getBean(spaceId);
}

From source file:io.isoft.reg.service.StaffDictServiceImpl.java

@Override
public List<StaffDict> findStaffs(StaffDictSearchCriteria criteria) {
    Assert.notNull(criteria, "Criteria must not be null");
    String deptCode = criteria.getDeptCode();
    if (!StringUtils.hasLength(deptCode)) {
        return this.staffDictRepository.findAll();
    }/*from www.  ja v a  2  s .  c o  m*/
    return this.staffDictRepository.findByDeptCode(deptCode);
}

From source file:com.parakhcomputer.web.servlet.view.tiles2.TilesAjaxUrlBasedViewResolver.java

/**
 * Does everything the <code>UrlBasedViewResolver</code> does and 
 * also sets some Tiles specific values on the view.
 * // w ww .  j  a  va  2  s.  c  om
 * @param viewName the name of the view to build
 * @return the View instance
 * @throws Exception if the view couldn't be resolved
 * @see #loadView(String, java.util.Locale)
 */
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
    AbstractUrlBasedView view = super.buildView(viewName);

    // if DynamicTilesView, set tiles specific values
    if (view instanceof DynamicTilesView) {
        DynamicTilesView dtv = (DynamicTilesView) view;

        if (StringUtils.hasLength(tilesDefinitionName)) {
            dtv.setTilesDefinitionName(tilesDefinitionName);
        }

        if (StringUtils.hasLength(tilesBodyAttributeName)) {
            dtv.setTilesBodyAttributeName(tilesBodyAttributeName);
        }

        if (tilesDefinitionDelimiter != null) {
            dtv.setTilesDefinitionDelimiter(tilesDefinitionDelimiter);
        }
    }

    return view;
}

From source file:org.brickred.controller.SuccessController.java

@RequestMapping(value = "/authSuccess")
public ModelAndView getRedirectURL(final HttpServletRequest request) throws Exception {
    ModelAndView mv = new ModelAndView();
    List<Contact> contactsList = new ArrayList<Contact>();
    SocialAuthManager manager = socialAuthTemplate.getSocialAuthManager();
    AuthProvider provider = manager.getCurrentAuthProvider();
    contactsList = provider.getContactList();
    if (contactsList != null && contactsList.size() > 0) {
        for (Contact p : contactsList) {
            if (!StringUtils.hasLength(p.getFirstName()) && !StringUtils.hasLength(p.getLastName())) {
                p.setFirstName(p.getDisplayName());
            }//from w  ww. j av  a 2  s . c o  m
        }
    }
    mv.addObject("profile", provider.getUserProfile());
    mv.addObject("contacts", contactsList);
    mv.setViewName("/jsp/authSuccess.jsp");

    return mv;
}

From source file:org.zilverline.web.HandlerValidator.java

/**
 * Validator for SearchForm. Validates name, maxResults, startAt and query
 * //  w  ww .  ja v  a2s .c om
 * @see org.springframework.validation.Validator#validate(java.lang.Object, org.springframework.validation.Errors)
 */
public void validate(Object obj, Errors errors) {
    Handler handler = (Handler) obj;
    Map mappings = handler.getMappings();
    // convert the keys to lowercase
    Iterator mapping = mappings.entrySet().iterator();

    try {
        while (mapping.hasNext()) {
            Map.Entry element = (Map.Entry) mapping.next();
            String archiver = (String) element.getValue();
            log.debug("checking mappings: " + archiver);
            // can be empty: then java.util.Zip used
            if (StringUtils.hasLength(archiver)) {
                // the archiver is an external application with options,
                // check whether the application exists
                String exe = archiver.split(" ")[0];
                log.debug("checking mappings: " + exe);
                File exeFile = new File(exe);
                if (exeFile.exists()) {
                    log.debug("Can find " + exe);
                    continue;
                }

                // else try find the thing on the path
                Process proc = Runtime.getRuntime().exec(exe);
                // any error message?
                StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
                // any output?
                StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
                // kick them off
                errorGobbler.start();
                outputGobbler.start();

                proc.destroy();
                log.debug("Exit value: " + proc.exitValue());

                // everthing OK?
                if (proc.exitValue() != 0) {
                    // error executing proc
                    log.debug(" --> Can't execute: '" + exe + "'. Exit value: "
                            + SysUtils.getErrorTextById(proc.exitValue()));
                    log.debug("mappings must exist on disk: " + exe);
                    errors.rejectValue("mappings", null, null, "must exist on disk.");
                } else {
                    log.debug(" --> Can execute: '" + exe + "'. Exit value: "
                            + SysUtils.getErrorTextById(proc.exitValue()));
                }
            }
        }
    } catch (Exception e) {
        log.debug("Can not execute one of the mappings", e);
        errors.rejectValue("mappings", null, null, "must exist on disk.");
    }

}