001/*
002 * (C) Copyright 2011 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Anahide Tchertchian
016 */
017package org.nuxeo.theme.styling.service;
018
019import java.util.List;
020import java.util.Map;
021
022import org.nuxeo.ecm.web.resources.api.service.WebResourceManager;
023import org.nuxeo.theme.styling.service.descriptors.FlavorDescriptor;
024import org.nuxeo.theme.styling.service.descriptors.LogoDescriptor;
025import org.nuxeo.theme.styling.service.descriptors.PageDescriptor;
026
027/**
028 * Service handling the mapping between a page and its resources and flavors.
029 * <p>
030 * Registers some contributions to the {@link WebResourceManager} for compatibility.
031 *
032 * @see FlavorDescriptor
033 * @since 5.5
034 */
035public interface ThemeStylingService {
036
037    public static final String FLAVOR_MARKER = "__FLAVOR__";
038
039    public static final String PAGE_STYLE_CLASS_NAME_PREFIX = " CSS";
040
041    public static final String PAGE_STYLE_NAME_SUFFIX = " Page Styles";
042
043    public static enum PRESET_CATEGORY {
044        background, border, color, font;
045    }
046
047    /**
048     * Returns the default flavor for a given theme page
049     */
050    String getDefaultFlavorName(String themePage);
051
052    /**
053     * Returns the flavor names for a given theme page
054     */
055    List<String> getFlavorNames(String themePage);
056
057    /**
058     * Returns the flavors for a given theme page
059     */
060    List<FlavorDescriptor> getFlavors(String themePage);
061
062    /**
063     * Returns the flavor for given name, or null if not found.
064     * <p>
065     * If not defined on the local flavor, flavor attributes will be resolved from the extended flavor if any.
066     * </p>
067     *
068     * @param flavorName
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     * @param flavor
085     */
086    LogoDescriptor getLogo(String flavor);
087
088    /**
089     * Returns the page for given name.
090     * <p>
091     * Resources and bundles declared for all pages will also be attached to returned page.
092     *
093     * @since 7.4
094     */
095    PageDescriptor getPage(String name);
096
097    /**
098     * Rerurns all pages declared on the service, except the global one named "*".
099     * <p>
100     * Resources and bundles declared for all pages will also be attached to returned pages.
101     *
102     * @since 7.10
103     **/
104    List<PageDescriptor> getPages();
105
106    /**
107     * Returns the negotiated String value for given target variable.
108     * <p>
109     * Context can be dependent on the target variable, depending on how this method is called/used and corresponding
110     * negotiator implementations.
111     *
112     * @since 7.4
113     */
114    String negotiate(String target, Object context);
115
116}