/*************************************************************** * This file is part of the [fleXive](R) framework. * * Copyright (c) 1999-2010 * UCS - unique computing solutions gmbh (http://www.ucs.at) * All rights reserved * * The [fleXive](R) project is free software; you can redistribute * it and/or modify it under the terms of the GNU Lesser General Public * License version 2.1 or higher as published by the Free Software Foundation. * * The GNU Lesser General Public License can be found at * http://www.gnu.org/licenses/lgpl.html. * A copy is found in the textfile LGPL.txt and important notices to the * license from the author are found in LICENSE.txt distributed with * these libraries. * * This library 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 General Public License for more details. * * For further information about UCS - unique computing solutions gmbh, * please see the company website: http://www.ucs.at * * For further information about [fleXive](R), please see the * project website: http://www.flexive.org * * * This copyright notice MUST APPEAR in all copies of the file! ***************************************************************/ package com.flexive.cms.war.servlets; import com.flexive.cms.shared.CMSUtils; import com.flexive.cms.war.CmsRequestUtils; import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.Log; import javax.servlet.*; import java.io.IOException; /** * Wrapper for the flexive DownloadServlet to serve files from the CMS /files folder. * * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at) * @version $Rev: 55 $ */ public class FileDownloadServlet implements Servlet { private static final Log LOG = LogFactory.getLog(FileDownloadServlet.class); private static final String BASE_URL = "/__cmsdownload"; private ServletConfig config; public void init(ServletConfig config) throws ServletException { this.config = config; } public ServletConfig getServletConfig() { return config; } public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { final String requestedPath = CmsRequestUtils.getRequestedURI(req).replace(BASE_URL, ""); final String treeMode = CmsRequestUtils.isEditTemplatesRequest(req) ? "edit" : "live"; final String path = "/download/tree/" + treeMode + CMSUtils.getTreeRoot() + requestedPath + "?inline=true"; if (LOG.isDebugEnabled()) { LOG.debug("CMS download servlet: forwarding to " + path); } req.getRequestDispatcher(path).forward(req, res); } public String getServletInfo() { return "FileDownloadServlet"; } public void destroy() { } }