001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.jsp.util;
029
030import org.opencms.util.CmsRequestUtil;
031
032import java.util.Arrays;
033import java.util.List;
034
035import javax.servlet.http.HttpServletRequest;
036
037/**
038 * Provides the detection for different devices, so that the
039 * <code>&lt;cms:device type="..."&gt;</code>-Tag can detect
040 * which kind of device type sends the HTTP request.<p>
041 *
042 * This implementation <b>detects smart phones and tablets</b>
043 * as mobile devices.<p>
044 *
045 * @see CmsJspDeviceSelector CmsJspDeviceSelector <b>detects only
046 * smart phones</b> as mobile devices
047 *
048 * @since 8.5.0.4
049 */
050public class CmsJspDeviceSelectorTablet implements I_CmsJspDeviceSelector {
051
052    /** Constant for desktop detection. */
053    public static final String C_DESKTOP = "desktop";
054
055    /** Constant for mobile detection. */
056    public static final String C_MOBILE = "mobile";
057
058    /** The list of types supported by this device selector implementation. */
059    public static final List<String> TYPES = Arrays.asList(new String[] {C_MOBILE, C_DESKTOP});
060
061    /** The user agent info. */
062    private UAgentInfo m_userAgentInfo;
063
064    /**
065     * @see org.opencms.jsp.util.I_CmsJspDeviceSelector#getDeviceType(javax.servlet.http.HttpServletRequest)
066     */
067    public String getDeviceType(HttpServletRequest req) {
068
069        m_userAgentInfo = new UAgentInfo(
070            req.getHeader(CmsRequestUtil.HEADER_USER_AGENT),
071            req.getHeader(CmsRequestUtil.HEADER_ACCEPT));
072        if (m_userAgentInfo.detectMobileQuick() || m_userAgentInfo.getIsTierTablet()) {
073            return C_MOBILE;
074        }
075        return C_DESKTOP;
076    }
077
078    /**
079     * @see org.opencms.jsp.util.I_CmsJspDeviceSelector#getDeviceTypes()
080     */
081    public List<String> getDeviceTypes() {
082
083        return TYPES;
084    }
085
086    /**
087     * Returns the User Agent info.<p>
088     *
089     * @return the information about the user agent
090     */
091    public UAgentInfo getUserAgentInfo() {
092
093        return m_userAgentInfo;
094    }
095}