org.springframework.util.StringUtils#startsWithIgnoreCase ( )源码实例Demo

下面列出了org.springframework.util.StringUtils#startsWithIgnoreCase ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dts   文件: DtsRemoteInterceptor.java
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws Exception {
    Enumeration<String> headerNames = request.getHeaderNames();
    if (headerNames != null) {
        while (headerNames.hasMoreElements()) {
            String headerName = headerNames.nextElement();
            if (StringUtils.startsWithIgnoreCase(headerName, CONTEXT_HEADER_PARENT)) {
                String value = request.getHeader(headerName);
                String key = StringUtils.replace(headerName, CONTEXT_HEADER_PARENT, "");
                SpringCloudDtsContext.getContext().setAttachment(key.toUpperCase(), value);
            }
        }
    }
    return true;
}
 
源代码2 项目: cerebro   文件: AlarmValidator.java
public void validateAlarm(final Alarm alarm) throws CerebroException {
    // Validate required fields
    if (StringUtils.isEmpty(alarm.getName())) {
        throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm name is required.");
    }

    if (StringUtils.isEmpty(alarm.getTarget()) || StringUtils.startsWithIgnoreCase(alarm.getTarget(), "*")) {
        throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm target is required.");
    }

    if (StringUtils.isEmpty(alarm.getWarn())) {
        throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm warning threshold is required.");
    }

    if (StringUtils.isEmpty(alarm.getError())) {
        throw new CerebroException(ErrorCode.ALARM_INVALID, "Alarm error threshold is required.");
    }
}
 
源代码3 项目: spring-analysis-note   文件: MockCookie.java
/**
 * Factory method that parses the value of a "Set-Cookie" header.
 * @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
 * @return the created cookie
 */
public static MockCookie parse(String setCookieHeader) {
	Assert.notNull(setCookieHeader, "Set-Cookie header must not be null");
	String[] cookieParts = setCookieHeader.split("\\s*=\\s*", 2);
	Assert.isTrue(cookieParts.length == 2, () -> "Invalid Set-Cookie header '" + setCookieHeader + "'");

	String name = cookieParts[0];
	String[] valueAndAttributes = cookieParts[1].split("\\s*;\\s*", 2);
	String value = valueAndAttributes[0];
	String[] attributes =
			(valueAndAttributes.length > 1 ? valueAndAttributes[1].split("\\s*;\\s*") : new String[0]);

	MockCookie cookie = new MockCookie(name, value);
	for (String attribute : attributes) {
		if (StringUtils.startsWithIgnoreCase(attribute, "Domain")) {
			cookie.setDomain(extractAttributeValue(attribute, setCookieHeader));
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "Max-Age")) {
			cookie.setMaxAge(Integer.parseInt(extractAttributeValue(attribute, setCookieHeader)));
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "Path")) {
			cookie.setPath(extractAttributeValue(attribute, setCookieHeader));
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "Secure")) {
			cookie.setSecure(true);
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "HttpOnly")) {
			cookie.setHttpOnly(true);
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "SameSite")) {
			cookie.setSameSite(extractAttributeValue(attribute, setCookieHeader));
		}
	}
	return cookie;
}
 
源代码4 项目: spring-analysis-note   文件: MockCookie.java
/**
 * Factory method that parses the value of a "Set-Cookie" header.
 * @param setCookieHeader the "Set-Cookie" value; never {@code null} or empty
 * @return the created cookie
 */
public static MockCookie parse(String setCookieHeader) {
	Assert.notNull(setCookieHeader, "Set-Cookie header must not be null");
	String[] cookieParts = setCookieHeader.split("\\s*=\\s*", 2);
	Assert.isTrue(cookieParts.length == 2, () -> "Invalid Set-Cookie header '" + setCookieHeader + "'");

	String name = cookieParts[0];
	String[] valueAndAttributes = cookieParts[1].split("\\s*;\\s*", 2);
	String value = valueAndAttributes[0];
	String[] attributes =
			(valueAndAttributes.length > 1 ? valueAndAttributes[1].split("\\s*;\\s*") : new String[0]);

	MockCookie cookie = new MockCookie(name, value);
	for (String attribute : attributes) {
		if (StringUtils.startsWithIgnoreCase(attribute, "Domain")) {
			cookie.setDomain(extractAttributeValue(attribute, setCookieHeader));
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "Max-Age")) {
			cookie.setMaxAge(Integer.parseInt(extractAttributeValue(attribute, setCookieHeader)));
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "Path")) {
			cookie.setPath(extractAttributeValue(attribute, setCookieHeader));
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "Secure")) {
			cookie.setSecure(true);
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "HttpOnly")) {
			cookie.setHttpOnly(true);
		}
		else if (StringUtils.startsWithIgnoreCase(attribute, "SameSite")) {
			cookie.setSameSite(extractAttributeValue(attribute, setCookieHeader));
		}
	}
	return cookie;
}
 
源代码5 项目: halo   文件: CommonController.java
/**
 * Handles custom exception, like HaloException.
 *
 * @param request http servlet request must not be null
 */
private void handleCustomException(@NonNull HttpServletRequest request) {
    Assert.notNull(request, "Http servlet request must not be null");

    Object throwableObject = request.getAttribute("javax.servlet.error.exception");
    if (throwableObject == null) {
        return;
    }

    Throwable throwable = (Throwable) throwableObject;

    if (throwable instanceof NestedServletException) {
        log.error("Captured an exception", throwable);
        Throwable rootCause = ((NestedServletException) throwable).getRootCause();
        if (rootCause instanceof AbstractHaloException) {
            AbstractHaloException haloException = (AbstractHaloException) rootCause;
            request.setAttribute("javax.servlet.error.status_code", haloException.getStatus().value());
            request.setAttribute("javax.servlet.error.exception", rootCause);
            request.setAttribute("javax.servlet.error.message", haloException.getMessage());
        }
    } else if (StringUtils.startsWithIgnoreCase(throwable.getMessage(), COULD_NOT_RESOLVE_VIEW_WITH_NAME_PREFIX)) {
        log.debug("Captured an exception", throwable);
        request.setAttribute("javax.servlet.error.status_code", HttpStatus.NOT_FOUND.value());

        NotFoundException viewNotFound = new NotFoundException("该路径没有对应的模板");
        request.setAttribute("javax.servlet.error.exception", viewNotFound);
        request.setAttribute("javax.servlet.error.message", viewNotFound.getMessage());
    }

}
 
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context,
		AnnotatedTypeMetadata metadata) {
	ConfigurableEnvironment environment = (ConfigurableEnvironment) context
			.getEnvironment();

	String protocol = environment.getProperty("dubbo.registry.protocol");

	if (PROTOCOL.equals(protocol)) {
		return ConditionOutcome.noMatch(
				"'spring-cloud' protocol was found from 'dubbo.registry.protocol'");
	}

	String address = environment.getProperty("dubbo.registry.address");

	if (StringUtils.startsWithIgnoreCase(address, PROTOCOL)) {
		return ConditionOutcome.noMatch(
				"'spring-cloud' protocol was found from 'dubbo.registry.address'");
	}

	Map<String, Object> properties = getSubProperties(
			environment.getPropertySources(), "dubbo.registries.");

	boolean found = properties.entrySet().stream().anyMatch(entry -> {
		String key = entry.getKey();
		String value = String.valueOf(entry.getValue());
		return (key.endsWith(".address") && value.startsWith(PROTOCOL))
				|| (key.endsWith(".protocol") && PROTOCOL.equals(value));

	});

	return found
			? ConditionOutcome.noMatch(
					"'spring-cloud' protocol was found in 'dubbo.registries.*'")
			: ConditionOutcome.match();
}
 
/**
 * Utility method that determines whether the request contains multipart content.
 *
 * @param request
 *     The servlet request to be evaluated. Must be non-null.
 * @return <code>true</code> if the request is multipart; {@code false} otherwise.
 * @see org.apache.commons.fileupload.servlet.ServletFileUpload#isMultipartContent(HttpServletRequest)
 */
public static final boolean isMultipartContent(HttpServletRequest request) {
    final String method = request.getMethod().toLowerCase();
    if (!method.equalsIgnoreCase("post") && !method.equalsIgnoreCase("put")) {
        return false;
    }

    String contentType = request.getContentType();
    return StringUtils.startsWithIgnoreCase(contentType, "multipart/");
}
 
源代码8 项目: citrus-simulator   文件: TemplateHelper.java
/**
 * Gets a classpath file resource from base template package.
 *
 * @param resourcePath      the relative path to the resource, including the resource name
 * @param resourceExtension the resource extension (e.g. '.xml')
 * @return the classpath resource
 */
public Resource getFileResource(String resourcePath, String resourceExtension) {
    String adaptedFileExtension = resourceExtension;
    if (StringUtils.hasLength(resourceExtension) && !StringUtils.startsWithIgnoreCase(resourceExtension, ".")) {
        adaptedFileExtension = "." + resourceExtension;
    }
    return new ClassPathResource(basePath + resourcePath + adaptedFileExtension);
}
 
/**
 * Deletes local branches if corresponding remote branch was removed.
 * @param trackingRefUpdates list of tracking ref updates
 * @param git git instance
 * @return list of deleted branches
 */
private Collection<String> deleteUntrackedLocalBranches(
		Collection<TrackingRefUpdate> trackingRefUpdates, Git git) {
	if (CollectionUtils.isEmpty(trackingRefUpdates)) {
		return Collections.emptyList();
	}

	Collection<String> branchesToDelete = new ArrayList<>();
	for (TrackingRefUpdate trackingRefUpdate : trackingRefUpdates) {
		ReceiveCommand receiveCommand = trackingRefUpdate.asReceiveCommand();
		if (receiveCommand.getType() == DELETE) {
			String localRefName = trackingRefUpdate.getLocalName();
			if (StringUtils.startsWithIgnoreCase(localRefName,
					LOCAL_BRANCH_REF_PREFIX)) {
				String localBranchName = localRefName.substring(
						LOCAL_BRANCH_REF_PREFIX.length(), localRefName.length());
				branchesToDelete.add(localBranchName);
			}
		}
	}

	if (CollectionUtils.isEmpty(branchesToDelete)) {
		return Collections.emptyList();
	}

	try {
		// make sure that deleted branch not a current one
		checkout(git, this.defaultLabel);
		return deleteBranches(git, branchesToDelete);
	}
	catch (Exception ex) {
		String message = format("Failed to delete %s branches.", branchesToDelete);
		warn(message, ex);
		return Collections.emptyList();
	}
}
 
@Override
public boolean isMultipart(HttpServletRequest request) {
	return StringUtils.startsWithIgnoreCase(request.getContentType(), "multipart/");
}
 
/**
 * Check if the request is a multipart request (by checking its Content-Type header).
 * @param request request with parameters to bind
 */
private boolean isMultipartRequest(WebRequest request) {
	String contentType = request.getHeader("Content-Type");
	return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
}
 
@Override
public boolean isMultipart(HttpServletRequest request) {
	return StringUtils.startsWithIgnoreCase(request.getContentType(), "multipart/");
}
 
/**
 * Check if the request is a multipart request (by checking its Content-Type header).
 * @param request request with parameters to bind
 */
private boolean isMultipartRequest(WebRequest request) {
	String contentType = request.getHeader("Content-Type");
	return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
}
 
源代码14 项目: lams   文件: WebRequestDataBinder.java
/**
 * Check if the request is a multipart request (by checking its Content-Type header).
 * @param request request with parameters to bind
 */
private boolean isMultipartRequest(WebRequest request) {
	String contentType = request.getHeader("Content-Type");
	return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
}
 
/**
 * Check if the request is a multipart request (by checking its Content-Type header).
 * @param request request with parameters to bind
 */
private boolean isMultipartRequest(WebRequest request) {
	String contentType = request.getHeader("Content-Type");
	return (contentType != null && StringUtils.startsWithIgnoreCase(contentType, "multipart"));
}
 
源代码16 项目: spring4-understanding   文件: PortletUtils.java
/**
 * Check whether the specified path indicates a resource in the protected
 * WEB-INF or META-INF directories.
 * @param path the path to check
 */
private static boolean isProtectedResource(String path) {
	return (StringUtils.startsWithIgnoreCase(path, "/WEB-INF") ||
			StringUtils.startsWithIgnoreCase(path, "/META-INF"));
}
 
源代码17 项目: beetl2.0   文件: UtilsFunctionPackage.java
/**
 * 无视大小写的startsWith判断
 *
 * @param input
 *            测试文本
 * @param prefix
 *            指定前缀
 * @return 无视大小写的startsWith判断
 */
public boolean startsWithIgnoreCase(String input, String prefix) {
	return StringUtils.startsWithIgnoreCase(input, prefix);
}