001/* 002 * (C) Copyright 2007-2016 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 */ 019package org.nuxeo.ecm.webapp.directory; 020 021import java.util.List; 022 023import org.nuxeo.ecm.platform.actions.ActionService; 024import org.nuxeo.runtime.api.Framework; 025import org.nuxeo.runtime.model.ComponentContext; 026import org.nuxeo.runtime.model.ComponentInstance; 027import org.nuxeo.runtime.model.DefaultComponent; 028 029/** 030 * Register directory tree configurations to make them available to the DirectoryTreeManagerBean to build 031 * DirectoryTreeNode instances. 032 * 033 * @author <a href="mailto:[email protected]">Olivier Grisel</a> 034 */ 035public class DirectoryTreeService extends DefaultComponent { 036 037 public static final String NAME = DirectoryTreeService.class.getName(); 038 039 protected DirectoryTreeRegistry registry; 040 041 public DirectoryTreeDescriptor getDirectoryTreeDescriptor(String treeName) { 042 return registry.getDirectoryTreeDescriptor(treeName); 043 } 044 045 @Override 046 public void activate(ComponentContext context) { 047 registry = new DirectoryTreeRegistry(); 048 } 049 050 @Override 051 public void deactivate(ComponentContext context) { 052 registry = null; 053 } 054 055 @Override 056 public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 057 DirectoryTreeDescriptor descriptor = (DirectoryTreeDescriptor) contribution; 058 registry.addContribution(descriptor); 059 getActionService().addAction(descriptor.getAction()); 060 } 061 062 @Override 063 public void unregisterContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { 064 DirectoryTreeDescriptor descriptor = (DirectoryTreeDescriptor) contribution; 065 registry.removeContribution(descriptor); 066 getActionService().removeAction(descriptor.getAction().getId()); 067 } 068 069 /** 070 * @since 6.0 071 */ 072 protected ActionService getActionService() { 073 return (ActionService) Framework.getRuntime().getComponent(ActionService.ID); 074 } 075 076 public List<String> getDirectoryTrees() { 077 return registry.getDirectoryTrees(); 078 } 079 080 /** 081 * Returns only the enabled Directory Trees marked as being also Navigation Trees. 082 * 083 * @since 5.4 084 */ 085 public List<String> getNavigationDirectoryTrees() { 086 return registry.getNavigationDirectoryTrees(); 087 } 088 089}