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