001/*
002 * (C) Copyright 2010 Nuxeo SAS (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 * Contributors:
014 * Nuxeo - initial API and implementation
015 */
016
017package org.nuxeo.ecm.platform.rendition.service;
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;
025import org.nuxeo.ecm.platform.rendition.extension.RenditionProvider;
026
027/**
028 * Definition of a rendition.
029 *
030 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
031 * @since 5.4.1
032 */
033@XObject("renditionDefinition")
034public class RenditionDefinition {
035
036    protected RenditionProvider provider;
037
038    @XNode("@name")
039    protected String name;
040
041    /**
042     * @since 7.3
043     */
044    @XNode("@cmisName")
045    protected String cmisName;
046
047    @XNode("@enabled")
048    Boolean enabled;
049
050    @XNode("label")
051    protected String label;
052
053    @XNode("icon")
054    protected String icon;
055
056    @XNode("kind")
057    protected String kind;
058
059    @XNode("operationChain")
060    protected String operationChain;
061
062    /**
063     * @since 6.0
064     */
065    @XNode("allowEmptyBlob")
066    protected Boolean allowEmptyBlob;
067
068    /**
069     * @since 6.0
070     */
071    @XNode("@visible")
072    protected Boolean visible;
073
074    @XNode("@class")
075    protected Class<? extends RenditionProvider> providerClass;
076
077    @XNode("contentType")
078    protected String contentType;
079
080    /**
081     * @since 7.2
082     */
083    @XNodeList(value = "filters/filter-id", type = ArrayList.class, componentType = String.class)
084    protected List<String> filterIds;
085
086    public String getName() {
087        return name;
088    }
089
090    public String getCmisName() {
091        return cmisName;
092    }
093
094    public boolean isEnabled() {
095        return enabled == null || enabled;
096    }
097
098    /**
099     * @since 7.3
100     */
101    public boolean isEnabledSet() {
102        return enabled != null;
103    }
104
105    public String getLabel() {
106        return label;
107    }
108
109    public String getOperationChain() {
110        return operationChain;
111    }
112
113    public Class<? extends RenditionProvider> getProviderClass() {
114        return providerClass;
115    }
116
117    public RenditionProvider getProvider() {
118        return provider;
119    }
120
121    public void setProvider(RenditionProvider provider) {
122        this.provider = provider;
123    }
124
125    public String getIcon() {
126        return icon;
127    }
128
129    public String getKind() {
130        return kind;
131    }
132
133    public String getProviderType() {
134        RenditionProvider provider = getProvider();
135        if (provider == null) {
136            return null;
137        }
138        return provider.getClass().getSimpleName();
139    }
140
141    public String getContentType() {
142        return contentType;
143    }
144
145    /**
146     * @since 7.3
147     */
148    public boolean isEmptyBlobAllowed() {
149        return allowEmptyBlob != null && allowEmptyBlob;
150    }
151
152    public boolean isEmptyBlobAllowedSet() {
153        return allowEmptyBlob != null;
154    }
155
156    public boolean isVisible() {
157        return visible == null || visible;
158    }
159
160    /**
161     * @since 7.3
162     */
163    public boolean isVisibleSet() {
164        return visible != null;
165    }
166
167    public List<String> getFilterIds() {
168        return filterIds;
169    }
170
171    public void setName(String name) {
172        this.name = name;
173    }
174
175    public void setCmisName(String cmisName) {
176        this.cmisName = cmisName;
177    }
178
179    public void setEnabled(boolean enabled) {
180        this.enabled = enabled;
181    }
182
183    public void setLabel(String label) {
184        this.label = label;
185    }
186
187    public void setIcon(String icon) {
188        this.icon = icon;
189    }
190
191    public void setKind(String kind) {
192        this.kind = kind;
193    }
194
195    public void setOperationChain(String operationChain) {
196        this.operationChain = operationChain;
197    }
198
199    public void setAllowEmptyBlob(boolean allowEmptyBlob) {
200        this.allowEmptyBlob = allowEmptyBlob;
201    }
202
203    public void setVisible(boolean visible) {
204        this.visible = visible;
205    }
206
207    public void setProviderClass(Class<? extends RenditionProvider> providerClass) {
208        this.providerClass = providerClass;
209    }
210
211    public void setContentType(String contentType) {
212        this.contentType = contentType;
213    }
214
215    public void setFilterIds(List<String> filterIds) {
216        this.filterIds = filterIds;
217    }
218
219    /**
220     * @since 7.3
221     */
222    @Override
223    public RenditionDefinition clone() {
224        RenditionDefinition clone = new RenditionDefinition();
225        clone.name = name;
226        clone.cmisName = cmisName;
227        clone.enabled = enabled;
228        clone.label = label;
229        clone.icon = icon;
230        clone.kind = kind;
231        clone.operationChain = operationChain;
232        clone.allowEmptyBlob = allowEmptyBlob;
233        clone.visible = visible;
234        clone.providerClass = providerClass;
235        clone.contentType = contentType;
236        if (filterIds != null) {
237            clone.filterIds = new ArrayList<>();
238            clone.filterIds.addAll(filterIds);
239        }
240        return clone;
241    }
242}