Changeset 20817

Show
Ignore:
Timestamp:
06/19/07 15:10:20 (1 year ago)
Author:
jmorliaguet
Message:

- compress JS files served by NXThemes (NXP-1207)

- added initial API for caching served resources on the server too

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.nuxeo.theme/trunk/nuxeo-theme-core/src/main/java/org/nuxeo/theme/themes/ThemeManager.java

    r20715 r20817  
    8282            "_ inherits from _"); 
    8383 
    84     private String renderedStyles = null; 
     84    private String cachedStyles = null; 
     85 
     86    private final Map<String, String> cachedResources = new HashMap<String, String>(); 
    8587 
    8688    public void clear() { 
     
    449451 
    450452    public void stylesModified() { 
    451         setRenderedStyles(null); 
     453        setCachedStyles(null); 
    452454    } 
    453455 
     
    668670 
    669671    // Cached styles 
    670     public String getRenderedStyles() { 
    671         return renderedStyles; 
    672     } 
    673  
    674     public void setRenderedStyles(String renderedStyles) { 
    675         this.renderedStyles = renderedStyles; 
     672    public String getCachedStyles() { 
     673        return cachedStyles; 
     674    } 
     675 
     676    public void setCachedStyles(String cachedStyles) { 
     677        this.cachedStyles = cachedStyles; 
     678    } 
     679 
     680    public String getResource(String name) { 
     681        return cachedResources.get(name); 
     682    } 
     683 
     684    public void setResource(String name, String content) { 
     685        cachedResources.put(name, content); 
    676686    } 
    677687 
  • org.nuxeo.theme/trunk/nuxeo-theme-jsf/src/main/java/org/nuxeo/theme/jsf/servlets/Resources.java

    r20757 r20817  
    3333import org.nuxeo.theme.ApplicationType; 
    3434import org.nuxeo.theme.Manager; 
     35import org.nuxeo.theme.jsf.JSUtils; 
    3536import org.nuxeo.theme.jsf.Utils; 
    3637import org.nuxeo.theme.resources.ResourceType; 
     
    4849    @Override 
    4950    protected void doGet(final HttpServletRequest request, 
    50             final HttpServletResponse response) throws ServletException, IOException { 
     51            final HttpServletResponse response) throws ServletException, 
     52            IOException { 
    5153        doPost(request, response); 
    5254    } 
     
    6769 
    6870        final TypeRegistry typeRegistry = Manager.getTypeRegistry(); 
     71        String contentType = null; 
     72        String key = m.group(1); 
    6973 
    70         String contentType = null
    71         final String[] resourceNames = m.group(1).split(","); 
     74        boolean compressJs = false
     75        final String[] resourceNames = key.split(","); 
    7276        for (String resourceName : resourceNames) { 
    7377            String previousContentType = contentType; 
    7478            if (resourceName.endsWith(".js")) { 
    7579                contentType = "text/javascript"; 
     80                compressJs = true; 
    7681            } else if (resourceName.endsWith(".css")) { 
    7782                contentType = "text/css"; 
     
    129134        } 
    130135 
    131         os.write(out.toString().getBytes()); 
     136        String source = out.toString(); 
     137        if (compressJs) { 
     138            source = JSUtils.compressSource(source); 
     139        } 
     140 
     141        os.write(source.getBytes()); 
    132142        os.close(); 
    133143 
     
    136146    } 
    137147 
    138     private static void writeResource(final ResourceType resource, final  OutputStream out) { 
     148    private static void writeResource(final ResourceType resource, 
     149            final OutputStream out) { 
    139150        InputStream in = null; 
    140151        try { 
  • org.nuxeo.theme/trunk/nuxeo-theme-jsf/src/main/java/org/nuxeo/theme/jsf/servlets/Styles.java

    r20159 r20817  
    7373        if (Utils.supportsGzip(request)) { 
    7474            response.setHeader("Content-Encoding", "gzip"); 
     75            // Needed by proxy servers 
     76            response.setHeader("Vary", "Accept-Encoding"); 
    7577            os = new GZIPOutputStream(os); 
    7678        } 
    7779 
    7880        final ThemeManager themeManager = Manager.getThemeManager(); 
    79         String rendered = themeManager.getRenderedStyles(); 
     81        String rendered = themeManager.getCachedStyles(); 
    8082        if (rendered == null) { 
    8183            final StringBuilder sb = new StringBuilder(); 
     
    8789            } 
    8890            rendered = sb.toString(); 
    89             themeManager.setRenderedStyles(rendered); 
     91            themeManager.setCachedStyles(rendered); 
    9092        } 
    9193