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    public static final String FLAVOR_MARKER = "__FLAVOR__";
040
041    public static final String PAGE_STYLE_CLASS_NAME_PREFIX = " CSS";
042
043    public static final String PAGE_STYLE_NAME_SUFFIX = " Page Styles";
044
045    public static 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     * @param flavorName
071     */
072    FlavorDescriptor getFlavor(String flavorName);
073
074    /**
075     * Returns the map of variable replacements for given flavor.
076     * <p>
077     * Returns an empty map if flavor is not resolved.
078     *
079     * @since 7.3
080     */
081    Map<String, String> getPresetVariables(String flavorName);
082
083    /**
084     * Returns the logo configured for given flavor name, and fallbacks on the extends flavor logo if not set.
085     *
086     * @param flavor
087     */
088    LogoDescriptor getLogo(String flavor);
089
090    /**
091     * Returns the page for given name.
092     * <p>
093     * Resources and bundles declared for all pages will also be attached to returned page.
094     *
095     * @since 7.4
096     */
097    PageDescriptor getPage(String name);
098
099    /**
100     * Rerurns all pages declared on the service, except the global one named "*".
101     * <p>
102     * Resources and bundles declared for all pages will also be attached to returned pages.
103     *
104     * @since 7.10
105     **/
106    List<PageDescriptor> getPages();
107
108    /**
109     * Returns the negotiated String value for given target variable.
110     * <p>
111     * Context can be dependent on the target variable, depending on how this method is called/used and corresponding
112     * negotiator implementations.
113     *
114     * @since 7.4
115     */
116    String negotiate(String target, Object context);
117
118}