Example usage for org.springframework.util StringUtils isEmpty

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

Introduction

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

Prototype

public static boolean isEmpty(@Nullable Object str) 

Source Link

Document

Check whether the given object (possibly a String ) is empty.

Usage

From source file:com.luna.common.web.interceptor.SetCommonDataInterceptor.java

/**
 * ?//w w w  .  j av a  2 s.  c om
 * 1?request.parameterBackURL
 * 2??header referer
 *
 * @param request
 * @return
 */
private String extractBackURL(HttpServletRequest request) {
    String url = request.getParameter(Constants.BACK_URL);

    //Filter  getParameternull ?Interceptor

    if (StringUtils.isEmpty(url)) {
        url = request.getHeader("Referer");
    }

    if (!StringUtils.isEmpty(url) && (url.startsWith("http://") || url.startsWith("https://"))) {
        return url;
    }

    if (!StringUtils.isEmpty(url) && url.startsWith(request.getContextPath())) {
        url = getBasePath(request) + url;
    }
    return url;
}

From source file:org.psikeds.resolutionengine.datalayer.vo.ValueObject.java

/**
 * @param obj/*from  w w w . java 2s .c  o  m*/
 *          a ValueObject
 * @return the value 0 if argument Object is a ValueObject of same Class and its ID is equal to
 *         the ID of this Object;
 *         a value greater than 0 if the specified Object is a ValueObject but has no ID
 *         or its ID is lexicographically less than the ID of this Object;
 *         a value less 0 else
 * @see java.lang.Object#equals(Object obj)
 * @see java.lang.String#equals(String str)
 * @throws IllegalArgumentException
 *           if argument Object is null or not a ValueObject
 */
@Override
public int compareTo(final Object obj) {
    // check that obj is not null and a value object
    if (!(obj instanceof ValueObject)) {
        throw new IllegalArgumentException("Not a ValueObject: " + String.valueOf(obj));
    }
    final ValueObject vo = (ValueObject) obj;
    // check that this is the same type of value object
    if (!vo.getClass().equals(this.getClass())) {
        return vo.getClass().getName().compareTo(this.getClass().getName());
    }
    // value objects without IDs can never be compared
    if (StringUtils.isEmpty(vo.getId())) {
        return 1;
    }
    if (StringUtils.isEmpty(this.getId())) {
        return -1;
    }
    // compare IDs
    return this.getId().compareTo(vo.getId());
}

From source file:com.developmentsprint.spring.breaker.config.BreakerAdviceParser.java

private RootBeanDefinition parseAttributeSource(List<Element> methods, ParserContext parserContext) {
    ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute> circuitBreakerAttributeMap = new ManagedMap<TypedStringValue, DefaultCircuitBreakerAttribute>(
            methods.size());//from  w  ww .j a  v a2 s . c  o m

    circuitBreakerAttributeMap.setSource(parserContext.extractSource(methods));

    for (Element methodEle : methods) {
        String methodName = methodEle.getAttribute(METHOD_NAME_ATTRIBUTE);
        TypedStringValue nameHolder = new TypedStringValue(methodName);
        nameHolder.setSource(parserContext.extractSource(methodEle));

        RuleBasedCircuitBreakerAttribute attribute = new RuleBasedCircuitBreakerAttribute();
        attribute.setMethodName(methodName);

        String cbName = methodEle.getAttribute(CB_NAME_ATTRIBUTE);
        if (StringUtils.isEmpty(cbName)) {
            attribute.setName(methodName);
        } else {
            attribute.setName(cbName);
        }

        ManagedMap<String, String> props = new ManagedMap<String, String>();
        Element propsElement = DomUtils.getChildElementByTagName(methodEle, "properties");
        if (propsElement != null) {
            //Map<String, String> props = new HashMap<String, String>();
            List<Element> propElements = DomUtils.getChildElementsByTagName(propsElement, "prop");
            for (Element propElement : propElements) {
                String key = propElement.getAttribute("key");
                String val = DomUtils.getTextValue(propElement);
                props.put(key, new TypedStringValue(val).getValue());
            }
            attribute.setProperties(props);
        }
        if (log.isDebugEnabled()) {
            for (Map.Entry<String, String> e : attribute.getProperties().entrySet()) {
                log.debug("{} prop : {} : {}", cbName, e.getKey(), e.getValue());
            }
        }

        circuitBreakerAttributeMap.put(nameHolder, attribute);
    }

    RootBeanDefinition attributeSourceDefinition = new RootBeanDefinition(
            NameMatchCircuitBreakerAttributeSource.class);
    attributeSourceDefinition.setSource(parserContext.extractSource(methods));
    attributeSourceDefinition.getPropertyValues().add("nameMap", circuitBreakerAttributeMap);
    return attributeSourceDefinition;
}

From source file:burstcoin.jminer.core.reader.Reader.java

/**
 * Post construct./*w w w  .ja va2s  .  c  o m*/
 */
@PostConstruct
protected void postConstruct() {
    Boolean poolMining = CoreProperties.isPoolMining();

    String numericAccountId;
    if (poolMining) {
        numericAccountId = CoreProperties.getNumericAccountId();
    } else {
        // calculate numericAccountId
        byte[] publicKey = Crypto.getPublicKey(CoreProperties.getPassPhrase());
        byte[] publicKeyHash = Crypto.sha256().digest(publicKey);
        long accountId = Convert.fullHashToId(publicKeyHash);
        numericAccountId = Convert.toUnsignedLong(accountId);
    }

    if (!StringUtils.isEmpty(numericAccountId)) {
        this.numericAccountId = numericAccountId;
    } else {
        LOG.error("init reader failed!");
    }

    directories = CoreProperties.getPlotPaths();
    chunkPartNonces = CoreProperties.getChunkPartNonces();
    scanPathsEveryRound = CoreProperties.isScanPathsEveryRound();
    readerThreads = CoreProperties.getReaderThreads();
    capacityLookup = new HashMap<>();

    if (CoreProperties.isListPlotFiles()) {
        getPlots().printPlotFiles();
    }
}

From source file:com.formkiq.core.controller.admin.AdminController.java

/**
 * Admin Forms page./*from   w w w .ja va  2 s  .  c  o m*/
 * @param type {@link String}
 * @param client {@link String}
 * @param name {@link String}
 * @param uuid {@link String}
 * @return {@link String}
 */
@RequestMapping(value = "/forms", method = RequestMethod.GET)
public String forms(@RequestParam(value = "type", required = false) final String type,
        @RequestParam(value = "client", required = false) final String client,
        @RequestParam(value = "name", required = false) final String name,
        @RequestParam(value = "uuid", required = false) final String uuid) {

    if (StringUtils.isEmpty(type)) {
        return "redirect:/admin/index";
    }

    if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(uuid) && !StringUtils.isEmpty(client)) {
        return "admin/formdetails";
    }

    return "admin/forms";
}

From source file:org.psikeds.queryagent.interfaces.presenter.pojos.POJO.java

public static String composeId(final String... ids) {
    final StringBuilder sb = new StringBuilder();
    for (final String pid : ids) {
        if (!StringUtils.isEmpty(pid)) {
            if (sb.length() > 0) {
                sb.append(COMPOSE_ID_SEPARATOR);
            }/*from ww  w  .ja  v  a 2s.  co  m*/
            sb.append(pid);
        }
    }
    return sb.toString();
}

From source file:org.psikeds.resolutionengine.interfaces.pojos.POJO.java

protected static String composeId(final String... ids) {
    final StringBuilder sb = new StringBuilder();
    for (final String pid : ids) {
        if (!StringUtils.isEmpty(pid)) {
            if (sb.length() > 0) {
                sb.append(COMPOSE_ID_SEPARATOR);
            }//from  w w w  . j  a v a  2 s.co  m
            sb.append(pid);
        }
    }
    return sb.toString();
}

From source file:org.ihtsdo.otf.refset.graph.gao.SearchGao.java

/**
 * @param refsetId/*from ww  w .  ja v  a 2 s .  c o m*/
 * @param from
 * @param to
 * @return
 * @throws RefsetGraphAccessException
 */
public SearchResult<String> getSearchResult(String query, Integer from, Integer to)
        throws RefsetGraphAccessException {

    SearchResult<String> result = new SearchResult<String>();

    //TitanGraph g = null;

    try {

        //g = f.getReadOnlyGraph();
        String queryString = String.format(url + QUERY, query, from, to - from);
        LOGGER.debug("Getting getting search result for {}", queryString);

        JsonNode response = rt.getForObject(queryString, JsonNode.class);

        LOGGER.debug("search service call successfully returned with {} ", response);

        Iterator<String> fields = response.fieldNames();
        while (fields.hasNext()) {
            String field = fields.next();
            if ("took".equalsIgnoreCase(field)) {

                result.setTime(response.get(field).asInt());
            }

            if ("hits".equalsIgnoreCase(field)) {

                Iterator<String> hitsFields = response.get(field).fieldNames();

                while (hitsFields.hasNext()) {

                    String hitsField = hitsFields.next();

                    if ("total".equalsIgnoreCase(hitsField)) {

                        result.setTotalNoOfResults(response.get(field).get(hitsField).asInt());
                    }

                    if ("hits".equalsIgnoreCase(hitsField)) {

                        Iterator<JsonNode> source = response.get(field).get(hitsField).elements();
                        List<String> r = new ArrayList<String>();

                        while (source.hasNext()) {

                            String uuid = source.next().at("/_source/parentId").asText();
                            if (!StringUtils.isEmpty(uuid) && !r.contains(uuid)) {

                                r.add(uuid);
                            }

                        }

                        //for now override total with number of records.TODO need something else 
                        result.setTotalNoOfResults(r.size());
                        result.setRecords(r);

                    }

                }
            }

        }

    } catch (Exception e) {

        //RefsetGraphFactory.rollback(g);         
        LOGGER.error("Error getting refsets member history", e);
        throw new RefsetGraphAccessException(e.getMessage(), e);

    }

    return result;
}

From source file:com.formkiq.core.service.UserServiceImpl.java

@Override
public User createUser(final String clientid, final String email, final String password,
        final UserStatus status, final UserRole role, final String loginToken)
        throws PreconditionFailedException {

    if (!this.securityService.isAdmin()) {

        if (this.systemPropertyService.isInviteOnly() && !UserStatus.INVITE.equals(status)) {
            throw new PreconditionFailedException("User can only be created via invite");
        }/*from w ww.j av  a2s  .c o  m*/
    }

    if (!EmailValidator.getInstance().isValid(email)) {
        throw new PreconditionFailedException("Invalid Email " + email);
    }

    if (StringUtils.isEmpty(password)) {
        throw new PreconditionFailedException("Password required");
    }

    if (status == null) {
        throw new PreconditionFailedException("UserStatus required");
    }

    if (role == null) {
        throw new PreconditionFailedException("UserRole required");
    }

    if (this.userDao.findUser(email) != null) {
        throw new PreconditionFailedException("Email already registered");
    }

    User user = new User();
    user.setClientid(clientid);
    user.setEmail(email);
    user.setStatus(status);
    user.setRole(role);
    setUserPassword(user, password);
    setUserLoginToken(user, loginToken);

    user = this.userDao.saveUser(user);

    return user;
}

From source file:cn.guoyukun.spring.web.interceptor.SetCommonDataInterceptor.java

/**
 * ?//from   www  .j  a v  a2 s  .com
 * 1?request.parameterBackURL
 * 2??header referer
 *
 * @param request
 * @return
 */
private String extractBackURL(HttpServletRequest request) {
    String url = request.getParameter(Constants.BACK_URL);

    //Filter  getParameternull ?Interceptor

    if (StringUtils.isEmpty(url)) {
        url = request.getHeader("Referer");
    }

    if (!StringUtils.isEmpty(url) && (url.startsWith("http://") || url.startsWith("https://"))) {
        return url;
    }

    if (!StringUtils.isEmpty(url) && url.startsWith(request.getContextPath())) {
        url = getBasePath(request) + url;
    }
    LOG.info("BACKURL:{}", url);
    return url;
}