001/* 002 * (C) Copyright 2012 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Benjamin JALON 018 */ 019 020package org.nuxeo.ecm.mobile.seam; 021 022import java.io.Serializable; 023 024import javax.faces.context.FacesContext; 025import javax.servlet.http.Cookie; 026import javax.servlet.http.HttpServletRequest; 027import javax.servlet.http.HttpServletResponse; 028 029import org.jboss.seam.ScopeType; 030import org.jboss.seam.annotations.Name; 031import org.jboss.seam.annotations.Scope; 032import org.nuxeo.ecm.mobile.handler.MobileRequestHandler; 033import org.nuxeo.ecm.mobile.handler.RequestHandler; 034 035/** 036 * Actions Bean needed to build JSF actions 037 * 038 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a> 039 * @since 5.5 040 */ 041@Name("mobileApplicationActions") 042@Scope(ScopeType.EVENT) 043public class MobileApplicationActionsBean implements Serializable { 044 045 private static final long serialVersionUID = 1L; 046 047 public boolean isMobileBrowser() { 048 RequestHandler handler = new MobileRequestHandler(); 049 HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest(); 050 return handler.isRequestRedirectedToApplication(request); 051 } 052 053 public String cleanCookie() { 054 Cookie cookie = new Cookie("skipMobileRedirection", "false"); 055 cookie.setPath("/"); 056 057 ((HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse()).addCookie(cookie); 058 return null; 059 } 060 061}