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