001/*
002 * (C) Copyright 2015 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-2.1.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 *     Florent Guillaume
016 */
017package org.nuxeo.ecm.core.io.download;
018
019import org.nuxeo.common.xmap.annotation.XNode;
020import org.nuxeo.common.xmap.annotation.XObject;
021
022/**
023 * Descriptor for the permissions associated to a blob download.
024 *
025 * @since 7.4
026 */
027@XObject("permission")
028public class DownloadPermissionDescriptor implements Comparable<DownloadPermissionDescriptor> {
029
030    public static final String DEFAULT_SCRIPT_LANGUAGE = "JavaScript";
031
032    @XNode("@name")
033    private String name;
034
035    @XNode("script")
036    private String script;
037
038    @XNode("script@language")
039    private String scriptLanguage;
040
041    public String getName() {
042        return name;
043    }
044
045    public String getScript() {
046        return script;
047    }
048
049    public String getScriptLanguage() {
050        return scriptLanguage == null ? DEFAULT_SCRIPT_LANGUAGE : scriptLanguage;
051    }
052
053    // empty constructor
054    public DownloadPermissionDescriptor() {
055    }
056
057    // copy constructor
058    public DownloadPermissionDescriptor(DownloadPermissionDescriptor other) {
059        name = other.name;
060        script = other.script;
061        scriptLanguage = other.scriptLanguage;
062    }
063
064    public void merge(DownloadPermissionDescriptor other) {
065        if (other.name != null) {
066            name = other.name;
067        }
068        if (other.script != null) {
069            script = other.script;
070        }
071        if (other.scriptLanguage != null) {
072            scriptLanguage = other.scriptLanguage;
073        }
074    }
075
076    @Override
077    public int compareTo(DownloadPermissionDescriptor other) {
078        return name.compareTo(other.name);
079    }
080
081}