001/*
002 * (C) Copyright ${year} Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Benjamin JALON
016 */
017
018package org.nuxeo.ecm.mobile.seam;
019
020import java.io.Serializable;
021
022import javax.faces.context.FacesContext;
023import javax.servlet.http.Cookie;
024import javax.servlet.http.HttpServletRequest;
025import javax.servlet.http.HttpServletResponse;
026
027import org.jboss.seam.ScopeType;
028import org.jboss.seam.annotations.Name;
029import org.jboss.seam.annotations.Scope;
030import org.nuxeo.ecm.mobile.handler.MobileRequestHandler;
031import org.nuxeo.ecm.mobile.handler.RequestHandler;
032
033/**
034 * Actions Bean needed to build JSF actions
035 *
036 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a>
037 * @since 5.5
038 */
039@Name("mobileApplicationActions")
040@Scope(ScopeType.EVENT)
041public class MobileApplicationActionsBean implements Serializable {
042
043    private static final long serialVersionUID = 1L;
044
045    public boolean isMobileBrowser() {
046        RequestHandler handler = new MobileRequestHandler();
047        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
048        return handler.isRequestRedirectedToApplication(request);
049    }
050
051    public String cleanCookie() {
052        Cookie cookie = new Cookie("skipMobileRedirection", "false");
053        cookie.setPath("/");
054
055        ((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()).addCookie(cookie);
056        return null;
057    }
058
059}