001/*
002 * (C) Copyright 2006-2011 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 <troger@nuxeo.com>
016 */
017
018package org.nuxeo.ecm.platform.video.service;
019
020import java.util.HashMap;
021import java.util.Map;
022
023import org.nuxeo.runtime.model.ContributionFragmentRegistry;
024
025/**
026 * {@link ContributionFragmentRegistry} to register {@link VideoConversion}.
027 *
028 * @author <a href="mailto:troger@nuxeo.com">Thomas Roger</a>
029 * @since 5.5
030 */
031public class VideoConversionContributionHandler extends ContributionFragmentRegistry<VideoConversion> {
032
033    public final Map<String, VideoConversion> registry;
034
035    public VideoConversionContributionHandler() {
036        registry = new HashMap<String, VideoConversion>();
037    }
038
039    @Override
040    public String getContributionId(VideoConversion contrib) {
041        return contrib.getName();
042    }
043
044    @Override
045    public void contributionUpdated(String id, VideoConversion contrib, VideoConversion newOrigContrib) {
046        if (contrib.isEnabled()) {
047            registry.put(id, contrib);
048        } else {
049            registry.remove(id);
050        }
051    }
052
053    @Override
054    public void contributionRemoved(String id, VideoConversion origContrib) {
055        registry.remove(id);
056    }
057
058    @Override
059    public VideoConversion clone(VideoConversion object) {
060        try {
061            return object.clone();
062        } catch (CloneNotSupportedException e) {
063            throw new Error(e); // cannot happens.
064        }
065    }
066
067    @Override
068    public void merge(VideoConversion src, VideoConversion dst) {
069        dst.setConverter(src.getConverter());
070        dst.setHeight(src.getHeight());
071        dst.setEnabled(src.isEnabled());
072
073        if (src.isRenditionSet()) {
074            dst.setRendition(src.isRendition());
075        }
076
077        if (src.isRenditionVisibleSet()) {
078            dst.setRenditionVisible(src.isRenditionVisible());
079        }
080    }
081
082}