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.kernel.servlet;
016    
017    import javax.servlet.ServletContext;
018    import javax.servlet.http.Cookie;
019    
020    /**
021     * @author Shuyang Zhou
022     * @author Brian Wing Shun Chan
023     */
024    public class ServletVersionDetector {
025    
026            public static boolean is2_5() {
027                    if (_2_5 != null) {
028                            return _2_5.booleanValue();
029                    }
030    
031                    try {
032                            ServletContext.class.getMethod("getContextPath");
033    
034                            _2_5 = Boolean.TRUE;
035                    }
036                    catch (Exception e) {
037                            _2_5 = Boolean.FALSE;
038                    }
039    
040                    return _2_5.booleanValue();
041            }
042    
043            public static boolean is3_0() {
044                    if (_3_0 != null) {
045                            return _3_0.booleanValue();
046                    }
047    
048                    try {
049                            Cookie.class.getMethod("isHttpOnly");
050    
051                            _3_0 = Boolean.TRUE;
052                    }
053                    catch (Exception e) {
054                            _3_0 = Boolean.FALSE;
055                    }
056    
057                    return _3_0.booleanValue();
058            }
059    
060            private static Boolean _2_5;
061            private static Boolean _3_0;
062    
063    }