<commit_before>/*
 * File   : $Source: /alkacon/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/rfsfile/Attic/CmsRfsFileDownloadServlet.java,v $
 * Date   : $Date: 2005/06/25 15:40:57 $
 * Version: $Revision: 1.7 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace.tools.workplace.rfsfile;

import org.opencms.flex.CmsFlexController;
import org.opencms.util.CmsStringUtil;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Helper <code>Servlet</code> that reads the 
 * <b>request parameter <i>fileName</i></b> for a valid RFS file name and 
 * pushes this file to the client browser where it triggers a download 
 * (popup-box with save dialog). <p>
 * 
 * @author  <NAME> 
 * 
 * @version $Revision: 1.7 $ 
 * 
 * @since 6.0.0 
 */
public final class CmsRfsFileDownloadServlet extends HttpServlet {

    /**
     * Default constructor for this stateless class. 
     */
    public CmsRfsFileDownloadServlet() {

        // nop
    }

    /**
     * Forwards the call to <code>{@link #doPost(HttpServletRequest, HttpServletResponse)}</code>.<p>
     * 
     * @param request Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                by the implicit jsp variable "request"
     * @param response Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                 by the implicit jsp variable "response"
     * 
     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     * @throws ServletException if the needed parameter 'filePath' cannot be found
     * @throws IOException if work related to the download process fails
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        doPost(request, response);
    }

    /**
     * Pushes a file that has been specified by request parameter 
     * <em>"filePath"</em> to the client browser.<p> 
     * 
     * The browser will open a popup menu that offers a donwload even if the 
     * file type is known to the client's OS.<p>
     * 
     * Note that the <b>parameter "filePath"</b> is read from the 
     * given <code>{@link HttpServletRequest}</code> for the file name to serve.<p>
     * 
     * @param req Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                by the implicit jsp variable "request"
     * 
     * @param res Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                 by the implicit jsp variable "response"
     * 
     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     * 
     * @throws ServletException if the needed parameter 'filePath' cannot be found
     * @throws IOException if work related to the download process fails
     */
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

        // find the file: 
        String fileToFind = req.getParameter("filePath");
        if (CmsStringUtil.isEmpty(fileToFind)) {
            throw new ServletException(Messages.get().key(Messages.ERR_DOWNLOAD_SERVLET_FILE_ARG_0));
        } else {

            File downloadFile = new File(fileToFind);
            res.setHeader("Content-Disposition", new StringBuffer("attachment; filename=\"").append(
                downloadFile.getName()).append("\"").toString());
            res.setContentLength((int)downloadFile.length());

            CmsFlexController controller = CmsFlexController.getController(req);
            res = controller.getTopResponse();
            res.setContentType("application/download");

            InputStream in = null;

            // push the file:
            ServletOutputStream outStream = null;<commit_msg>Undefined RFC 1252 http header content-type subtype misleading the browsers download box file-type message.<commit_after>/*
 * File   : $Source: /alkacon/cvs/opencms/src-modules/org/opencms/workplace/tools/workplace/rfsfile/Attic/CmsRfsFileDownloadServlet.java,v $
 * Date   : $Date: 2005/06/25 16:51:07 $
 * Version: $Revision: 1.8 $
 *
 * This library is part of OpenCms -
 * the Open Source Content Mananagement System
 *
 * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
 *
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * For further information about Alkacon Software GmbH, please see the
 * company website: http://www.alkacon.com
 *
 * For further information about OpenCms, please see the
 * project website: http://www.opencms.org
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package org.opencms.workplace.tools.workplace.rfsfile;

import org.opencms.flex.CmsFlexController;
import org.opencms.util.CmsStringUtil;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Helper <code>Servlet</code> that reads the 
 * <b>request parameter <i>fileName</i></b> for a valid RFS file name and 
 * pushes this file to the client browser where it triggers a download 
 * (popup-box with save dialog). <p>
 * 
 * @author  <NAME> 
 * 
 * @version $Revision: 1.8 $ 
 * 
 * @since 6.0.0 
 */
public final class CmsRfsFileDownloadServlet extends HttpServlet {

    /**
     * Default constructor for this stateless class. 
     */
    public CmsRfsFileDownloadServlet() {

        // nop
    }

    /**
     * Forwards the call to <code>{@link #doPost(HttpServletRequest, HttpServletResponse)}</code>.<p>
     * 
     * @param request Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                by the implicit jsp variable "request"
     * @param response Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                 by the implicit jsp variable "response"
     * 
     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     * @throws ServletException if the needed parameter 'filePath' cannot be found
     * @throws IOException if work related to the download process fails
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

        doPost(request, response);
    }

    /**
     * Pushes a file that has been specified by request parameter 
     * <em>"filePath"</em> to the client browser.<p> 
     * 
     * The browser will open a popup menu that offers a donwload even if the 
     * file type is known to the client's OS.<p>
     * 
     * Note that the <b>parameter "filePath"</b> is read from the 
     * given <code>{@link HttpServletRequest}</code> for the file name to serve.<p>
     * 
     * @param req Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                by the implicit jsp variable "request"
     * 
     * @param res Provided by the servlet container if this servlet is directly used from the container's servlet-mappings or 
     *                 by the implicit jsp variable "response"
     * 
     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     * 
     * @throws ServletException if the needed parameter 'filePath' cannot be found
     * @throws IOException if work related to the download process fails
     */
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {

        // find the file: 
        String fileToFind = req.getParameter("filePath");
        if (CmsStringUtil.isEmpty(fileToFind)) {
            throw new ServletException(Messages.get().key(Messages.ERR_DOWNLOAD_SERVLET_FILE_ARG_0));
        } else {

            File downloadFile = new File(fileToFind);
            res.setHeader("Content-Disposition", new StringBuffer("attachment; filename=\"").append(
                downloadFile.getName()).append("\"").toString());
            res.setContentLength((int)downloadFile.length());

            CmsFlexController controller = CmsFlexController.getController(req);
            res = controller.getTopResponse();
            res.setContentType("application/octet-stream");

            InputStream in = null;

            // push the file:
            ServletOutputStream outStream = null;
{'fraction_non_alphanumeric': 0.08694063926940639, 'fraction_numerical': 0.008036529680365296, 'mean_word_length': 3.2151655119322555, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '684116', 'n_tokens_mistral': 3044, 'n_tokens_neox': 2885, 'n_words': 1038}