Search in sources :

Example 1 with ResourceChainRegistration

use of org.springframework.web.servlet.config.annotation.ResourceChainRegistration 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)

Aggregations

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 GzipResourceResolver (org.springframework.web.servlet.resource.GzipResourceResolver)1 PathResourceResolver (org.springframework.web.servlet.resource.PathResourceResolver)1 Memory (php.runtime.Memory)1 ArrayMemory (php.runtime.memory.ArrayMemory)1