001/*
002 *  Copyright 2010 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.cms.clientsideelement.styles;
017
018import java.util.ArrayList;
019import java.util.LinkedHashSet;
020import java.util.List;
021import java.util.Map;
022import java.util.Set;
023
024import org.ametys.core.ui.ClientSideElement.ScriptFile;
025
026/**
027 * This extension point allows to determine which styles does exist for html edition 
028 */
029public interface HTMLEditorStyleExtensionPoint
030{
031    /** Avalon role name */
032    public static final String ROLE = HTMLEditorStyleExtensionPoint.class.getName();
033    
034    /**
035     * Get the list of styles for paragraphs
036     * @param contextualParameters Contextuals parameters transmitted by the environment.
037     * @return A category. Can be null.
038     */
039    public StyleCategory getPara(Map<String, Object> contextualParameters);
040    
041    /**
042     * Get the list of styles for tables
043     * @param contextualParameters Contextuals parameters transmitted by the environment.
044     * @return A category. Can be null.
045     */
046    public StyleCategory getTable(Map<String, Object> contextualParameters);
047    
048    /**
049     * Get the list of styles for link
050     * @param contextualParameters Contextuals parameters transmitted by the environment.
051     * @return A category. Can be null.
052     */
053    public StyleCategory getLink(Map<String, Object> contextualParameters);
054    
055    /**
056     * Get the list of styles for images
057     * @param contextualParameters Contextuals parameters transmitted by the environment.
058     * @return A category. Can be null.
059     */
060    public StyleCategory getImage(Map<String, Object> contextualParameters);
061    
062    /**
063     * Get the list of styles for unordered lists
064     * @param contextualParameters Contextuals parameters transmitted by the environment.
065     * @return A category. Can be null.
066     */
067    public StyleCategory getUnorderedList(Map<String, Object> contextualParameters);
068    
069    /**
070     * Get the list of styles for ordered lists
071     * @param contextualParameters Contextuals parameters transmitted by the environment.
072     * @return A category. Can be null.
073     */
074    public StyleCategory getOrderedList(Map<String, Object> contextualParameters);
075    
076    /**
077     * Get the aggregation of all backoffice css files
078     * @param contextParameters The contextual parameters
079     * @return A non null list of ScriptFile
080     */
081    public default List<ScriptFile> getBackOfficeCSSFiles(Map<String, Object> contextParameters)
082    {
083        List<ScriptFile> cssFiles = new ArrayList<>();
084        
085        List<StyleCategory> styleCategories = new ArrayList<>();
086        styleCategories.add(getImage(contextParameters));
087        styleCategories.add(getLink(contextParameters));
088        styleCategories.add(getOrderedList(contextParameters));
089        styleCategories.add(getPara(contextParameters));
090        styleCategories.add(getTable(contextParameters));
091        styleCategories.add(getUnorderedList(contextParameters));
092        
093        Set<String> filesAsString = new LinkedHashSet<>();
094        for (StyleCategory styleCategory : styleCategories)
095        {
096            if (styleCategory != null)
097            {
098                filesAsString.addAll(styleCategory.getBackOfficeCSSFiles());
099            }
100        }
101        filesAsString.remove(null);
102        
103        for (String fileAsString : filesAsString)
104        {
105            cssFiles.add(new ScriptFile(fileAsString));
106        }
107        
108        return cssFiles;
109    }
110    
111    /**
112     * Get the aggregation of all inline editor css files
113     * @param contextParameters The contextual parameters
114     * @return A non null list of ScriptFile
115     */
116    public default List<ScriptFile> getInlineEditorCSSFiles(Map<String, Object> contextParameters)
117    {
118        List<ScriptFile> cssFiles = new ArrayList<>();
119        
120        List<StyleCategory> styleCategories = new ArrayList<>();
121        styleCategories.add(getImage(contextParameters));
122        styleCategories.add(getLink(contextParameters));
123        styleCategories.add(getOrderedList(contextParameters));
124        styleCategories.add(getPara(contextParameters));
125        styleCategories.add(getTable(contextParameters));
126        styleCategories.add(getUnorderedList(contextParameters));
127        
128        Set<String> filesAsString = new LinkedHashSet<>();
129        for (StyleCategory styleCategory : styleCategories)
130        {
131            if (styleCategory != null)
132            {
133                filesAsString.addAll(styleCategory.getInlineEditorCSSFiles());
134            }
135        }
136        filesAsString.remove(null);
137        
138        for (String fileAsString : filesAsString)
139        {
140            cssFiles.add(new ScriptFile(fileAsString));
141        }
142        
143        return cssFiles;
144    }
145}