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