001/*
002 *  Copyright 2025 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.content;
017
018import org.ametys.cms.repository.Content;
019import org.ametys.runtime.model.View;
020
021/**
022 * Component responsible to retrieve the view of a content
023 */
024public interface ContentViewProvider
025{
026    /** Avalon Role */
027    public static final String ROLE = ContentViewProvider.class.getName();
028    
029    /**
030     * Get the view for view resulting of the concatenation of views of the given content.
031     * @param viewName the name of the view to retrieve
032     * @param content the given content
033     * @return The view or null if none matches.
034     */
035    public default View getView(String viewName, Content content)
036    {
037        return getView(viewName, content.getTypes(), content.getMixinTypes());
038    }
039    
040    /**
041     * Get the view for view resulting of the concatenation of views of the given content.
042     * @param viewName the name of the view to retrieve
043     * @param contentTypeIds the identifiers of the content types
044     * @param mixinIds the identifiers of the mixins
045     * @return The view or null if none matches.
046     */
047    public View getView(String viewName, String[] contentTypeIds, String[] mixinIds);
048    
049    /**
050     * Get the view for view resulting for a given content
051     * @param viewName the name of the view to retrieve. If null or empty, fallback view will be used.
052     * @param fallbackViewName the name of the view to retrieve if the initial was not found. If null or empty, "main" view view will be used as fallback view.
053     * @param content the content
054     * @return The view or null if none matches.
055     */
056    public default View getViewWithFallback(String viewName, String fallbackViewName, Content content)
057    {
058        return getViewWithFallback(viewName, fallbackViewName, content.getTypes(), content.getMixinTypes());
059    }
060    
061    /**
062     * Get the view for view resulting for a given content
063     * @param viewName the name of the view to retrieve. If null or empty, fallback view will be used.
064     * @param fallbackViewName the name of the view to retrieve if the initial was not found. If null or empty, "main" view view will be used as fallback view.
065     * @param contentTypeIds the identifiers of the content types
066     * @param mixinIds the identifiers of the mixins
067     * @return The view or null if none matches.
068     */
069    public View getViewWithFallback(String viewName, String fallbackViewName, String[] contentTypeIds, String[] mixinIds);
070}