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