/** * Return whether the given resource location is a URL: either a * special "classpath" or "classpath*" pseudo URL or a standard URL. * @param resourceLocation the location String to check * @return whether the location qualifies as a URL * @see ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX * @see org.springframework.util.ResourceUtils#CLASSPATH_URL_PREFIX * @see org.springframework.util.ResourceUtils#isUrl(String) * @see java.net.URL */ public static boolean isUrl(@Nullable String resourceLocation) { return (resourceLocation != null && (resourceLocation.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX) || ResourceUtils.isUrl(resourceLocation))); }
private boolean isInvalidPath(String path) { if (path.contains("WEB-INF") || path.contains("META-INF")) { return true; } if (path.contains(":/")) { String relativePath = (path.charAt(0) == '/' ? path.substring(1) : path); if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) { return true; } } if (path.contains("..") && StringUtils.cleanPath(path).contains("../")) { return true; } return false; }
/** * Return whether the given resource location is a URL: either a * special "classpath" or "classpath*" pseudo URL or a standard URL. * @param resourceLocation the location String to check * @return whether the location qualifies as a URL * @see ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX * @see org.springframework.util.ResourceUtils#CLASSPATH_URL_PREFIX * @see org.springframework.util.ResourceUtils#isUrl(String) * @see java.net.URL */ public static boolean isUrl(@Nullable String resourceLocation) { return (resourceLocation != null && (resourceLocation.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX) || ResourceUtils.isUrl(resourceLocation))); }
private static void assertLocalFunctionNames(String... functions) { for (String function : functions) { if (ResourceUtils.isUrl(function)) { throw new IllegalArgumentException(String.format( "Blocking accessing to resource %s is not allowed using reactive infrastructure. You may load the resource at startup and cache its value.", function)); } } }
if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) { if (logger.isWarnEnabled()) { logger.warn("Path represents URL or has \"url:\" prefix: [" + path + "]");
if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) { if (logger.isWarnEnabled()) { logger.warn("Path represents URL or has \"url:\" prefix: [" + path + "]");
if (!ResourceUtils.isUrl(text)) { file = new File(text); if (file.isAbsolute()) {
if (ResourceUtils.isUrl(relativePath) || relativePath.startsWith("url:")) { if (logger.isWarnEnabled()) { logger.warn("Path represents URL or has \"url:\" prefix: [" + path + "]");
protected String replaceWithResourceIfNecessary(String function) { String func = function; if (this.resourceLoader != null && ResourceUtils.isUrl(function)) { Resource functionResource = resourceLoader.getResource(func); if (!functionResource.exists()) { throw new InvalidDataAccessApiUsageException(String.format("Resource %s not found!", function)); } Scanner scanner = null; try { scanner = new Scanner(functionResource.getInputStream()); return scanner.useDelimiter("\\A").next(); } catch (IOException e) { throw new InvalidDataAccessApiUsageException(String.format("Cannot read map-reduce file %s!", function), e); } finally { if (scanner != null) { scanner.close(); } } } return func; }
private Set<String> getSearchLocations(String propertyName) { Set<String> locations = new LinkedHashSet<>(); if (this.environment.containsProperty(propertyName)) { for (String path : asResolvedSet( this.environment.getProperty(propertyName), null)) { if (!path.contains("$")) { path = StringUtils.cleanPath(path); if (!ResourceUtils.isUrl(path)) { path = ResourceUtils.FILE_URL_PREFIX + path; } } locations.add(path); } } return locations; }
if (!ResourceUtils.isUrl(text)) { file = new File(text); if (file.isAbsolute()) {
private static void assertLocalFunctionNames(String... functions) { for (String function : functions) { if (ResourceUtils.isUrl(function)) { throw new IllegalArgumentException(String.format( "Blocking accessing to resource %s is not allowed using reactive infrastructure. You may load the resource at startup and cache its value.", function)); } } }
/** * Return whether the given resource location is a URL: either a * special "classpath" or "classpath*" pseudo URL or a standard URL. * @param resourceLocation the location String to check * @return whether the location qualifies as a URL * @see ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX * @see org.springframework.util.ResourceUtils#CLASSPATH_URL_PREFIX * @see org.springframework.util.ResourceUtils#isUrl(String) * @see java.net.URL */ public static boolean isUrl(String resourceLocation) { return (resourceLocation != null && (resourceLocation.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX) || ResourceUtils.isUrl(resourceLocation))); }
protected String replaceWithResourceIfNecessary(String function) { String func = function; if (this.resourceLoader != null && ResourceUtils.isUrl(function)) { Resource functionResource = resourceLoader.getResource(func); if (!functionResource.exists()) { throw new InvalidDataAccessApiUsageException(String.format("Resource %s not found!", function)); } Scanner scanner = null; try { scanner = new Scanner(functionResource.getInputStream()); return scanner.useDelimiter("\\A").next(); } catch (IOException e) { throw new InvalidDataAccessApiUsageException(String.format("Cannot read map-reduce file %s!", function), e); } finally { if (scanner != null) { scanner.close(); } } } return func; }
/** * Return whether the given resource location is a URL: either a * special "classpath" or "classpath*" pseudo URL or a standard URL. * @see ResourcePatternResolver#CLASSPATH_URL_PREFIX * @see org.springframework.util.ResourceUtils#CLASSPATH_URL_PREFIX * @see org.springframework.util.ResourceUtils#isUrl(String) * @see java.net.URL */ public static boolean isUrl(String resourceLocation) { if (resourceLocation.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX)) { return true; } return ResourceUtils.isUrl(resourceLocation); }
/** * Return whether the given resource location is a URL: either a * special "classpath" or "classpath*" pseudo URL or a standard URL. * @param resourceLocation the location String to check * @return whether the location qualifies as a URL * @see ResourcePatternResolver#CLASSPATH_ALL_URL_PREFIX * @see org.springframework.util.ResourceUtils#CLASSPATH_URL_PREFIX * @see org.springframework.util.ResourceUtils#isUrl(String) * @see java.net.URL */ public static boolean isUrl(@Nullable String resourceLocation) { return (resourceLocation != null && (resourceLocation.startsWith(ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX) || ResourceUtils.isUrl(resourceLocation))); }
/** * Check the configured url format is valid by using {@code new URI()} */ private void checkConfiguredUrl(RetrofitProperties properties) { properties.getEndpoints().stream() .map(RetrofitProperties.EndPoint::getBaseUrl) .forEach(url -> { Assert.isTrue(ResourceUtils.isUrl(url), url + " is not a valid url"); if (!url.endsWith("/")) { log.warn("The [{}] didn't end with \"/\". This means a relative base url, end with / would be better.", url); } }); } }
private void validateUrl(final String url) { boolean isValid = true; if (url.contains("..")) { isValid = false; } if (isValid) { isValid = ResourceUtils.isUrl(url); } if (!isValid) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.Unknown); sce.getElements().add("Invalid URL: " + url); throw sce; } }
public static Resource resourceFromString(String uri) throws MalformedURLException { Resource resource; File file = new File(uri); if (file.exists()) { resource = new FileSystemResource(uri); } else if (ResourceUtils.isUrl(uri)) { resource = new UrlResource(uri); } else { resource = new ClassPathResource(uri); } return resource; } }