當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceUtils.CLASSPATH_URL_PREFIX屬性代碼示例

本文整理匯總了Java中org.springframework.util.ResourceUtils.CLASSPATH_URL_PREFIX屬性的典型用法代碼示例。如果您正苦於以下問題:Java ResourceUtils.CLASSPATH_URL_PREFIX屬性的具體用法?Java ResourceUtils.CLASSPATH_URL_PREFIX怎麽用?Java ResourceUtils.CLASSPATH_URL_PREFIX使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.springframework.util.ResourceUtils的用法示例。


在下文中一共展示了ResourceUtils.CLASSPATH_URL_PREFIX屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConfigLocations

/**
 * Subclasses can override this method to return the locations of their
 * config files.
 * <p>A plain path will be treated as class path location, e.g.:
 * "org/springframework/whatever/foo.xml". Note however that you may prefix
 * path locations with standard Spring resource prefixes. Therefore, a
 * config location path prefixed with "classpath:" with behave the same as a
 * plain path, but a config location such as
 * "file:/some/path/path/location/appContext.xml" will be treated as a
 * filesystem location.
 * <p>The default implementation builds config locations for the config paths
 * specified through {@link #getConfigPaths()}.
 * @return an array of config locations
 * @see #getConfigPaths()
 * @see org.springframework.core.io.ResourceLoader#getResource(String)
 */
protected final String[] getConfigLocations() {
	String[] paths = getConfigPaths();
	String[] convertedPaths = new String[paths.length];
	for (int i = 0; i < paths.length; i++) {
		String path = paths[i];
		if (path.startsWith(SLASH)) {
			convertedPaths[i] = ResourceUtils.CLASSPATH_URL_PREFIX + path;
		}
		else if (!ResourcePatternUtils.isUrl(path)) {
			convertedPaths[i] = ResourceUtils.CLASSPATH_URL_PREFIX + SLASH
					+ StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(getClass()) + SLASH + path);
		}
		else {
			convertedPaths[i] = StringUtils.cleanPath(path);
		}
	}
	return convertedPaths;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:AbstractSingleSpringContextTests.java

示例2: detectDefaultPropertiesFile

/**
 * Detect a default properties file for the supplied class, as specified
 * in the class-level Javadoc for {@link TestPropertySource}.
 */
private static String detectDefaultPropertiesFile(Class<?> testClass) {
	String resourcePath = ClassUtils.convertClassNameToResourcePath(testClass.getName()) + ".properties";
	String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
	ClassPathResource classPathResource = new ClassPathResource(resourcePath);

	if (classPathResource.exists()) {
		if (logger.isInfoEnabled()) {
			logger.info(String.format("Detected default properties file \"%s\" for test class [%s]",
				prefixedResourcePath, testClass.getName()));
		}
		return prefixedResourcePath;
	}
	else {
		String msg = String.format("Could not detect default properties file for test [%s]: "
				+ "%s does not exist. Either declare the 'locations' or 'properties' attributes "
				+ "of @TestPropertySource or make the default properties file available.", testClass.getName(),
			classPathResource);
		logger.error(msg);
		throw new IllegalStateException(msg);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:TestPropertySourceAttributes.java

示例3: detectDefaultScript

/**
 * Detect a default SQL script by implementing the algorithm defined in
 * {@link Sql#scripts}.
 */
private String detectDefaultScript(TestContext testContext, boolean classLevel) {
	Class<?> clazz = testContext.getTestClass();
	Method method = testContext.getTestMethod();
	String elementType = (classLevel ? "class" : "method");
	String elementName = (classLevel ? clazz.getName() : method.toString());

	String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName());
	if (!classLevel) {
		resourcePath += "." + method.getName();
	}
	resourcePath += ".sql";

	String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
	ClassPathResource classPathResource = new ClassPathResource(resourcePath);

	if (classPathResource.exists()) {
		if (logger.isInfoEnabled()) {
			logger.info(String.format("Detected default SQL script \"%s\" for test %s [%s]", prefixedResourcePath,
				elementType, elementName));
		}
		return prefixedResourcePath;
	}
	else {
		String msg = String.format("Could not detect default SQL script for test %s [%s]: "
				+ "%s does not exist. Either declare statements or scripts via @Sql or make the "
				+ "default SQL script available.", elementType, elementName, classPathResource);
		logger.error(msg);
		throw new IllegalStateException(msg);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:34,代碼來源:SqlScriptsTestExecutionListener.java

示例4: generateDefaultLocations

/**
 * Generate the default classpath resource locations array based on the
 * supplied class.
 *
 * <p>For example, if the supplied class is {@code com.example.MyTest},
 * the generated locations will contain a single string with a value of
 * {@code "classpath:com/example/MyTest<suffix>"}, where {@code <suffix>}
 * is the value of the first configured
 * {@linkplain #getResourceSuffixes() resource suffix} for which the
 * generated location actually exists in the classpath.
 *
 * <p>As of Spring 3.1, the implementation of this method adheres to the
 * contract defined in the {@link SmartContextLoader} SPI. Specifically,
 * this method will <em>preemptively</em> verify that the generated default
 * location actually exists. If it does not exist, this method will log a
 * warning and return an empty array.
 *
 * <p>Subclasses can override this method to implement a different
 * <em>default location generation</em> strategy.
 *
 * @param clazz the class for which the default locations are to be generated
 * @return an array of default application context resource locations
 * @since 2.5
 * @see #getResourceSuffixes()
 */
protected String[] generateDefaultLocations(Class<?> clazz) {
	Assert.notNull(clazz, "Class must not be null");

	String[] suffixes = getResourceSuffixes();
	for (String suffix : suffixes) {
		Assert.hasText(suffix, "Resource suffix must not be empty");
		String resourcePath = ClassUtils.convertClassNameToResourcePath(clazz.getName()) + suffix;
		String prefixedResourcePath = ResourceUtils.CLASSPATH_URL_PREFIX + resourcePath;
		ClassPathResource classPathResource = new ClassPathResource(resourcePath);

		if (classPathResource.exists()) {
			if (logger.isInfoEnabled()) {
				logger.info(String.format("Detected default resource location \"%s\" for test class [%s]",
					prefixedResourcePath, clazz.getName()));
			}
			return new String[] { prefixedResourcePath };
		}
		else if (logger.isDebugEnabled()) {
			logger.debug(String.format("Did not detect default resource location for test class [%s]: "
					+ "%s does not exist", clazz.getName(), classPathResource));
		}
	}

	if (logger.isInfoEnabled()) {
		logger.info(String.format("Could not detect default resource locations for test class [%s]: "
				+ "no resource found for suffixes %s.", clazz.getName(), ObjectUtils.nullSafeToString(suffixes)));
	}

	return EMPTY_STRING_ARRAY;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:55,代碼來源:AbstractContextLoader.java

示例5: getConfigLocations

/**
 * Subclasses can override this method to return the locations of their
 * config files, unless they override {@link #contextKey()} and
 * {@link #loadContext(Object)} instead.
 * <p>A plain path will be treated as class path location, e.g.:
 * "org/springframework/whatever/foo.xml". Note however that you may prefix
 * path locations with standard Spring resource prefixes. Therefore, a
 * config location path prefixed with "classpath:" with behave the same as a
 * plain path, but a config location such as
 * "file:/some/path/path/location/appContext.xml" will be treated as a
 * filesystem location.
 * <p>The default implementation builds config locations for the config paths
 * specified through {@link #getConfigPaths()}.
 * @return an array of config locations
 * @see #getConfigPaths()
 * @see org.springframework.core.io.ResourceLoader#getResource(String)
 */
protected String[] getConfigLocations() {
	String[] paths = getConfigPaths();
	String[] locations = new String[paths.length];
	for (int i = 0; i < paths.length; i++) {
		String path = paths[i];
		if (path.startsWith("/")) {
			locations[i] = ResourceUtils.CLASSPATH_URL_PREFIX + path;
		}
		else {
			locations[i] = ResourceUtils.CLASSPATH_URL_PREFIX +
					StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(getClass()) + "/" + path);
		}
	}
	return locations;
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:32,代碼來源:AbstractSingleSpringContextTests.java

示例6: convertToClasspathResourcePaths

/**
 * Convert the supplied paths to classpath resource paths.
 *
 * <p>For each of the supplied paths:
 * <ul>
 * <li>A plain path &mdash; for example, {@code "context.xml"} &mdash; will
 * be treated as a classpath resource that is relative to the package in
 * which the specified class is defined.
 * <li>A path starting with a slash will be treated as an absolute path
 * within the classpath, for example: {@code "/org/example/schema.sql"}.
 * <li>A path which is prefixed with a URL protocol (e.g.,
 * {@link ResourceUtils#CLASSPATH_URL_PREFIX classpath:},
 * {@link ResourceUtils#FILE_URL_PREFIX file:}, {@code http:}, etc.) will be
 * {@link StringUtils#cleanPath cleaned} but otherwise unmodified.
 *
 * @param clazz the class with which the paths are associated
 * @param paths the paths to be converted
 * @return a new array of converted resource paths
 * @see #convertToResources
 */
public static String[] convertToClasspathResourcePaths(Class<?> clazz, String... paths) {
	String[] convertedPaths = new String[paths.length];
	for (int i = 0; i < paths.length; i++) {
		String path = paths[i];
		if (path.startsWith(SLASH)) {
			convertedPaths[i] = ResourceUtils.CLASSPATH_URL_PREFIX + path;
		}
		else if (!ResourcePatternUtils.isUrl(path)) {
			convertedPaths[i] = ResourceUtils.CLASSPATH_URL_PREFIX + SLASH
					+ StringUtils.cleanPath(ClassUtils.classPackageAsResourcePath(clazz) + SLASH + path);
		}
		else {
			convertedPaths[i] = StringUtils.cleanPath(path);
		}
	}
	return convertedPaths;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:37,代碼來源:TestContextResourceUtils.java


注:本文中的org.springframework.util.ResourceUtils.CLASSPATH_URL_PREFIX屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。