001/* 002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others. 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 * Thomas Roger 016 */ 017 018package org.nuxeo.ecm.platform.rendition.service; 019 020import static org.apache.commons.logging.LogFactory.getLog; 021 022import java.util.ArrayList; 023import java.util.List; 024 025import org.apache.commons.logging.Log; 026import org.nuxeo.common.xmap.annotation.XNode; 027import org.nuxeo.common.xmap.annotation.XNodeList; 028import org.nuxeo.common.xmap.annotation.XObject; 029 030/** 031 * Descriptor contribution {@link RenditionDefinitionProvider}s. 032 * 033 * @since 7.2 034 */ 035@XObject("renditionDefinitionProvider") 036public class RenditionDefinitionProviderDescriptor { 037 038 private static final Log log = getLog(RenditionDefinitionProviderDescriptor.class); 039 040 @XNode("@name") 041 protected String name; 042 043 @XNode("@enabled") 044 Boolean enabled; 045 046 @XNode("@class") 047 protected Class<? extends RenditionDefinitionProvider> providerClass; 048 049 protected RenditionDefinitionProvider provider; 050 051 @XNodeList(value = "filters/filter-id", type = ArrayList.class, componentType = String.class) 052 protected List<String> filterIds; 053 054 public String getName() { 055 return name; 056 } 057 058 public boolean isEnabled() { 059 return enabled == null || enabled; 060 } 061 062 public boolean isEnabledSet() { 063 return enabled != null; 064 } 065 066 public Class<? extends RenditionDefinitionProvider> getProviderClass() { 067 return providerClass; 068 } 069 070 public RenditionDefinitionProvider getProvider() { 071 if (provider == null && providerClass != null) { 072 try { 073 provider = providerClass.newInstance(); 074 } catch (InstantiationException | IllegalAccessException e) { 075 log.error(String.format("Unable to instantiate RenditionDefinitionProvider for '%s'", getName()), e); 076 } 077 } 078 return provider; 079 } 080 081 public List<String> getFilterIds() { 082 return filterIds; 083 } 084 085 public void setEnabled(Boolean enabled) { 086 this.enabled = enabled; 087 } 088 089 public void setProviderClass(Class<? extends RenditionDefinitionProvider> providerClass) { 090 this.providerClass = providerClass; 091 } 092 093 public void setProvider(RenditionDefinitionProvider provider) { 094 this.provider = provider; 095 } 096 097 public void setFilterIds(List<String> filterIds) { 098 this.filterIds = filterIds; 099 } 100 101 @Override 102 public RenditionDefinitionProviderDescriptor clone() { 103 RenditionDefinitionProviderDescriptor clone = new RenditionDefinitionProviderDescriptor(); 104 clone.name = name; 105 clone.enabled = enabled; 106 clone.providerClass = providerClass; 107 if (filterIds != null) { 108 clone.filterIds = new ArrayList<>(); 109 clone.filterIds.addAll(filterIds); 110 } 111 return clone; 112 } 113}