001/*
002 * (C) Copyright 2006-2013 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 *
014 * Contributors:
015 *     ldoguin
016 *
017 */
018package org.nuxeo.template.service;
019
020import java.util.Collection;
021import java.util.HashMap;
022import java.util.Map;
023
024import org.nuxeo.runtime.model.ContributionFragmentRegistry;
025import org.nuxeo.template.api.descriptor.OutputFormatDescriptor;
026
027public class OutputFormatRegistry extends ContributionFragmentRegistry<OutputFormatDescriptor> {
028
029    protected Map<String, OutputFormatDescriptor> outputFormats = new HashMap<String, OutputFormatDescriptor>();
030
031    @Override
032    public OutputFormatDescriptor clone(OutputFormatDescriptor outFormat) {
033        return outFormat.clone();
034    }
035
036    public OutputFormatDescriptor getOutputFormatById(String id) {
037        return outputFormats.get(id);
038    }
039
040    public Collection<OutputFormatDescriptor> getRegistredOutputFormat() {
041        return outputFormats.values();
042    }
043
044    @Override
045    public void contributionRemoved(String id, OutputFormatDescriptor outFormat) {
046        outputFormats.remove(id);
047    }
048
049    @Override
050    public void contributionUpdated(String id, OutputFormatDescriptor outFormat, OutputFormatDescriptor newoutFormat) {
051        if (outFormat == null || !outFormat.isEnabled()) {
052            outputFormats.remove(id);
053        } else {
054            outputFormats.put(id, outFormat);
055        }
056    }
057
058    @Override
059    public String getContributionId(OutputFormatDescriptor outFormat) {
060        return outFormat.getId();
061    }
062
063    @Override
064    public void merge(OutputFormatDescriptor srcOutFormat, OutputFormatDescriptor descOutFormat) {
065        descOutFormat.merge(srcOutFormat);
066    }
067
068}