001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.servlet.filters.etag;
016    
017    import com.liferay.portal.kernel.servlet.StringServletResponse;
018    import com.liferay.portal.kernel.util.ParamUtil;
019    import com.liferay.portal.servlet.filters.BasePortalFilter;
020    import com.liferay.util.servlet.ServletResponseUtil;
021    
022    import javax.servlet.FilterChain;
023    import javax.servlet.http.HttpServletRequest;
024    import javax.servlet.http.HttpServletResponse;
025    
026    /**
027     * @author Eduardo Lundgren
028     * @author Brian Wing Shun Chan
029     * @author Raymond Augé
030     * @author Shuyang Zhou
031     */
032    public class ETagFilter extends BasePortalFilter {
033    
034            protected void processFilter(
035                            HttpServletRequest request, HttpServletResponse response,
036                            FilterChain filterChain)
037                    throws Exception {
038    
039                    boolean etag = ParamUtil.getBoolean(request, _ETAG, true);
040    
041                    if (etag) {
042                            StringServletResponse stringResponse =
043                                    new StringServletResponse(response);
044    
045                            processFilter(
046                                    ETagFilter.class, request, stringResponse, filterChain);
047    
048                            if (!ETagUtil.processETag(request, response, stringResponse)) {
049                                    ServletResponseUtil.write(response, stringResponse);
050                            }
051                    }
052                    else {
053                            processFilter(ETagFilter.class, request, response, filterChain);
054                    }
055            }
056    
057            private static final String _ETAG = "etag";
058    
059    }