001/*
002 * (C) Copyright 2011 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 *     Anahide Tchertchian
018 */
019package org.nuxeo.theme.styling.service;
020
021import java.util.List;
022import java.util.Map;
023
024import org.nuxeo.ecm.web.resources.api.service.WebResourceManager;
025import org.nuxeo.theme.styling.service.descriptors.FlavorDescriptor;
026import org.nuxeo.theme.styling.service.descriptors.LogoDescriptor;
027import org.nuxeo.theme.styling.service.descriptors.PageDescriptor;
028
029/**
030 * Service handling the mapping between a page and its resources and flavors.
031 * <p>
032 * Registers some contributions to the {@link WebResourceManager} for compatibility.
033 *
034 * @see FlavorDescriptor
035 * @since 5.5
036 */
037public interface ThemeStylingService {
038
039    String FLAVOR_MARKER = "__FLAVOR__";
040
041    String PAGE_STYLE_CLASS_NAME_PREFIX = " CSS";
042
043    String PAGE_STYLE_NAME_SUFFIX = " Page Styles";
044
045    public enum PRESET_CATEGORY {
046        background, border, color, font;
047    }
048
049    /**
050     * Returns the default flavor for a given theme page
051     */
052    String getDefaultFlavorName(String themePage);
053
054    /**
055     * Returns the flavor names for a given theme page
056     */
057    List<String> getFlavorNames(String themePage);
058
059    /**
060     * Returns the flavors for a given theme page
061     */
062    List<FlavorDescriptor> getFlavors(String themePage);
063
064    /**
065     * Returns the flavor for given name, or null if not found.
066     * <p>
067     * If not defined on the local flavor, flavor attributes will be resolved from the extended flavor if any.
068     * </p>
069     */
070    FlavorDescriptor getFlavor(String flavorName);
071
072    /**
073     * Returns the map of variable replacements for given flavor.
074     * <p>
075     * Returns an empty map if flavor is not resolved.
076     *
077     * @since 7.3
078     */
079    Map<String, String> getPresetVariables(String flavorName);
080
081    /**
082     * Returns the logo configured for given flavor name, and fallbacks on the extends flavor logo if not set.
083     */
084    LogoDescriptor getLogo(String flavor);
085
086    /**
087     * Returns the page for given name.
088     * <p>
089     * Resources and bundles declared for all pages will also be attached to returned page.
090     *
091     * @since 7.4
092     */
093    PageDescriptor getPage(String name);
094
095    /**
096     * Rerurns all pages declared on the service, except the global one named "*".
097     * <p>
098     * Resources and bundles declared for all pages will also be attached to returned pages.
099     *
100     * @since 7.10
101     **/
102    List<PageDescriptor> getPages();
103
104    /**
105     * Returns the negotiated String value for given target variable.
106     * <p>
107     * Context can be dependent on the target variable, depending on how this method is called/used and corresponding
108     * negotiator implementations.
109     *
110     * @since 7.4
111     */
112    String negotiate(String target, Object context);
113
114}