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.web.source;
017
018import java.util.ArrayList;
019import java.util.List;
020
021import org.ametys.cms.source.ContentView;
022import org.ametys.cms.source.DefaultContentView;
023
024/**
025 * This implementation of a {@link ContentView} looks first in the directory skin://stylesheets/content/[cType]/[cType]-[view].[extension] then skin://stylesheets/content/[cType]/[cType].[extension] then defaults to {@link DefaultContentView}.
026 */
027public class WebContentView extends DefaultContentView
028{
029    @Override
030    protected List<String> _getDefaultSourceURIs(String pluginName, String formatSuffix, String extension)
031    {
032        List<String> result = new ArrayList<>();
033        if (!"web".equals(pluginName))
034        {
035            result.add("plugin:web://stylesheets/default-content" + formatSuffix + "." + extension);
036        }
037        
038        result.addAll(super._getDefaultSourceURIs(pluginName, formatSuffix, extension));
039        
040        return result;
041    }
042    
043    @Override
044    protected List<String> _getSourceURIsForDynamicContentType(String contentTypeAlias, String view, String formatSuffix, String pluginName, String extension)
045    {
046        ArrayList<String> result = new ArrayList<>();
047        
048        result.add("skin://stylesheets/content/" + contentTypeAlias + "/" + contentTypeAlias + formatSuffix + "-" + view + "." + extension);
049        result.add("skin://stylesheets/content/" + contentTypeAlias + "/" + contentTypeAlias + formatSuffix + "." + extension);
050        result.addAll(super._getSourceURIsForDynamicContentType(contentTypeAlias, view, formatSuffix, pluginName, extension));
051
052        return result;
053    }
054    
055    @Override
056    protected List<String> _getSourceURIsForContentType(String contentTypeAlias, String contentTypeId, String view, String formatSuffix, String extension)
057    {
058        ArrayList<String> result = new ArrayList<>();
059        
060        result.add("skin://stylesheets/content/" + contentTypeAlias + "/" + contentTypeAlias + formatSuffix + "-" + view + "." + extension);
061        result.add("skin://stylesheets/content/" + contentTypeAlias + "/" + contentTypeAlias + formatSuffix + "." + extension);
062        result.addAll(super._getSourceURIsForContentType(contentTypeAlias, contentTypeId, view, formatSuffix, extension));
063
064        return result;
065    }
066}