001/* 002 * (C) Copyright 2006-2007 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 * Nuxeo - initial API and implementation 018 * 019 * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ 020 */ 021 022package org.nuxeo.ecm.webapp.documentsLists; 023 024import java.util.ArrayList; 025import java.util.HashMap; 026import java.util.List; 027import java.util.Map; 028 029import org.apache.commons.logging.Log; 030import org.apache.commons.logging.LogFactory; 031import org.nuxeo.runtime.model.ComponentContext; 032import org.nuxeo.runtime.model.ComponentInstance; 033import org.nuxeo.runtime.model.DefaultComponent; 034 035public class DocumentsListsService extends DefaultComponent { 036 037 public static final String NAME = "org.nuxeo.ecm.webapp.documentsLists.DocumentsListsService"; 038 039 private static final Log log = LogFactory.getLog(DocumentsListsService.class); 040 041 private Map<String, DocumentsListDescriptor> descriptors; 042 043 public DocumentsListDescriptor getDocumentsListDescriptor(String descriptorName) { 044 return descriptors.get(descriptorName); 045 } 046 047 public List<String> getDocumentsListDescriptorsName() { 048 List<String> list = new ArrayList<String>(); 049 for (String k : descriptors.keySet()) { 050 if (descriptors.get(k).getEnabled()) { 051 list.add(k); 052 } 053 } 054 return list; 055 } 056 057 @Override 058 public void activate(ComponentContext context) { 059 descriptors = new HashMap<String, DocumentsListDescriptor>(); 060 } 061 062 @Override 063 public void deactivate(ComponentContext context) { 064 descriptors = null; 065 } 066 067 private void mergeDescriptors(DocumentsListDescriptor newContrib) { 068 DocumentsListDescriptor oldDescriptor = descriptors.get(newContrib.getName()); 069 070 oldDescriptor.setEnabled(newContrib.getEnabled()); 071 if (newContrib.getCategory() != null) { 072 oldDescriptor.setCategory(newContrib.getCategory()); 073 } 074 oldDescriptor.setSupportAppends(newContrib.getSupportAppends()); 075 oldDescriptor.setDefaultInCategory(newContrib.getDefaultInCategory()); 076 oldDescriptor.setIsSession(newContrib.getIsSession()); 077 oldDescriptor.setPersistent(newContrib.getPersistent()); 078 oldDescriptor.setEvenstName(newContrib.getEventsName()); 079 if (newContrib.getImageURL() != null) { 080 oldDescriptor.setImageURL(newContrib.getImageURL()); 081 } 082 oldDescriptor.setReadOnly(oldDescriptor.getReadOnly()); 083 if (newContrib.getTitle() != null) { 084 oldDescriptor.setTitle(newContrib.getTitle()); 085 } 086 } 087 088 @Override 089 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 090 091 DocumentsListDescriptor descriptor = (DocumentsListDescriptor) contribution; 092 if (descriptors.containsKey(descriptor.getName())) { 093 mergeDescriptors(descriptor); 094 log.debug("merged DocumentsListDescriptor: " + descriptor.getName()); 095 } else { 096 descriptors.put(descriptor.getName(), descriptor); 097 log.debug("registered DocumentsListDescriptor: " + descriptor.getName()); 098 } 099 } 100 101 @Override 102 public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 103 104 DocumentsListDescriptor descriptor = (DocumentsListDescriptor) contribution; 105 descriptors.remove(descriptor.getName()); 106 log.debug("unregistered DocumentsListDescriptor: " + descriptor.getName()); 107 } 108 109}