<%@page import="java.io.*,java.util.zip.*,org.apache.log4j.Logger" %><%@page import="com.intland.codebeamer.utils.Common" %><% // IMPORTANT: DO NOT touch the imports above, these must be in ONE LINE. // if you put any characters outside of scriptlets, there will be an // "java.lang.IllegalStateException: getOutputStream() has already been called for this response" exception // because the getOutputStream() will be called just to print out the new lines or chars outside scriptlets!!!! /** * $Id$ * * @author Moxiecode * @copyright Copyright © 2006, Moxiecode Systems AB, All rights reserved. * * This file compresses the TinyMCE JavaScript using GZip and * enables the browser to do two requests instead of one for each .js file. * * It's a good idea to use the diskcache option since it reduces the servers workload. */ final Logger log = Logger.getLogger(getClass().getName()); final String jsEncoding = "ISO-8859-1"; String cacheKey = "", cacheFile = "", content = "", enc, suffix, cachePath; String plugins[], languages[], themes[]; boolean diskCache, supportsGzip, isJS, compress; int i, x, expiresOffset; OutputStreamWriter bow; ByteArrayOutputStream bos; GZIPOutputStream gzipStream; FileOutputStream fout; FileInputStream fin; // Get input plugins = getParam(request, "plugins", "").split(","); languages = getParam(request, "languages", "").split(","); themes = getParam(request, "themes", "").split(","); diskCache = getParam(request, "diskcache", "").equals("true"); isJS = getParam(request, "js", "").equals("true"); compress = getParam(request, "compress", "true").equals("true"); suffix = getParam(request, "suffix", "").equals("_src") ? "_src" : ""; cachePath = mapPath(request, "."); // Cache path, this is where the .gz files will be stored expiresOffset = 3600 * 24 * 10; // Cache for 10 days in browser cache // Custom extra javascripts to pack String custom[] = {/* "some custom .js file", "some custom .js file" */}; // Headers response.setContentType("text/javascript"); response.addHeader("Vary", "Accept-Encoding"); // Handle proxies response.setDateHeader("Expires", System.currentTimeMillis() + (expiresOffset * 1000)); // Is called directly then auto init with default settings if (!isJS) { if (log.isInfoEnabled()) { log.info("Return plain file: " + mapPath(request, "tiny_mce_gzip.js")); } out.print(getFileContents(mapPath(request, "tiny_mce_gzip.js"))); out.print("tinyMCE_GZ.init({});"); return; } // Setup cache info if (diskCache) { cacheKey = getParam(request, "plugins", "") + getParam(request, "languages", "") + getParam(request, "themes", ""); for (i=0; i<%! /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ private void writeToResponse (ServletResponse response, ByteArrayOutputStream out, Logger log) throws IOException { if (log.isInfoEnabled()) { log.info("Write response. Content length: " + out.size()); } response.setContentLength(out.size()); out.writeTo(response.getOutputStream()); } public String getParam(HttpServletRequest request, String name, String def) { String value = request.getParameter(name) != null ? "" + request.getParameter(name) : def; return value.replaceAll("[^0-9a-zA-Z\\-_,]+", ""); } public String getFileContents(String path) { try { if (!new File(path).exists()) return ""; FileInputStream fis = new FileInputStream(path); int x = fis.available(); byte b[] = new byte[x]; fis.read(b); return new String(b); } catch (IOException e) { // Ignore } return ""; } public String mapPath(HttpServletRequest request, String path) { String servletPath = SecurityFilter.getRequestPathInfo(request); String absPath = getServletContext().getRealPath(servletPath); absPath = absPath.substring(0, absPath.lastIndexOf(File.separatorChar) + 1); return absPath + path.replace('/', File.separatorChar); } public String md5(String str) { try { java.security.MessageDigest md5 = java.security.MessageDigest.getInstance("MD5"); char[] charArray = str.toCharArray(); byte[] byteArray = new byte[charArray.length]; for (int i=0; i