001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.servlet.filters.doubleclick;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.HttpUtil;
020    import com.liferay.portal.kernel.util.TransientValue;
021    import com.liferay.portal.servlet.filters.BasePortalFilter;
022    
023    import javax.servlet.FilterChain;
024    import javax.servlet.http.HttpServletRequest;
025    import javax.servlet.http.HttpServletResponse;
026    import javax.servlet.http.HttpSession;
027    
028    import org.apache.commons.lang.time.StopWatch;
029    
030    /**
031     * @author     Olaf Fricke
032     * @author     Brian Wing Shun Chan
033     * @author     Raymond Aug??
034     * @deprecated As of 6.1.0, with no direct replacement
035     */
036    public class DoubleClickFilter extends BasePortalFilter {
037    
038            @Override
039            public boolean isFilterEnabled() {
040                    return false;
041            }
042    
043            @Override
044            protected void processFilter(
045                            HttpServletRequest request, HttpServletResponse response,
046                            FilterChain filterChain)
047                    throws Exception {
048    
049                    StopWatch stopWatch = null;
050    
051                    if (_log.isDebugEnabled()) {
052                            stopWatch = new StopWatch();
053    
054                            stopWatch.start();
055                    }
056    
057                    HttpSession session = request.getSession(false);
058    
059                    if (session == null) {
060                            processFilter(
061                                    DoubleClickFilter.class, request, response, filterChain);
062                    }
063                    else {
064                            DoubleClickController doubleClickController = null;
065    
066                            synchronized (session) {
067                                    TransientValue<DoubleClickController> transientValue =
068                                            (TransientValue<DoubleClickController>)session.getAttribute(
069                                                    _CONTROLLER_KEY);
070    
071                                    if (transientValue != null) {
072                                            doubleClickController = transientValue.getValue();
073                                    }
074    
075                                    if (doubleClickController == null) {
076                                            doubleClickController = new DoubleClickController();
077    
078                                            transientValue = new TransientValue<DoubleClickController>(
079                                                    doubleClickController);
080    
081                                            session.setAttribute(_CONTROLLER_KEY, transientValue);
082                                    }
083                            }
084    
085                            boolean ok = false;
086    
087                            try {
088                                    doubleClickController.control(request, response, filterChain);
089    
090                                    ok = true;
091                            }
092                            finally {
093                                    if (stopWatch != null) {
094                                            String completeURL = HttpUtil.getCompleteURL(request);
095    
096                                            if (ok) {
097                                                    _log.debug(
098                                                            "Double click prevention succeeded in " +
099                                                                    stopWatch.getTime() + " ms for " + completeURL);
100                                            }
101                                            else {
102                                                    _log.debug(
103                                                            "Double click prevention failed in " +
104                                                                    stopWatch.getTime() + " ms for " + completeURL);
105                                            }
106                                    }
107                            }
108                    }
109            }
110    
111            private static final String _CONTROLLER_KEY =
112                    DoubleClickFilter.class.getName();
113    
114            private static Log _log = LogFactoryUtil.getLog(DoubleClickFilter.class);
115    
116    }