Java Code Examples for cn.hutool.core.util.StrUtil#containsIgnoreCase()

The following examples show how to use cn.hutool.core.util.StrUtil#containsIgnoreCase() . 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: PreviewFilter.java    From spring-microservice-exam with MIT License 5 votes vote down vote up
/**
 * 是否拦截
 *
 * @param request request
 * @return boolean
 * @author tangyi
 * @date 2019/06/19 20:06
 */
private boolean shouldFilter(ServerHttpRequest request) {
	// enabled不为true
	Map<String, String> previewConfigMap = LoadingCacheHelper.getInstance().get(PreviewConfigLoader.class, PreviewConfigLoader.PREVIEW_ENABLE);
	if (previewConfigMap == null || previewConfigMap.isEmpty() || !previewConfigMap.containsKey(PreviewConfigLoader.PREVIEW_ENABLE)) {
		return true;
	}
	// 演示环境下,只拦截对默认租户的修改操作
	if ("true".equals(previewConfigMap.get(PreviewConfigLoader.PREVIEW_ENABLE)) && GatewayConstant.DEFAULT_TENANT_CODE
			.equals(request.getHeaders().getFirst(GatewayConstant.TENANT_CODE_HEADER))) {
		String method = request.getMethodValue(), uri = request.getURI().getPath();
		// GET请求、POST请求
		if (StrUtil.equalsIgnoreCase(method, HttpMethod.GET.name()))
			return false;
		if (StrUtil.equalsIgnoreCase(method, HttpMethod.POST.name()) && !StrUtil.containsIgnoreCase(uri, "delete")
				&& !StrUtil.containsIgnoreCase(uri, "menu"))
			return false;
		// 拦截DELETE请求
		if (StrUtil.equalsIgnoreCase(method, HttpMethod.DELETE.name()) && !StrUtil
				.containsIgnoreCase(uri, "attachment"))
			return true;
		// 不能修改路由
		if (StrUtil.containsIgnoreCase(uri, "/route/") && (
				StrUtil.equalsIgnoreCase(method, HttpMethod.DELETE.name()) || StrUtil
						.equalsIgnoreCase(method, HttpMethod.PUT.name()) || StrUtil
						.equalsIgnoreCase(method, HttpMethod.POST.name())))
			return true;
		// URL白名单
		return !isIgnore(uri);
	}
	return false;
}
 
Example 2
Source File: PreviewFilter.java    From spring-microservice-exam with MIT License 5 votes vote down vote up
/**
 * 是否忽略URI
 *
 * @param uri uri
 * @return boolean
 * @author tangyi
 * @date 2019/04/23 13:44
 */
private boolean isIgnore(String uri) {
	List<String> ignoreUrls = previewConfig.getIgnores();
	if (ignoreUrls != null && !ignoreUrls.isEmpty()) {
		for (String ignoreUrl : ignoreUrls) {
			if (StrUtil.containsIgnoreCase(uri, ignoreUrl))
				return true;
		}
	}
	return false;
}
 
Example 3
Source File: LinuxSystemCommander.java    From Jpom with MIT License 5 votes vote down vote up
@Override
public boolean getServiceStatus(String serviceName) {
    if (StrUtil.startWith(serviceName, StrUtil.SLASH)) {
        String ps = getPs(serviceName);
        return StrUtil.isNotEmpty(ps);
    }
    String format = StrUtil.format("service {} status", serviceName);
    String result = CommandUtil.execSystemCommand(format);
    return StrUtil.containsIgnoreCase(result, "RUNNING");
}
 
Example 4
Source File: LoginLogServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
private static String simplifyOperatingSystem(String operatingSystem) {
    for (String b : OPERATING_SYSTEM) {
        if (StrUtil.containsIgnoreCase(operatingSystem, b)) {
            return b;
        }
    }
    return operatingSystem;
}
 
Example 5
Source File: LoginLogServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 5 votes vote down vote up
private static String simplifyBrowser(String browser) {
    for (String b : BROWSER) {
        if (StrUtil.containsIgnoreCase(browser, b)) {
            return b;
        }
    }
    return browser;
}
 
Example 6
Source File: ZFileCache.java    From zfile with MIT License 5 votes vote down vote up
/**
 * 指定驱动器, 根据文件及文件名查找相关的文件
 *
 * @param   driveId
 *          驱动器 ID
 *
 * @param   key
 *          搜索键, 可匹配文件夹名称和文件名称.
 *
 * @return  搜索结果, 包含文件夹和文件.
 */
public List<FileItemDTO> find(Integer driveId, String key) {
    List<FileItemDTO> result = new ArrayList<>();

    DriveConfig driveConfig = driverConfigRepository.getOne(driveId);
    boolean searchContainEncryptedFile = driveConfig.getSearchContainEncryptedFile();
    boolean ignoreCase = driveConfig.getSearchIgnoreCase();

    for (List<FileItemDTO> fileItemList : getCacheByDriveId(driveId)) {
        // 过滤加密文件
        if (!searchContainEncryptedFile && isEncryptedFolder(fileItemList)) {
            continue;
        }

        for (FileItemDTO fileItemDTO : fileItemList) {
            boolean testResult;

            // 根据是否需要忽略大小写来匹配文件(夹)名
            if (ignoreCase) {
                testResult = StrUtil.containsIgnoreCase(fileItemDTO.getName(), key);
            } else {
                testResult = fileItemDTO.getName().contains(key);
            }

            if (testResult) {
                result.add(fileItemDTO);
            }
        }
    }
    return result;
}
 
Example 7
Source File: LoginLogServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
private static String simplifyOperatingSystem(String operatingSystem) {
    for (String b : OPERATING_SYSTEM) {
        if (StrUtil.containsIgnoreCase(operatingSystem, b)) {
            return b;
        }
    }
    return operatingSystem;
}
 
Example 8
Source File: LoginLogServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 5 votes vote down vote up
private static String simplifyBrowser(String browser) {
    for (String b : BROWSER) {
        if (StrUtil.containsIgnoreCase(browser, b)) {
            return b;
        }
    }
    return browser;
}
 
Example 9
Source File: WindowsSystemCommander.java    From Jpom with MIT License 4 votes vote down vote up
@Override
public boolean getServiceStatus(String serviceName) {
    String result = CommandUtil.execSystemCommand("sc query " + serviceName);
    return StrUtil.containsIgnoreCase(result, "RUNNING");
}