001/*
002 * (C) Copyright 2012 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 *     bjalon
016 */
017package org.nuxeo.ecm.mobile;
018
019import java.util.ArrayList;
020import java.util.List;
021
022import org.nuxeo.common.xmap.annotation.XNode;
023import org.nuxeo.common.xmap.annotation.XNodeList;
024import org.nuxeo.common.xmap.annotation.XObject;
025
026/**
027 * Descriptor that represent a definition of an application and a handler that will detect request context that will
028 * make the user redirect to this application.
029 * 
030 * @author <a href="mailto:bjalon@nuxeo.com">Benjamin JALON</a>
031 * @since 5.5
032 */
033@XObject("application")
034public class ApplicationDefinitionDescriptor {
035
036    @XNode("@name")
037    public String name;
038
039    @XNode("@order")
040    public Integer order;
041
042    @XNode("@disabled")
043    public boolean disabled;
044
045    @XNode("requestHandlerName")
046    public String requestHandlerName;
047
048    @XNode("applicationRelativePath")
049    public String applicationRelativePath;
050
051    @XNode("loginPage")
052    public String loginPage;
053
054    @XNode("logoutPage")
055    public String logoutPage;
056
057    @XNodeList(value = "resources/resourcesBaseURL", type = ArrayList.class, componentType = String.class)
058    public List<String> resourcesBaseUrl = new ArrayList<String>();
059
060    /**
061     * Application name described
062     */
063    public String getName() {
064        return name;
065    }
066
067    /**
068     * Return true if the given Application is enabled.
069     */
070    public boolean isDisable() {
071        return disabled;
072    }
073
074    /**
075     * Return the name of the handler that implements the logic of redirection to the application described into this
076     * descriptor. Definition of the handler is defined into the handler extension point.
077     */
078    public String getRequestHandlerName() {
079        return requestHandlerName;
080    }
081
082    /**
083     * Order is used to sort {@code RequestHandler} executed to find the target application given a request.
084     */
085    public Integer getOrder() {
086        return order;
087    }
088
089    /**
090     * Base URL of the described application (without the Nuxeo Context Path)
091     */
092    public String getApplicationRelativePath() {
093        return applicationRelativePath;
094    }
095
096    /**
097     * relative path of the login page
098     */
099    public String getLoginPage() {
100        return loginPage;
101    }
102
103    /**
104     * relative path of the logout page
105     */
106    public String getLogoutPage() {
107        return logoutPage;
108    }
109
110    private boolean isResourcesBaseUrlChecked = false;
111
112    /**
113     * Resource Base URL of the resources needed by the application described (without the Nuxeo Context Path) add a
114     * slash at the end of the base url.
115     */
116    public List<String> getResourcesBaseUrl() {
117        if (!isResourcesBaseUrlChecked) {
118            List<String> result = new ArrayList<String>();
119            isResourcesBaseUrlChecked = true;
120            for (String url : resourcesBaseUrl) {
121                if (!url.endsWith("/")) {
122                    result.add(url + "/");
123                }
124            }
125            resourcesBaseUrl = result;
126        }
127        return resourcesBaseUrl;
128    }
129
130}