All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.beangle.struts2.util.BeangleStaticContentLoader Maven / Gradle / Ivy

There is a newer version: 3.11.3
Show newest version
/*
 * Beangle, Agile Development Scaffold and Toolkits.
 *
 * Copyright © 2005, The Beangle Software.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see .
 */
package org.beangle.struts2.util;

import java.io.IOException;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.apache.struts2.dispatcher.HostConfig;
import org.apache.struts2.dispatcher.StaticContentLoader;
import org.beangle.commons.inject.Containers;
import org.beangle.commons.web.resource.ResourceProcessor;

/**
 * BeangleStaticContentLoader provide serval features
 * 
    *
  • 1 Avoid load resource when get not expired content using ETag
  • *
  • 2 Multi resource in one request
  • *
  • 3 Realy detect resource modify datetime.
  • *
*

* This loader can find content of new version using url's lastmodifed .So different resource path * (rename beagle-3.0.js to beangle-3.1.js,or using beangle-3.0.js?version=m1 etc.) was not * necessary; *

* * @author chaostone * @version $Id: BeangleStaticContentLoader.java Dec 25, 2011 9:19:06 PM chaostone $ */ public class BeangleStaticContentLoader implements StaticContentLoader { private ResourceProcessor processor; /** * Locate a static resource and copy directly to the response, setting the * appropriate caching headers. */ public void findStaticResource(String path, HttpServletRequest request, HttpServletResponse response) throws IOException { processor.process(cleanupPath(path), request, response); } public boolean canHandle(String resourcePath) { return resourcePath.startsWith("/static"); } /** * @param path requested path * @return path without leading "/static" */ protected String cleanupPath(String path) { return path.substring("/static".length()); } /** * Catch struts2 init parameters */ public void setHostConfig(HostConfig filterConfig) { processor = Containers.getRoot().getBean(ResourceProcessor.class).get(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy