Java Code Examples for org.thymeleaf.util.StringUtils

The following examples show how to use org.thymeleaf.util.StringUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected String computeResourceName(final IEngineConfiguration configuration, final String ownerTemplate,
    final String template, final String prefix, final String suffix, final Map<String, String> templateAliases,
    final Map<String, Object> templateResolutionAttributes) {

  Validate.notNull(template, "Template name cannot be null");

  // Don't bother computing resource name if template is not extensible
  if (!template.startsWith(EXT_FRAG_PREFIX))
    return template;

  String resourceName = template.substring(PREFIX_LENGTH);
  if (!StringUtils.isEmptyOrWhitespace(prefix))
    resourceName = prefix + resourceName;
  if (!StringUtils.isEmptyOrWhitespace(suffix))
    resourceName = resourceName + suffix;

  TdsContext tdsContext = (TdsContext) applicationContext.getBean("TdsContext");
  resourceName = tdsContext.getThreddsDirectory() + resourceName;


  return resourceName;
}
 
Example 2
Source Project: SecKillShop   Source File: GoodsController.java    License: MIT License 6 votes vote down vote up
@RequestMapping("/to_list")
@ResponseBody
public String toList(Model model, MiaoshaUser user, HttpServletRequest request, HttpServletResponse response) {
    model.addAttribute("user", user);
    //取缓存
    String html = redisService.get(GoodsKey.getGoodList, "", String.class);
    if (!StringUtils.isEmpty(html)) {
        return html;
    }
    List<GoodsVo> listGoodsVo = goodsService.listGoodsVo();
    model.addAttribute("listGoodsVo", listGoodsVo);

    WebContext ctx = new WebContext(request, response, request.getServletContext(), request.getLocale(), model.asMap());
    html = thymeleafViewResolver.getTemplateEngine().process("goodlist", ctx);
    if (!StringUtils.isEmpty(html)) {
        redisService.set(GoodsKey.getGoodList, "", html);
    }
    return html;
}
 
Example 3
Source Project: wallride   Source File: WallRideResourceTemplateResource.java    License: Apache License 2.0 6 votes vote down vote up
public Reader reader() throws IOException {
	// Will never return null, but an IOException if not found
	try {
		final InputStream inputStream = this.resource.getInputStream();
		if (!StringUtils.isEmptyOrWhitespace(this.characterEncoding)) {
			return new BufferedReader(new InputStreamReader(new BufferedInputStream(inputStream), this.characterEncoding));
		}

		return new BufferedReader(new InputStreamReader(new BufferedInputStream(inputStream)));
	} catch (AmazonS3Exception e) {
		if (e.getStatusCode() == 404) {
			throw new IOException(e);
		}
		throw e;
	}
}
 
Example 4
Source Project: thymeleaf-extras-shiro   Source File: ShiroFacade.java    License: Apache License 2.0 6 votes vote down vote up
public static boolean hasAllRoles(final Collection<String> roles) {
    if (SecurityUtils.getSubject() != null) {
        if (roles.isEmpty()) {
            return false;
        }

        final Subject subject = SecurityUtils.getSubject();
        for (final String role : roles) {
            if (!subject.hasRole(StringUtils.trim(role))) {
                return false;
            }
        }
        return true;
    }
    return false;
}
 
Example 5
Source Project: alcor   Source File: RestPreconditions.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceProjectId(CustomerResource resource, String projectId) {
    String resourceProjectId = resource.getProjectId();
    if (StringUtils.isEmpty(resourceProjectId)) {
        resource.setProjectId(projectId);
    } else if (!resourceProjectId.equalsIgnoreCase(projectId)) {
        System.out.println("Resource id not matched " + resourceProjectId + " : " + projectId);
        resource.setProjectId(projectId);
    }
}
 
Example 6
Source Project: alcor   Source File: RestPreconditions.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceVpcId(CustomerResource resource, String vpcId) {
    String resourceVpcId = null;
    if (resource instanceof VpcState) {
        resourceVpcId = resource.getId();
    } else if (resource instanceof SubnetState) {
        resourceVpcId = ((SubnetState) resource).getVpcId();
    }

    if (StringUtils.isEmpty(resourceVpcId)) {
        resource.setId(vpcId);
    } else if (!resourceVpcId.equalsIgnoreCase(vpcId)) {
        System.out.println("Resource vpc id not matched " + resourceVpcId + " : " + vpcId);
        resource.setId(vpcId);
    }
}
 
Example 7
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceProjectId(CustomerResource resource, String projectId) {
    String resourceProjectId = resource.getProjectId();
    if (StringUtils.isEmpty(resourceProjectId)) {
        resource.setProjectId(projectId);
    } else if (!resourceProjectId.equalsIgnoreCase(projectId)) {
        logger.log(Level.INFO, "Resource id not matched " + resourceProjectId + " : " + projectId);
        resource.setProjectId(projectId);
    }
}
 
Example 8
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceVpcId(CustomerResource resource, String vpcId) {
    String resourceVpcId = null;
    if (resource instanceof VpcEntity) {
        resourceVpcId = resource.getId();
    }

    if (StringUtils.isEmpty(resourceVpcId)) {
        resource.setId(vpcId);
    } else if (!resourceVpcId.equalsIgnoreCase(vpcId)) {
        logger.log(Level.INFO, "Resource vpc id not matched " + resourceVpcId + " : " + vpcId);
        resource.setId(vpcId);
    }
}
 
Example 9
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceSegmentId(CustomerResource resource, String segmentId) {
    String resourceSegmentId = null;
    if (resource instanceof SegmentEntity) {
        resourceSegmentId = resource.getId();
    }

    if (StringUtils.isEmpty(resourceSegmentId)) {
        resource.setId(segmentId);
    } else if (!resourceSegmentId.equalsIgnoreCase(segmentId)) {
        logger.log(Level.INFO, "Resource segment id not matched " + resourceSegmentId + " : " + segmentId);
        resource.setId(segmentId);
    }
}
 
Example 10
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceSegmentRangeId(CustomerResource resource, String segmentRangeId) {
    String resourceSegmentRangeId = null;
    if (resource instanceof NetworkSegmentRangeEntity) {
        resourceSegmentRangeId = resource.getId();
    }

    if (StringUtils.isEmpty(resourceSegmentRangeId)) {
        resource.setId(segmentRangeId);
    } else if (!resourceSegmentRangeId.equalsIgnoreCase(segmentRangeId)) {
        logger.log(Level.INFO, "Resource segment range id not matched " + resourceSegmentRangeId + " : " + segmentRangeId);
        resource.setId(segmentRangeId);
    }
}
 
Example 11
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceProjectId(CustomerResource resource, String projectId) {
    String resourceProjectId = resource.getProjectId();
    if (StringUtils.isEmpty(resourceProjectId)) {
        resource.setProjectId(projectId);
    } else if (!resourceProjectId.equalsIgnoreCase(projectId)) {
        System.out.println("Resource id not matched " + resourceProjectId + " : " + projectId);
        resource.setProjectId(projectId);
    }
}
 
Example 12
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceVpcId(CustomerResource resource, String vpcId) {
    String resourceVpcId = null;
    if (resource instanceof RouteEntity) {
        resourceVpcId = resource.getId();
    }

    if (StringUtils.isEmpty(resourceVpcId)) {
        resource.setId(vpcId);
    } else if (!resourceVpcId.equalsIgnoreCase(vpcId)) {
        System.out.println("Resource vpc id not matched " + resourceVpcId + " : " + vpcId);
        resource.setId(vpcId);
    }
}
 
Example 13
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceProjectId(CustomerResource resource, String projectId) {
    String resourceProjectId = resource.getProjectId();
    if (StringUtils.isEmpty(resourceProjectId)) {
        resource.setProjectId(projectId);
    } else if (!resourceProjectId.equalsIgnoreCase(projectId)) {
        System.out.println("Resource id not matched " + resourceProjectId + " : " + projectId);
        resource.setProjectId(projectId);
    }
}
 
Example 14
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static void populateResourceVpcId(CustomerResource resource, String vpcId) {
    String resourceVpcId = null;
    if (resource instanceof VpcEntity) {
        resourceVpcId = resource.getId();
    }

    if (StringUtils.isEmpty(resourceVpcId)) {
        resource.setId(vpcId);
    } else if (!resourceVpcId.equalsIgnoreCase(vpcId)) {
        System.out.println("Resource vpc id not matched " + resourceVpcId + " : " + vpcId);
        resource.setId(vpcId);
    }
}
 
Example 15
Source Project: SecKillShop   Source File: IsMobileValidator.java    License: MIT License 5 votes vote down vote up
@Override
public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) {
    /** 判断值是否为必须的*/
    if (required) {
        return ValidatorUtil.isMobile(s);
    } else {
        if (StringUtils.isEmpty(s)) {
            return false;
        }
        return ValidatorUtil.isMobile(s);
    }
}
 
Example 16
Source Project: SecKillShop   Source File: MiaoshaUserService.java    License: MIT License 5 votes vote down vote up
public MiaoshaUser getMiaoshaUserByToken(String token, HttpServletResponse response) {
    if (StringUtils.isEmpty(token)) {
        return null;
    }
    MiaoshaUser user = redisService.get(MiaoshaKey.token, token, MiaoshaUser.class);
    //when user login and use the website,extend to the cookie datetime
    if (user != null) {
        addCookie(user, token, response);
    }
    return user;
}
 
Example 17
Source Project: SecKillShop   Source File: UserArgumentResolver.java    License: MIT License 5 votes vote down vote up
@Override
public Object resolveArgument(MethodParameter methodParameter, ModelAndViewContainer modelAndViewContainer, NativeWebRequest nativeWebRequest, WebDataBinderFactory webDataBinderFactory) throws Exception {
    HttpServletRequest request = nativeWebRequest.getNativeRequest(HttpServletRequest.class);
    HttpServletResponse response = nativeWebRequest.getNativeResponse(HttpServletResponse.class);

    String paramsToken = request.getParameter(MiaoshaUserService.LOGIN_COOKIE_TOKEN);
    String cookieToken = getCookieValue(request, MiaoshaUserService.LOGIN_COOKIE_TOKEN);
    if (StringUtils.isEmpty(cookieToken) && StringUtils.isEmpty(paramsToken)) {
        return null;
    }
    String token = StringUtils.isEmpty(paramsToken) ? cookieToken : paramsToken;

    MiaoshaUser user = miaoshaUserService.getMiaoshaUserByToken(token, response);
    return user;
}
 
Example 18
Source Project: SecKillShop   Source File: ValidatorUtil.java    License: MIT License 5 votes vote down vote up
public static boolean isMobile(String mobile) {
    if (StringUtils.isEmpty(mobile)) {
        return false;
    }
    Matcher matcher = p.matcher(mobile);
    return matcher.matches();
}
 
Example 19
Source Project: MicroCommunity   Source File: WechatGatewaySMOImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 文字处理
 *
 * @param fromUserName
 * @param toUserName
 * @param keyword
 * @return
 */
private String textResponseHandler(String fromUserName, String toUserName,
                                   String keyword) {
    if (StringUtils.isEmpty(keyword)) {
        return WechatFactory
                .formatText(toUserName, fromUserName, "未包含任何信息");
    } else {
        String responseStr = keyWordHandler(fromUserName, toUserName,
                keyword);
        return WechatFactory
                .formatText(toUserName, fromUserName, responseStr);
    }
}
 
Example 20
/**
 * 查询未入驻的小区
 *
 * @param pd
 * @return
 */
@Override
public ResponseEntity<String> listNoEnterCommunity(IPageData pd) {
    ResponseEntity<String> responseEntity = null;
    JSONObject _paramObj = JSONObject.parseObject(pd.getReqData());
    //权限校验
    checkUserHasPrivilege(pd, restTemplate, PrivilegeCodeConstant.PRIVILEGE_ENTER_COMMUNITY);
    responseEntity = super.getStoreInfo(pd, restTemplate);
    if (responseEntity.getStatusCode() != HttpStatus.OK) {
        return responseEntity;
    }
    Assert.jsonObjectHaveKey(responseEntity.getBody().toString(), "storeId", "根据用户ID查询商户ID失败,未包含storeId节点");

    String storeId = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeId");
    String storeTypeCd = JSONObject.parseObject(responseEntity.getBody().toString()).getString("storeTypeCd");
    String communityName = !_paramObj.containsKey("communityName") ? "" : _paramObj.getString("communityName");
    //修改用户信息
    if (StringUtils.isEmpty(communityName)) {
        responseEntity = this.callCenterService(restTemplate, pd, "",
                ServiceConstant.SERVICE_API_URL + "/api/query.noEnterCommunity.byMember?"
                        + "memberTypeCd=" + MappingCache.getValue(MappingConstant.DOMAIN_STORE_TYPE_2_COMMUNITY_MEMBER_TYPE, storeTypeCd),
                HttpMethod.GET);
    } else {
        responseEntity = this.callCenterService(restTemplate, pd, "",
                ServiceConstant.SERVICE_API_URL + "/api/query.noEnterCommunity.byMemberAndName?"
                        + "memberTypeCd=" + MappingCache.getValue(MappingConstant.DOMAIN_STORE_TYPE_2_COMMUNITY_MEMBER_TYPE, storeTypeCd)
                        + "&name=" + communityName,
                HttpMethod.GET);
    }

    if (responseEntity.getStatusCode() != HttpStatus.OK) {
        return responseEntity;
    }

    JSONArray tmpCommunitys = JSONObject.parseObject(responseEntity.getBody().toString()).getJSONArray("communitys");
    freshCommunityAttr(tmpCommunitys);
    responseEntity = new ResponseEntity<String>(tmpCommunitys.toJSONString(),
            HttpStatus.OK);
    return responseEntity;
}
 
Example 21
Source Project: tutorials   Source File: ContactInfoValidator.java    License: MIT License 5 votes vote down vote up
@Override
public void initialize(final ContactInfo contactInfo) {
    if (StringUtils.isEmptyOrWhitespace(expressionType)) {
        LOG.error("Contact info type missing!");
    } else {
        pattern = expressionRepository.findById(expressionType).map(ContactInfoExpression::getPattern).orElse("");
    }
}
 
Example 22
Source Project: tutorials   Source File: ContactInfoValidator.java    License: MIT License 5 votes vote down vote up
@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
    if (!StringUtils.isEmptyOrWhitespace(pattern)) {
        return Pattern.matches(pattern, value);
    }
    LOG.error("Contact info pattern missing!");
    return false;
}
 
Example 23
Source Project: thymeleaf-extras-shiro   Source File: ThymeleafFacade.java    License: Apache License 2.0 5 votes vote down vote up
public static List<String> evaluateAsStringsWithDelimiter(ITemplateContext arguments, String rawValue, String delimiter) {
    notNull(arguments, "arguments must not be null");
    notEmpty(rawValue, "rawValue must not be empty");
    notEmpty(delimiter, "delimiter must not be empty");

    final List<String> result = new ArrayList<String>();
    final List<Object> iterates = evaluateAsIterableOrRawValue(arguments, rawValue);

    for (Object o : iterates) {
        result.addAll(asList(StringUtils.split(o, delimiter)));
    }

    return unmodifiableList(result);
}
 
Example 24
Source Project: thymeleaf-extras-shiro   Source File: ShiroFacade.java    License: Apache License 2.0 5 votes vote down vote up
public static boolean hasAnyRoles(final Collection<String> roles) {
    if (SecurityUtils.getSubject() != null) {
        final Subject subject = SecurityUtils.getSubject();
        for (final String role : roles) {
            if (subject.hasRole(StringUtils.trim(role))) {
                return true;
            }
        }
    }
    return false;
}
 
Example 25
Source Project: influx-proxy   Source File: StringToBoolJsonDeserializer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Boolean deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    return StringUtils.equals(p.getValueAsString(),"true");
}
 
Example 26
Source Project: alcor   Source File: RestPreconditions.java    License: Apache License 2.0 4 votes vote down vote up
public static void verifyResourceNotNull(CustomerResource resource) throws ResourceNullException {
    if (resource == null || StringUtils.isEmpty(resource.getId())) {
        throw new ResourceNullException("Empty resource id");
    }
}
 
Example 27
Source Project: alcor   Source File: RestPreconditions.java    License: Apache License 2.0 4 votes vote down vote up
public static void verifyParameterNotNullorEmpty(String resourceId) throws ParameterNullOrEmptyException {
    if (StringUtils.isEmpty(resourceId)) {
        throw new ParameterNullOrEmptyException("Empty parameter");
    }
}
 
Example 28
Source Project: alcor   Source File: RestPreconditions.java    License: Apache License 2.0 4 votes vote down vote up
public static void verifyParameterEqual(String expectedResourceId, String resourceId) throws ParameterUnexpectedValueException {
    if (StringUtils.isEmpty(resourceId) || !resourceId.equalsIgnoreCase(expectedResourceId)) {
        throw new ParameterUnexpectedValueException("Expeceted value: " + expectedResourceId + " | actual: " + resourceId);
    }
}
 
Example 29
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static void verifyResourceNotNull(CustomerResource resource) throws ResourceNullException {
    if (resource == null || StringUtils.isEmpty(resource.getId())) {
        throw new ResourceNullException("Empty resource id");
    }
}
 
Example 30
Source Project: alcor   Source File: RestPreconditionsUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static void verifyParameterNotNullorEmpty(String resourceId) throws ParameterNullOrEmptyException {
    if (StringUtils.isEmpty(resourceId)) {
        throw new ParameterNullOrEmptyException("Empty parameter");
    }
}