org.zkoss.zuss
Class ZussServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by javax.servlet.http.HttpServlet
          extended by org.zkoss.zuss.ZussServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public class ZussServlet
extends javax.servlet.http.HttpServlet

The ZUSS servlet used to load ZUSS file and convert it to CSS.

The initial parameter allowed (init-param):

client.cache.hours
Default: 0
How long the browser is allowed to cache the CSS content. If zero or negative, it means the browser shall not cache it. For a production system, you shall assign a big number, such as 8760, and encode the path with a version number, such as /css/main.zuss?v=a_version_number.
compress
Default: true
Whether to compress CSS in GZIP when sending to the browser.
encoding
Default: UTF-8
The encoding used to read ZUSS and generate CSS.
server.cache
Default: false
Whether to allow this servlet to cache CSS, so ZUSS will be compiled only once for the whole system. Turn it on for the production system.

Author:
tomyeh
See Also:
Serialized Form

Constructor Summary
ZussServlet()
           
 
Method Summary
protected  void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
protected  java.io.InputStream getInputStream(java.lang.String path)
          Returns the input stream of the given path.
protected  java.lang.String getPath(javax.servlet.http.HttpServletRequest request)
          Retrieves the path of the ZUSS file from the request.
protected  Resolver getResolver(javax.servlet.http.HttpServletRequest request)
          Returns a resolver used to provide the default variables and functions.
 void init()
           
protected  boolean isIncluded(javax.servlet.http.HttpServletRequest request)
          Returns if this request is caused by being included by another servlet.
protected  void setCacheControl(javax.servlet.http.HttpServletResponse response)
          Sets the cache-control related headers.
protected  byte[] translate(javax.servlet.http.HttpServletRequest request, java.lang.String path)
          Translate ZUSS to CSS.
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZussServlet

public ZussServlet()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
Throws:
javax.servlet.ServletException

doGet

protected void doGet(javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
              throws javax.servlet.ServletException,
                     java.io.IOException
Overrides:
doGet in class javax.servlet.http.HttpServlet
Throws:
javax.servlet.ServletException
java.io.IOException

translate

protected byte[] translate(javax.servlet.http.HttpServletRequest request,
                           java.lang.String path)
                    throws java.io.IOException
Translate ZUSS to CSS.

Parameters:
path - the path of the ZUSS file, which is decided by getPath(javax.servlet.http.HttpServletRequest).
Returns:
the CSS content in a byte array (it is not compressed).
Throws:
java.io.IOException

getResolver

protected Resolver getResolver(javax.servlet.http.HttpServletRequest request)
Returns a resolver used to provide the default variables and functions.

Default: an instance of RequestResolver.


getInputStream

protected java.io.InputStream getInputStream(java.lang.String path)
Returns the input stream of the given path.

Default: invoke getServletContext().getResourceAsStream() to load the ZUSS file.

Parameters:
path - the path of the ZUSS file, which is decided by getPath(javax.servlet.http.HttpServletRequest).

getPath

protected java.lang.String getPath(javax.servlet.http.HttpServletRequest request)
Retrieves the path of the ZUSS file from the request.

Default: returns request.getPath()


isIncluded

protected boolean isIncluded(javax.servlet.http.HttpServletRequest request)
Returns if this request is caused by being included by another servlet.


setCacheControl

protected void setCacheControl(javax.servlet.http.HttpServletResponse response)
Sets the cache-control related headers.

Default: it depends on client.cache.hours



Copyright © 2005-2010 Potix Corporation. All Rights Reserved.