当前位置: 首页>>代码示例>>Java>>正文


Java ResourceTransformer类代码示例

本文整理汇总了Java中org.springframework.web.servlet.resource.ResourceTransformer的典型用法代码示例。如果您正苦于以下问题:Java ResourceTransformer类的具体用法?Java ResourceTransformer怎么用?Java ResourceTransformer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ResourceTransformer类属于org.springframework.web.servlet.resource包,在下文中一共展示了ResourceTransformer类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resourceChain

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
@Test
public void resourceChain() throws Exception {
	ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
	ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
	this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:ResourceHandlerRegistryTests.java

示例2: resourceChainWithVersionResolver

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
@Test
public void resourceChainWithVersionResolver() throws Exception {
	VersionResourceResolver versionResolver = new VersionResourceResolver()
			.addFixedVersionStrategy("fixed", "/**/*.js")
			.addContentVersionStrategy("/**");

	this.registration.resourceChain(true).addResolver(versionResolver)
			.addTransformer(new AppCacheManifestTransformer());

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(3));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
	assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:ResourceHandlerRegistryTests.java

示例3: addTransformer

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
/**
 * Add a resource transformer to the chain.
 * @param transformer the transformer to add
 * @return the current instance for chained method invocation
 */
public ResourceChainRegistration addTransformer(ResourceTransformer transformer) {
	Assert.notNull(transformer, "The provided ResourceTransformer should not be null");
	this.transformers.add(transformer);
	if (transformer instanceof CssLinkResourceTransformer) {
		this.hasCssLinkTransformer = true;
	}
	return this;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ResourceChainRegistration.java

示例4: getResourceTransformers

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
protected List<ResourceTransformer> getResourceTransformers() {
	if (this.hasVersionResolver  && !this.hasCssLinkTransformer) {
		List<ResourceTransformer> result = new ArrayList<ResourceTransformer>(this.transformers);
		boolean hasTransformers = !this.transformers.isEmpty();
		boolean hasCaching = hasTransformers && this.transformers.get(0) instanceof CachingResourceTransformer;
		result.add(hasCaching ? 1 : 0, new CssLinkResourceTransformer());
		return result;
	}
	return this.transformers;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:ResourceChainRegistration.java

示例5: testResourcesWithResolversTransformers

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
@Test
public void testResourcesWithResolversTransformers() throws Exception {
	loadBeanDefinitions("mvc-config-resources-chain.xml", 11);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertNotNull(mapping.getUrlMap().get("/resources/**"));
	ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"),
			ResourceHttpRequestHandler.class);
	assertNotNull(handler);

	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers, Matchers.hasSize(4));
	assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
	assertThat(resolvers.get(1), Matchers.instanceOf(VersionResourceResolver.class));
	assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));

	CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
	assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertEquals("test-resource-cache", cachingResolver.getCache().getName());

	VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(1);
	assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
			Matchers.instanceOf(FixedVersionStrategy.class));
	assertThat(versionResolver.getStrategyMap().get("/**"),
			Matchers.instanceOf(ContentVersionStrategy.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(3));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
	assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));

	CachingResourceTransformer cachingTransformer = (CachingResourceTransformer) transformers.get(0);
	assertThat(cachingTransformer.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
	assertEquals("test-resource-cache", cachingTransformer.getCache().getName());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:MvcNamespaceTests.java

示例6: testResourcesWithResolversTransformersCustom

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
@Test
public void testResourcesWithResolversTransformersCustom() throws Exception {
	loadBeanDefinitions("mvc-config-resources-chain-no-auto.xml", 12);

	SimpleUrlHandlerMapping mapping = appContext.getBean(SimpleUrlHandlerMapping.class);
	assertNotNull(mapping);
	assertNotNull(mapping.getUrlMap().get("/resources/**"));
	ResourceHttpRequestHandler handler = appContext.getBean((String) mapping.getUrlMap().get("/resources/**"),
			ResourceHttpRequestHandler.class);
	assertNotNull(handler);

	assertThat(handler.getCacheControl().getHeaderValue(),
			Matchers.equalTo(CacheControl.maxAge(1, TimeUnit.HOURS)
					.sMaxAge(30, TimeUnit.MINUTES).cachePublic().getHeaderValue()));

	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers, Matchers.hasSize(3));
	assertThat(resolvers.get(0), Matchers.instanceOf(VersionResourceResolver.class));
	assertThat(resolvers.get(1), Matchers.instanceOf(GzipResourceResolver.class));
	assertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.class));

	VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(0);
	assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
			Matchers.instanceOf(FixedVersionStrategy.class));
	assertThat(versionResolver.getStrategyMap().get("/**"),
			Matchers.instanceOf(ContentVersionStrategy.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(2));
	assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
	assertThat(transformers.get(1), Matchers.instanceOf(AppCacheManifestTransformer.class));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:33,代码来源:MvcNamespaceTests.java

示例7: resourceChainWithoutCaching

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
@Test
public void resourceChainWithoutCaching() throws Exception {
	this.registration.resourceChain(false);

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers, Matchers.hasSize(2));
	assertThat(resolvers.get(0), Matchers.instanceOf(WebJarsResourceResolver.class));
	assertThat(resolvers.get(1), Matchers.instanceOf(PathResourceResolver.class));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(0));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ResourceHandlerRegistryTests.java

示例8: resourceChainWithOverrides

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
@Test
public void resourceChainWithOverrides() throws Exception {
	CachingResourceResolver cachingResolver = Mockito.mock(CachingResourceResolver.class);
	VersionResourceResolver versionResolver = Mockito.mock(VersionResourceResolver.class);
	PathResourceResolver pathResourceResolver = new PathResourceResolver();
	CachingResourceTransformer cachingTransformer = Mockito.mock(CachingResourceTransformer.class);
	AppCacheManifestTransformer appCacheTransformer = Mockito.mock(AppCacheManifestTransformer.class);
	CssLinkResourceTransformer cssLinkTransformer = new CssLinkResourceTransformer();

	this.registration.setCachePeriod(3600)
			.resourceChain(false)
				.addResolver(cachingResolver)
				.addResolver(versionResolver)
				.addResolver(pathResourceResolver)
				.addTransformer(cachingTransformer)
				.addTransformer(appCacheTransformer)
				.addTransformer(cssLinkTransformer);

	ResourceHttpRequestHandler handler = getHandler("/resources/**");
	List<ResourceResolver> resolvers = handler.getResourceResolvers();
	assertThat(resolvers.toString(), resolvers, Matchers.hasSize(3));
	assertThat(resolvers.get(0), Matchers.sameInstance(cachingResolver));
	assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver));
	assertThat(resolvers.get(2), Matchers.sameInstance(pathResourceResolver));

	List<ResourceTransformer> transformers = handler.getResourceTransformers();
	assertThat(transformers, Matchers.hasSize(3));
	assertThat(transformers.get(0), Matchers.sameInstance(cachingTransformer));
	assertThat(transformers.get(1), Matchers.sameInstance(appCacheTransformer));
	assertThat(transformers.get(2), Matchers.sameInstance(cssLinkTransformer));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:ResourceHandlerRegistryTests.java

示例9: getResourceTransformers

import org.springframework.web.servlet.resource.ResourceTransformer; //导入依赖的package包/类
protected List<ResourceTransformer> getResourceTransformers(String mapping) {
	SimpleUrlHandlerMapping handler = (SimpleUrlHandlerMapping) this.context
			.getBean("resourceHandlerMapping");
	ResourceHttpRequestHandler resourceHandler = (ResourceHttpRequestHandler) handler
			.getHandlerMap().get(mapping);
	return resourceHandler.getResourceTransformers();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:WebMvcAutoConfigurationTests.java


注:本文中的org.springframework.web.servlet.resource.ResourceTransformer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。