org.thymeleaf.util.StringUtils Java Examples

The following examples show how to use org.thymeleaf.util.StringUtils. 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
Source File: ShiroFacade.java    From thymeleaf-extras-shiro with 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 #2
Source File: TdsExtensibleTemplateResolver.java    From tds with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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 #3
Source File: WallRideResourceTemplateResource.java    From wallride with 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 File: GoodsController.java    From SecKillShop with 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 #5
Source File: RestPreconditionsUtil.java    From alcor with 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 File: RestPreconditionsUtil.java    From alcor with 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 #7
Source File: RestPreconditionsUtil.java    From alcor with 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 #8
Source File: RestPreconditionsUtil.java    From alcor with 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 #9
Source File: IsMobileValidator.java    From SecKillShop with 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 #10
Source File: MiaoshaUserService.java    From SecKillShop with 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 #11
Source File: UserArgumentResolver.java    From SecKillShop with 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 #12
Source File: ValidatorUtil.java    From SecKillShop with 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 #13
Source File: WechatGatewaySMOImpl.java    From MicroCommunity with 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 #14
Source File: FrontCommunityServiceSMOImpl.java    From MicroCommunity with Apache License 2.0 5 votes vote down vote up
/**
 * 查询未入驻的小区
 *
 * @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 #15
Source File: ContactInfoValidator.java    From tutorials with 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 #16
Source File: ContactInfoValidator.java    From tutorials with 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 #17
Source File: ThymeleafFacade.java    From thymeleaf-extras-shiro with 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 #18
Source File: ShiroFacade.java    From thymeleaf-extras-shiro with 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 #19
Source File: RestPreconditions.java    From alcor with 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 #20
Source File: RestPreconditions.java    From alcor with 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 #21
Source File: RestPreconditionsUtil.java    From alcor with 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 #22
Source File: RestPreconditionsUtil.java    From alcor with 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 #23
Source File: RestPreconditionsUtil.java    From alcor with 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 #24
Source File: RestPreconditionsUtil.java    From alcor with 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 #25
Source File: RestPreconditions.java    From alcor with 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 #26
Source File: RestParameterValidator.java    From alcor with Apache License 2.0 4 votes vote down vote up
public static void checkSecurityGroupRuleId(String securityGroupRuleId) throws SecurityGroupRuleIdRequired {
    if (StringUtils.isEmpty(securityGroupRuleId)) {
        throw new SecurityGroupRuleIdRequired();
    }
}
 
Example #27
Source File: RestPreconditions.java    From alcor with 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 File: RestPreconditions.java    From alcor with 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 File: NameFormatter.java    From tutorials with MIT License 4 votes vote down vote up
private String formatName(String input, Locale locale) {
    return StringUtils.replace(input, " ", ",");
}
 
Example #30
Source File: RestPreconditionsUtil.java    From alcor with 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");
    }
}