001/* 002 * (C) Copyright 2006-2007 Nuxeo SAS (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 * Nuxeo - initial API and implementation 016 * 017 */ 018 019package org.nuxeo.ecm.webapp.dnd; 020 021import javax.faces.context.ExternalContext; 022import javax.faces.context.FacesContext; 023import javax.servlet.http.HttpServletRequest; 024 025import org.jboss.seam.ScopeType; 026import org.jboss.seam.annotations.Factory; 027import org.jboss.seam.annotations.Name; 028import org.jboss.seam.annotations.Scope; 029import org.jboss.seam.contexts.Contexts; 030import org.nuxeo.common.utils.UserAgentMatcher; 031 032/** 033 * Seam component used to outject a Session scoped flag that indicates if client's browser supports HTML5 (plugin free) 034 * Drag&Drop feature 035 * 036 * @author Tiry (tdelprat@nuxeo.com) 037 */ 038@Name("dndConfigHelper") 039@Scope(ScopeType.EVENT) 040public class DndConfigurationHelper { 041 042 /** 043 * Factory method used to push into the Session context a flag indicating if HTML5 Drag&Drop can be used 044 * 045 * @return 046 */ 047 @Factory(value = "useHtml5DragAndDrop", scope = ScopeType.SESSION) 048 public boolean useHtml5DragAndDrop() { 049 050 FacesContext context = FacesContext.getCurrentInstance(); 051 ExternalContext econtext = context.getExternalContext(); 052 HttpServletRequest request = (HttpServletRequest) econtext.getRequest(); 053 054 String ua = request.getHeader("User-Agent"); 055 056 return UserAgentMatcher.html5DndIsSupported(ua); 057 } 058 059 public void setHtml5DndEnabled(boolean enabled) { 060 Contexts.getSessionContext().set("useHtml5DragAndDrop", enabled); 061 } 062 063}