001/* 002 * Copyright 2017 Anyware Services 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 */ 016package org.ametys.core.ui.widgets.richtext; 017 018import java.util.ArrayList; 019import java.util.Collections; 020import java.util.List; 021import java.util.Map; 022import java.util.Set; 023 024import org.apache.avalon.framework.service.ServiceException; 025import org.apache.avalon.framework.service.ServiceManager; 026import org.apache.avalon.framework.service.Serviceable; 027 028import org.ametys.core.ui.ClientSideElement; 029import org.ametys.runtime.plugin.component.PluginAware; 030 031/** 032 * This file imports extension will imports all files requires by validators and convertors from the {@link RichTextConfigurationExtensionPoint} 033 */ 034public class RichTextConfigurationFileImportsClientSideElement implements ClientSideElement, PluginAware, Serviceable 035{ 036 private RichTextConfigurationExtensionPoint _richTextConfigurationExtensionPoint; 037 private String _id; 038 private String _pluginName; 039 040 public void service(ServiceManager manager) throws ServiceException 041 { 042 _richTextConfigurationExtensionPoint = (RichTextConfigurationExtensionPoint) manager.lookup(RichTextConfigurationExtensionPoint.ROLE); 043 } 044 045 public void setPluginInfo(String pluginName, String featureName, String id) 046 { 047 _pluginName = pluginName; 048 _id = id; 049 } 050 051 public String getId() 052 { 053 return _id; 054 } 055 056 public List<Script> getScripts(Map<String, Object> contextParameters) 057 { 058 return getScripts(false, contextParameters); 059 } 060 061 public List<Script> getScripts(boolean ignoreRights, Map<String, Object> contextParameters) 062 { 063 List<Script> scripts = new ArrayList<>(); 064 065 for (String richTextConfigurationId : _richTextConfigurationExtensionPoint.getExtensionsIds()) 066 { 067 RichTextConfiguration richTextConfiguration = _richTextConfigurationExtensionPoint.getExtension(richTextConfigurationId); 068 for (String category : richTextConfiguration.getCategories()) 069 { 070 Set<ClientSideElement> convertors = richTextConfiguration.getConvertors(category, contextParameters); 071 if (convertors != null) 072 { 073 for (ClientSideElement convertor : convertors) 074 { 075 List<Script> scriptsToAdd = convertor.getScripts(contextParameters); 076 if (scriptsToAdd != null) 077 { 078 scripts.addAll(scriptsToAdd); 079 } 080 } 081 } 082 083 Set<ClientSideElement> validators = richTextConfiguration.getValidators(category, contextParameters); 084 if (validators != null) 085 { 086 for (ClientSideElement validator : validators) 087 { 088 List<Script> scriptsToAdd = validator.getScripts(contextParameters); 089 if (scriptsToAdd != null) 090 { 091 scripts.addAll(scriptsToAdd); 092 } 093 } 094 } 095 } 096 } 097 098 return scripts; 099 } 100 101 public Map<String, String> getRights(Map<String, Object> contextParameters) 102 { 103 return Collections.EMPTY_MAP; 104 } 105 106 public String getPluginName() 107 { 108 return _pluginName; 109 } 110 111 public Map<String, List<String>> getDependencies() 112 { 113 return Collections.EMPTY_MAP; 114 } 115 116}