GzipModule.cs :  » Content-Management-Systems-CMS » umbraco » umbraco » editorControls » tinyMCE3 » webcontrol » plugin » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Content Management Systems CMS » umbraco 
umbraco » umbraco » editorControls » tinyMCE3 » webcontrol » plugin » GzipModule.cs
/*
 * $Id: GzipModule.cs 439 2007-11-26 13:26:10Z spocke $
 *
 * @author Moxiecode
 * @copyright Copyright  2004-2007, Moxiecode Systems AB, All rights reserved.
 */

using System;
using System.Web;
using System.Text.RegularExpressions;
using System.IO;

namespace umbraco.editorControls.tinyMCE3.webcontrol.plugin{
    /// <summary>
  /// Description of HttpHandler.
  /// </summary>
  public class GzipModule : IModule {
    /// <summary></summary>
    /// <param name="context">Request context.</param>
    public void ProcessRequest(HttpContext context) {
      HttpRequest request = context.Request;
      HttpResponse response = context.Response;
      HttpServerUtility server = context.Server;
      GzipCompressor gzipCompressor = new GzipCompressor();
      ConfigSection configSection = (ConfigSection) System.Web.HttpContext.Current.GetSection("TinyMCE");
      string suffix = "", enc;
      string[] languages = request.QueryString["languages"].Split(',');
      bool supportsGzip;

      // Set response headers
      response.ContentType = "text/javascript";
      response.Charset = "UTF-8";
      response.Buffer = false;

            // UMBRACO: Populate the configsection if it's empty
            if (configSection == null)
            {
                configSection = new ConfigSection();
                configSection.GzipEnabled = true;
                configSection.InstallPath = umbraco.editorControls.tinymce.tinyMCEConfiguration.JavascriptPath;
                configSection.GzipExpiresOffset = TimeSpan.FromDays(10).Ticks;
            }

      // Setup cache
      response.Cache.SetExpires(DateTime.Now.AddTicks(configSection.GzipExpiresOffset));
      response.Cache.SetCacheability(HttpCacheability.Public);
      response.Cache.SetValidUntilExpires(false);

      // Check if it supports gzip
      enc = Regex.Replace("" + request.Headers["Accept-Encoding"], @"\s+", "").ToLower();
      supportsGzip = enc.IndexOf("gzip") != -1 || request.Headers["---------------"] != null;
      enc = enc.IndexOf("x-gzip") != -1 ? "x-gzip" : "gzip";

      // Handle mode/suffix
      if (configSection.Mode != null)
        suffix = "_" + configSection.Mode;

      gzipCompressor.AddData("var tinyMCEPreInit = {base : '" + new Uri(request.Url, configSection.InstallPath).ToString() + "', suffix : '" + suffix + "'};");

      // Add core
      gzipCompressor.AddFile(server.MapPath(configSection.InstallPath + "/tiny_mce" + suffix + ".js"));

      // Add core languages
      foreach (string lang in languages)
        gzipCompressor.AddFile(server.MapPath(configSection.InstallPath + "/langs/" + lang + ".js"));

      // Add themes
      if (request.QueryString["themes"] != null) {
        foreach (string theme in request.QueryString["themes"].Split(',')) {
          gzipCompressor.AddFile(server.MapPath(configSection.InstallPath + "/themes/" + theme + "/editor_template" + suffix + ".js"));

          // Add theme languages
          foreach (string lang in languages) {
            string path = server.MapPath(configSection.InstallPath + "/themes/" + theme + "/langs/" + lang + ".js");

            if (File.Exists(path))
              gzipCompressor.AddFile(path);
          }

          gzipCompressor.AddData("tinymce.ThemeManager.urls['" + theme + "'] = tinymce.baseURL+'/themes/" + theme + "';");
        }
      }

      // Add plugins
      if (request.QueryString["plugins"] != null) {
        foreach (string plugin in request.QueryString["plugins"].Split(',')) {
          gzipCompressor.AddFile(server.MapPath(configSection.InstallPath + "/plugins/" + plugin + "/editor_plugin" + suffix + ".js"));

          // Add plugin languages
          foreach (string lang in languages) {
            string path = server.MapPath(configSection.InstallPath + "/plugins/" + plugin + "/langs/" + lang + ".js");

            if (File.Exists(path))
              gzipCompressor.AddFile(path);
          }

          gzipCompressor.AddData("tinymce.ThemeManager.urls['" + plugin + "'] = tinymce.baseURL+'/plugins/" + plugin + "';");
        }
      }

      // Output compressed file
      gzipCompressor.NoCompression = !supportsGzip || configSection.GzipNoCompression;
      if (!gzipCompressor.NoCompression)
        response.AppendHeader("Content-Encoding", enc);

      gzipCompressor.DiskCache = configSection.GzipDiskCache;
      gzipCompressor.CachePath = configSection.GzipCachePath;

      gzipCompressor.Compress(response.OutputStream);
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.