Search in sources :

Example 1 with GzipResourceResolver

use of org.springframework.web.servlet.resource.GzipResourceResolver in project jphp by jphp-compiler.

the class PWebServer method _makeHandlers.

protected WebServerConfig.Handlers _makeHandlers() {
    return new WebServerConfig.Handlers() {

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            for (ArrayMemory handler : staticHandlers) {
                Memory path = handler.valueOfIndex("path");
                ResourceHandlerRegistration registration;
                if (path.isArray()) {
                    registration = registry.addResourceHandler(path.toValue(ArrayMemory.class).toStringArray());
                } else {
                    registration = registry.addResourceHandler(path.toString());
                }
                Memory cachePeriod = handler.valueOfIndex("cachePeriod");
                registration.setCachePeriod(cachePeriod.isNull() ? null : cachePeriod.toInteger());
                Memory location = handler.valueOfIndex("location");
                if (location.isArray()) {
                    registration.addResourceLocations(location.toValue(ArrayMemory.class).toStringArray());
                } else {
                    registration.addResourceLocations(location.toString());
                }
                ResourceChainRegistration chain = registration.resourceChain(handler.valueOfIndex("cache").toBoolean());
                if (handler.valueOfIndex("gzip").toBoolean()) {
                    chain.addResolver(new GzipResourceResolver());
                }
                chain.addResolver(new PathResourceResolver());
            }
        }
    };
}
Also used : ArrayMemory(php.runtime.memory.ArrayMemory) PathResourceResolver(org.springframework.web.servlet.resource.PathResourceResolver) ResourceHandlerRegistration(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration) Memory(php.runtime.Memory) ArrayMemory(php.runtime.memory.ArrayMemory) GzipResourceResolver(org.springframework.web.servlet.resource.GzipResourceResolver) ResourceHandlerRegistry(org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry) ResourceChainRegistration(org.springframework.web.servlet.config.annotation.ResourceChainRegistration)

Example 2 with GzipResourceResolver

use of org.springframework.web.servlet.resource.GzipResourceResolver in project tutorials by eugenp.

the class MvcConfig method addResourceHandlers.

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    // For examples using Spring 4.1.0
    if ((env.getProperty("resource.handler.conf")).equals("4.1.0")) {
        registry.addResourceHandler("/js/**").addResourceLocations("/js/").setCachePeriod(3600).resourceChain(true).addResolver(new GzipResourceResolver()).addResolver(new PathResourceResolver());
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/", "classpath:/other-resources/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());
        registry.addResourceHandler("/files/**").addResourceLocations("file:/Users/Elena/").setCachePeriod(3600).resourceChain(true).addResolver(new PathResourceResolver());
        registry.addResourceHandler("/other-files/**").addResourceLocations("file:/Users/Elena/").setCachePeriod(3600).resourceChain(true).addResolver(new GzipResourceResolver());
    } else // For examples using Spring 4.0.7
    if ((env.getProperty("resource.handler.conf")).equals("4.0.7")) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/", "/resources/", "classpath:/other-resources/");
        registry.addResourceHandler("/files/**").addResourceLocations("file:/Users/Elena/");
    }
}
Also used : PathResourceResolver(org.springframework.web.servlet.resource.PathResourceResolver) GzipResourceResolver(org.springframework.web.servlet.resource.GzipResourceResolver)

Aggregations

GzipResourceResolver (org.springframework.web.servlet.resource.GzipResourceResolver)2 PathResourceResolver (org.springframework.web.servlet.resource.PathResourceResolver)2 ResourceChainRegistration (org.springframework.web.servlet.config.annotation.ResourceChainRegistration)1 ResourceHandlerRegistration (org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration)1 ResourceHandlerRegistry (org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry)1 Memory (php.runtime.Memory)1 ArrayMemory (php.runtime.memory.ArrayMemory)1