<commit_before>package org.demyo.web.controller;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPOutputStream;

import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Port of the official GZip compressor to a Spring 3 controller.
 * <p>
 * Removes configuration of some information: cache is always on, plugin is always initialised properly, there is
 * no suffix (use minified script), always compress, always include core. Stores the cache in a proper location.
 * Uses Spring's MD5 helper. Use IOUtils to read file contents. All methods are private. Assumes no custom files.
 * </p>
 * <p>
 * Appart from that, most of the structure is untouched, and a bit ugly.
 * </p>
 * <p>
 * The original code is copyright 2009, Moxiecode Systems AB, released under LGPL License.
 * </p>
 * 
 * @author $Author: xr $
 * @version $Revision: 1034 $
 */
@Controller
@RequestMapping("/tiny_mce")
public class TinyMCEController {
	private static final Logger LOGGER = LoggerFactory.getLogger(TinyMCEController.class);
	private static final long EXPIRES_OFFSET = 3600 * 24 * 10 * 1000; // cache for 10 days in browser

	private final String cachePath;
	@Autowired
	private ServletContext context;

	/**
	 * Default constructor.
	 */
	public TinyMCEController() {
		// TODO: use demyo cache location
		cachePath = System.getProperty("java.io.tmpdir");
	}

	/**
	 * Gets the gzipped TinyMCE components.
	 * 
	 * @param request The HTTP request.
	 * @param response The HTTP response.
	 * @throws IOException For various I/O errors.
	 */
	@RequestMapping("/tiny_mce.js.gz")
	public void getGzipFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
		ServletOutputStream outStream = response.getOutputStream();

		// Get input
		String[] plugins = getParam(request, "plugins", "").split(",");
		String[] languages = getParam(request, "languages", "").split(",");
		String[] themes = getParam(request, "themes", "").split(",");

		// Custom extra javascripts to pack

		// Headers
		response.setContentType("text/javascript");
		response.addHeader("Vary", "Accept-Encoding"); // Handle proxies
		response.setDateHeader("Expires", System.currentTimeMillis() + EXPIRES_OFFSET);<commit_msg>Use system cache for TinyMCE<commit_after>package org.demyo.web.controller;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.GZIPOutputStream;

import javax.servlet.ServletContext;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.demyo.model.config.SystemConfiguration;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Port of the official GZip compressor to a Spring 3 controller.
 * <p>
 * Removes configuration of some information: cache is always on, plugin is always initialised properly, there is
 * no suffix (use minified script), always compress, always include core. Stores the cache in a proper location.
 * Uses Spring's MD5 helper. Use IOUtils to read file contents. All methods are private. Assumes no custom files.
 * </p>
 * <p>
 * Appart from that, most of the structure is untouched, and a bit ugly.
 * </p>
 * <p>
 * The original code is copyright 2009, Moxiecode Systems AB, released under LGPL License.
 * </p>
 * 
 * @author $Author: xr $
 * @version $Revision: 1034 $
 */
@Controller
@RequestMapping("/tiny_mce")
public class TinyMCEController {
	private static final Logger LOGGER = LoggerFactory.getLogger(TinyMCEController.class);
	private static final long EXPIRES_OFFSET = 3600 * 24 * 10 * 1000; // cache for 10 days in browser

	private final String cachePath;
	@Autowired
	private ServletContext context;

	/**
	 * Default constructor.
	 */
	public TinyMCEController() {
		cachePath = SystemConfiguration.getInstance().getTempDirectory().getAbsolutePath();
	}

	/**
	 * Gets the gzipped TinyMCE components.
	 * 
	 * @param request The HTTP request.
	 * @param response The HTTP response.
	 * @throws IOException For various I/O errors.
	 */
	@RequestMapping("/tiny_mce.js.gz")
	public void getGzipFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
		ServletOutputStream outStream = response.getOutputStream();

		// Get input
		String[] plugins = getParam(request, "plugins", "").split(",");
		String[] languages = getParam(request, "languages", "").split(",");
		String[] themes = getParam(request, "themes", "").split(",");

		// Custom extra javascripts to pack

		// Headers
		response.setContentType("text/javascript");
		response.addHeader("Vary", "Accept-Encoding"); // Handle proxies
		response.setDateHeader("Expires", System.currentTimeMillis() + EXPIRES_OFFSET);
{'fraction_non_alphanumeric': 0.11085368027089645, 'fraction_numerical': 0.009267510247727678, 'mean_word_length': 4.833679833679834, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1568568', 'n_tokens_mistral': 1681, 'n_tokens_neox': 1588, 'n_words': 490}