Example usage for org.springframework.ui.context.support SimpleTheme SimpleTheme

List of usage examples for org.springframework.ui.context.support SimpleTheme SimpleTheme

Introduction

In this page you can find the example usage for org.springframework.ui.context.support SimpleTheme SimpleTheme.

Prototype

public SimpleTheme(String name, MessageSource messageSource) 

Source Link

Document

Create a SimpleTheme.

Usage

From source file:org.openmrs.web.StaticThemeSource.java

/**
 * @see org.springframework.ui.context.ThemeSource#getTheme(java.lang.String)
 *///w  w  w .  j a  v a 2 s  .  c o m
@Override
public Theme getTheme(String ignoredArgument) {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename(this.themeName);
    return new SimpleTheme(themeName, messageSource);
}

From source file:com.epam.cme.storefront.web.theme.CustomResourceBundleThemeSource.java

/**
 * This implementation returns a SimpleTheme instance, holding a ResourceBundle-based
 * MessageSource whose basename corresponds to the given site name (prefixed by the configured
 * "siteBasenamePrefix") which then delegates to a ResourceBundle-based MessageSource whose
 * basename corresponds to the theme name (prefixed by the configured "themeBasenamePrefix")
 * which in turn delegates to the {@link #getParentMessageSource()}.
 * //from   w w w . j  av  a 2  s  .c  o  m
 * <p>
 * SimpleTheme instances are cached per theme name.
 * 
 * <p>
 * Uses reloadable MessageSources to reflect changes to the underlying files. Set the
 * {@link #setCacheSeconds(int)} to control how long the files should be cached for.
 * 
 * @param themeName
 *            the theme name
 * @see #setSiteBasenamePrefix
 * @see #setThemeBasenamePrefix
 */
@Override
public Theme getTheme(final String themeName) {
    if (themeName == null) {
        return null;
    }

    synchronized (this.themeCache) {
        // Look for the theme in the cache
        {
            final Theme theme = this.themeCache.get(themeName);
            if (theme != null) {
                return theme;
            }
        }

        // Create the new theme

        // Split the theme name into site and theme parts
        final String[] strings = splitThemeName(themeName);
        final String uiExperiencePart = strings[0];
        final String sitePart = strings[1];
        final String themePart = strings[2];

        final String siteBasename = getSiteBasenamePrefix() + sitePart;
        final String themeBasename = getThemeBasenamePrefix() + themePart;
        final String uiExperienceCode = uiExperiencePart.toLowerCase();

        // Build the messages sources from most general to most specific
        final MessageSource themeMessageSource = createMessageSource(themeBasename, getParentMessageSource());
        final MessageSource themeUiExperienceMessageSource = createMessageSource(
                themeBasename + "-" + uiExperienceCode, themeMessageSource);
        final MessageSource siteMessageSource = createMessageSource(siteBasename,
                themeUiExperienceMessageSource);
        final MessageSource siteUiExperienceMessageSource = createMessageSource(
                siteBasename + "-" + uiExperienceCode, siteMessageSource);

        final Theme theme = new SimpleTheme(themeName, siteUiExperienceMessageSource);
        this.themeCache.put(themeName, theme);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Theme created: name '" + themeName + "', siteBasename [" + siteBasename
                    + "], themeBasename [" + themeBasename + "]");
        }
        return theme;
    }
}

From source file:com.acc.storefront.web.theme.StorefrontResourceBundleSource.java

/**
 * This implementation returns a SimpleTheme instance, holding a ResourceBundle-based MessageSource whose basename
 * corresponds to the given site name (prefixed by the configured "siteBasenamePrefix") which then delegates to a
 * ResourceBundle-based MessageSource whose basename corresponds to the theme name (prefixed by the configured
 * "themeBasenamePrefix") which in turn delegates to the {@link #getParentMessageSource()}.
 * /*from w ww  .j  a  v  a  2s  . c  om*/
 * <p>
 * SimpleTheme instances are cached per theme name.
 * 
 * <p>
 * Uses reloadable MessageSources to reflect changes to the underlying files. Set the {@link #setCacheSeconds(int)}
 * to control how long the files should be cached for.
 * 
 * @param themeName
 *           the theme name
 * @see #setSiteBasenamePrefix
 * @see #setThemeBasenamePrefix
 */
@Override
public Theme getTheme(final String themeName) {
    if (themeName == null) {
        return null;
    }

    synchronized (this.themeCache) {
        // Look for the theme in the cache
        {
            final Theme theme = this.themeCache.get(themeName);
            if (theme != null) {
                //return theme;
            }
        }

        // Split the theme name into site and theme parts
        final String[] strings = splitThemeName(themeName);
        final String uiExperiencePart = strings[0];
        final String sitePart = strings[1];
        final String themePart = strings[2];
        final String siteBasename = getBasenamePrefix() + getSitePrefix() + "-" + sitePart;
        final String themeBasename = getBasenamePrefix() + getThemePrefix() + "-" + themePart;
        final String uiExperienceCode = uiExperiencePart.toLowerCase();
        final List<String> addOnNames = requiredAddOnsNameProvider
                .getAddOns(getExtensionNameForWebroot(appContext));

        // Build the messages sources from most general to most specific
        final MessageSource addOnBaseMessageSrouce = createAddOnMessageSource(addOnNames,
                getParentMessageSource(), getBasePrefix());
        final MessageSource themeMessageSource = createMessageSource(themeBasename, addOnBaseMessageSrouce);
        final MessageSource addOnThemeMessageSource = createAddOnMessageSource(addOnNames, themeMessageSource,
                getThemePrefix(), themePart);
        final MessageSource themeUiExperienceMessageSource = createMessageSource(
                themeBasename + "-" + uiExperienceCode, addOnThemeMessageSource);
        final MessageSource addOnThemeUiMessageSource = createAddOnMessageSource(addOnNames,
                themeUiExperienceMessageSource, getThemePrefix(), themePart, uiExperienceCode);
        final MessageSource siteMessageSource = createMessageSource(siteBasename, addOnThemeUiMessageSource);
        final MessageSource addOnSiteMessageSource = createAddOnMessageSource(addOnNames, siteMessageSource,
                getSitePrefix(), sitePart);
        final MessageSource siteUiExperienceMessageSource = createMessageSource(
                siteBasename + "-" + uiExperienceCode, addOnSiteMessageSource);
        final MessageSource addOnSiteUiMessageSource = createAddOnMessageSource(addOnNames,
                siteUiExperienceMessageSource, getSitePrefix(), sitePart, uiExperienceCode);

        lastMessageSource = addOnSiteUiMessageSource;

        // Create the new theme
        final Theme theme = new SimpleTheme(themeName, addOnSiteUiMessageSource);
        this.themeCache.put(themeName, theme);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Theme created: name '" + themeName + "', iteBasename [" + siteBasename
                    + "], themeBasename [" + themeBasename + "]");
        }
        return theme;
    }
}

From source file:com.exxonmobile.ace.hybris.storefront.web.theme.StorefrontResourceBundleSource.java

/**
 * This implementation returns a SimpleTheme instance, holding a ResourceBundle-based MessageSource whose basename
 * corresponds to the given site name (prefixed by the configured "siteBasenamePrefix") which then delegates to a
 * ResourceBundle-based MessageSource whose basename corresponds to the theme name (prefixed by the configured
 * "themeBasenamePrefix") which in turn delegates to the {@link #getParentMessageSource()}.
 * /* w  w  w  .  ja  v a 2s.c  o m*/
 * <p>
 * SimpleTheme instances are cached per theme name.
 * 
 * <p>
 * Uses reloadable MessageSources to reflect changes to the underlying files. Set the {@link #setCacheSeconds(int)}
 * to control how long the files should be cached for.
 * 
 * @param themeName
 *           the theme name
 * @see #setSiteBasenamePrefix
 * @see #setThemeBasenamePrefix
 */
@Override
public Theme getTheme(final String themeName) {
    if (themeName == null) {
        return null;
    }

    synchronized (this.themeCache) {
        // Look for the theme in the cache
        {
            final Theme theme = this.themeCache.get(themeName);
            if (theme != null) {
                return theme;
            }
        }

        // Split the theme name into site and theme parts
        final String[] strings = splitThemeName(themeName);
        final String uiExperiencePart = strings[0];
        final String sitePart = strings[1];
        final String themePart = strings[2];
        final String siteBasename = getBasenamePrefix() + getSitePrefix() + "-" + sitePart;
        final String themeBasename = getBasenamePrefix() + getThemePrefix() + "-" + themePart;
        final String uiExperienceCode = uiExperiencePart.toLowerCase();
        final List<String> addOnNames = requiredAddOnsNameProvider
                .getAddOns(getExtensionNameForWebroot(appContext));

        // Build the messages sources from most general to most specific
        final MessageSource addOnBaseMessageSrouce = createAddOnMessageSource(addOnNames,
                getParentMessageSource(), getBasePrefix());
        final MessageSource themeMessageSource = createMessageSource(themeBasename, addOnBaseMessageSrouce);
        final MessageSource addOnThemeMessageSource = createAddOnMessageSource(addOnNames, themeMessageSource,
                getThemePrefix(), themePart);
        final MessageSource themeUiExperienceMessageSource = createMessageSource(
                themeBasename + "-" + uiExperienceCode, addOnThemeMessageSource);
        final MessageSource addOnThemeUiMessageSource = createAddOnMessageSource(addOnNames,
                themeUiExperienceMessageSource, getThemePrefix(), themePart, uiExperienceCode);
        final MessageSource siteMessageSource = createMessageSource(siteBasename, addOnThemeUiMessageSource);
        final MessageSource addOnSiteMessageSource = createAddOnMessageSource(addOnNames, siteMessageSource,
                getSitePrefix(), sitePart);
        final MessageSource siteUiExperienceMessageSource = createMessageSource(
                siteBasename + "-" + uiExperienceCode, addOnSiteMessageSource);
        final MessageSource addOnSiteUiMessageSource = createAddOnMessageSource(addOnNames,
                siteUiExperienceMessageSource, getSitePrefix(), sitePart, uiExperienceCode);

        lastMessageSource = addOnSiteUiMessageSource;

        // Create the new theme
        final Theme theme = new SimpleTheme(themeName, addOnSiteUiMessageSource);
        this.themeCache.put(themeName, theme);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Theme created: name '" + themeName + "', iteBasename [" + siteBasename
                    + "], themeBasename [" + themeBasename + "]");
        }
        return theme;
    }
}

From source file:com.jnj.b2b.storefront.web.theme.StorefrontResourceBundleSource.java

/**
 * This implementation returns a SimpleTheme instance, holding a ResourceBundle-based MessageSource whose basename
 * corresponds to the given site name (prefixed by the configured "siteBasenamePrefix") which then delegates to a
 * ResourceBundle-based MessageSource whose basename corresponds to the theme name (prefixed by the configured
 * "themeBasenamePrefix") which in turn delegates to the {@link #getParentMessageSource()}.
 * // w ww.  jav  a2 s  . co  m
 * <p>
 * SimpleTheme instances are cached per theme name.
 * 
 * <p>
 * Uses reloadable MessageSources to reflect changes to the underlying files. Set the {@link #setCacheSeconds(int)}
 * to control how long the files should be cached for.
 * 
 * @param themeName
 *           the theme name
 * @see #setSiteBasenamePrefix
 * @see #setThemeBasenamePrefix
 */
@Override
public Theme getTheme(final String themeName) {
    if (themeName == null) {
        return null;
    }

    synchronized (this.themeCache) {
        // Look for the theme in the cache
        {
            final Theme theme = this.themeCache.get(themeName);
            if (theme != null) {
                return theme;
            }
        }

        // Split the theme name into site and theme parts
        final String[] strings = splitThemeName(themeName);
        final String uiExperiencePart = strings[0];
        final String sitePart = strings[1];
        final String themePart = strings[2];
        final String siteBasename = getBasenamePrefix() + getSitePrefix() + "-" + sitePart;
        final String themeBasename = getBasenamePrefix() + getThemePrefix() + "-" + themePart;
        final String uiExperienceCode = uiExperiencePart.toLowerCase();
        final List<String> addOnNames = requiredAddOnsNameProvider
                .getAddOns(StringUtils.remove(appContext.getApplicationName(), "/"));

        // Build the messages sources from most general to most specific
        final MessageSource addOnBaseMessageSrouce = createAddOnMessageSource(addOnNames,
                getParentMessageSource(), getBasePrefix());
        final MessageSource themeMessageSource = createMessageSource(themeBasename, addOnBaseMessageSrouce);
        final MessageSource addOnThemeMessageSource = createAddOnMessageSource(addOnNames, themeMessageSource,
                getThemePrefix(), themePart);
        final MessageSource themeUiExperienceMessageSource = createMessageSource(
                themeBasename + "-" + uiExperienceCode, addOnThemeMessageSource);
        final MessageSource addOnThemeUiMessageSource = createAddOnMessageSource(addOnNames,
                themeUiExperienceMessageSource, getThemePrefix(), themePart, uiExperienceCode);
        final MessageSource siteMessageSource = createMessageSource(siteBasename, addOnThemeUiMessageSource);
        final MessageSource addOnSiteMessageSource = createAddOnMessageSource(addOnNames, siteMessageSource,
                getSitePrefix(), sitePart);
        final MessageSource siteUiExperienceMessageSource = createMessageSource(
                siteBasename + "-" + uiExperienceCode, addOnSiteMessageSource);
        final MessageSource addOnSiteUiMessageSource = createAddOnMessageSource(addOnNames,
                siteUiExperienceMessageSource, getSitePrefix(), sitePart, uiExperienceCode);

        lastMessageSource = addOnSiteUiMessageSource;

        // Create the new theme
        final Theme theme = new SimpleTheme(themeName, addOnSiteUiMessageSource);
        this.themeCache.put(themeName, theme);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Theme created: name '" + themeName + "', iteBasename [" + siteBasename
                    + "], themeBasename [" + themeBasename + "]");
        }
        return theme;
    }
}

From source file:org.springframework.ui.context.support.ResourceBundleThemeSource.java

/**
 * This implementation returns a SimpleTheme instance, holding a
 * ResourceBundle-based MessageSource whose basename corresponds to
 * the given theme name (prefixed by the configured "basenamePrefix").
 * <p>SimpleTheme instances are cached per theme name. Use a reloadable
 * MessageSource if themes should reflect changes to the underlying files.
 * @see #setBasenamePrefix/*ww  w.  ja v a 2 s.co m*/
 * @see #createMessageSource
 */
@Override
@Nullable
public Theme getTheme(String themeName) {
    Theme theme = this.themeCache.get(themeName);
    if (theme == null) {
        synchronized (this.themeCache) {
            theme = this.themeCache.get(themeName);
            if (theme == null) {
                String basename = this.basenamePrefix + themeName;
                MessageSource messageSource = createMessageSource(basename);
                theme = new SimpleTheme(themeName, messageSource);
                initParent(theme);
                this.themeCache.put(themeName, theme);
                if (logger.isDebugEnabled()) {
                    logger.debug("Theme created: name '" + themeName + "', basename [" + basename + "]");
                }
            }
        }
    }
    return theme;
}