001/*
002 * (C) Copyright 2017 Nuxeo (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 *     Antoine Taillefer <ataillefer@nuxeo.com>
018 */
019package org.nuxeo.ecm.webapp.action;
020
021import static org.jboss.seam.ScopeType.APPLICATION;
022import static org.jboss.seam.ScopeType.CONVERSATION;
023
024import java.io.Serializable;
025
026import javax.faces.context.FacesContext;
027import javax.servlet.http.HttpServletRequest;
028
029import org.jboss.seam.annotations.Factory;
030import org.jboss.seam.annotations.In;
031import org.jboss.seam.annotations.Name;
032import org.jboss.seam.annotations.Scope;
033import org.nuxeo.ecm.core.api.DocumentModel;
034import org.nuxeo.ecm.platform.ui.web.api.NavigationContext;
035import org.nuxeo.ecm.platform.web.common.MobileBannerHelper;
036
037/**
038 * Actions for the banner to open a document in the mobile application.
039 *
040 * @since 9.1
041 */
042@Name("mobileBannerActions")
043@Scope(CONVERSATION)
044public class MobileBannerActions implements Serializable {
045
046    private static final long serialVersionUID = 1L;
047
048    @In(create = true, required = false)
049    protected transient NavigationContext navigationContext;
050
051    public String getURLForAndroidApplication() {
052        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance()
053                                                                      .getExternalContext()
054                                                                      .getRequest();
055        DocumentModel currentDocument = navigationContext.getCurrentDocument();
056        return MobileBannerHelper.getURLForAndroidApplication(request, currentDocument);
057    }
058
059    public String getURLForIOSApplication() {
060        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance()
061                                                                      .getExternalContext()
062                                                                      .getRequest();
063        DocumentModel currentDocument = navigationContext.getCurrentDocument();
064        return MobileBannerHelper.getURLForIOSApplication(request, currentDocument);
065    }
066
067    @Factory(value = "appStoreURL", scope = APPLICATION)
068    public String getAppStoreURL() {
069        return MobileBannerHelper.getAppStoreURL();
070    }
071
072}