Remove deprecated ThemeResolver support

See gh-33809
This commit is contained in:
rstoyanchev
2025-01-14 15:26:44 +00:00
parent 9ddbf800b9
commit 9f77d5ff1f
54 changed files with 39 additions and 2163 deletions

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.context;
import org.jspecify.annotations.Nullable;
/**
* Sub-interface of ThemeSource to be implemented by objects that
* can resolve theme messages hierarchically.
*
* @author Jean-Pierre Pawlak
* @author Juergen Hoeller
* @deprecated as of 6.0 in favor of using CSS, without direct replacement
*/
@Deprecated(since = "6.0")
public interface HierarchicalThemeSource extends ThemeSource {
/**
* Set the parent that will be used to try to resolve theme messages
* that this object can't resolve.
* @param parent the parent ThemeSource that will be used to
* resolve messages that this object can't resolve.
* May be {@code null}, in which case no further resolution is possible.
*/
void setParentThemeSource(@Nullable ThemeSource parent);
/**
* Return the parent of this ThemeSource, or {@code null} if none.
*/
@Nullable ThemeSource getParentThemeSource();
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.context;
import org.springframework.context.MessageSource;
/**
* A Theme can resolve theme-specific messages, codes, file paths, etc.
* (e.g. CSS and image files in a web environment).
* The exposed {@link org.springframework.context.MessageSource} supports
* theme-specific parameterization and internationalization.
*
* @author Juergen Hoeller
* @since 17.06.2003
* @see ThemeSource
* @see org.springframework.web.servlet.ThemeResolver
* @deprecated as of 6.0 in favor of using CSS, without direct replacement
*/
@Deprecated(since = "6.0")
public interface Theme {
/**
* Return the name of the theme.
* @return the name of the theme (never {@code null})
*/
String getName();
/**
* Return the specific MessageSource that resolves messages
* with respect to this theme.
* @return the theme-specific MessageSource (never {@code null})
*/
MessageSource getMessageSource();
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.context;
import org.jspecify.annotations.Nullable;
/**
* Interface to be implemented by objects that can resolve {@link Theme Themes}.
* This enables parameterization and internationalization of messages
* for a given 'theme'.
*
* @author Jean-Pierre Pawlak
* @author Juergen Hoeller
* @see Theme
* @deprecated as of 6.0 in favor of using CSS, without direct replacement
*/
@Deprecated(since = "6.0")
public interface ThemeSource {
/**
* Return the Theme instance for the given theme name.
* <p>The returned Theme will resolve theme-specific messages, codes,
* file paths, etc (for example, CSS and image files in a web environment).
* @param themeName the name of the theme
* @return the corresponding Theme, or {@code null} if none defined.
* Note that, by convention, a ThemeSource should at least be able to
* return a default Theme for the default theme name "theme" but may also
* return default Themes for other theme names.
* @see org.springframework.web.servlet.theme.AbstractThemeResolver#ORIGINAL_DEFAULT_THEME_NAME
*/
@Nullable Theme getTheme(String themeName);
}

View File

@@ -1,8 +0,0 @@
/**
* Contains classes defining the application context subinterface
* for UI applications. The theme feature is added here.
*/
@NullMarked
package org.springframework.ui.context;
import org.jspecify.annotations.NullMarked;

View File

@@ -1,64 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.context.support;
import org.jspecify.annotations.Nullable;
import org.springframework.ui.context.HierarchicalThemeSource;
import org.springframework.ui.context.Theme;
import org.springframework.ui.context.ThemeSource;
/**
* Empty ThemeSource that delegates all calls to the parent ThemeSource.
* If no parent is available, it simply won't resolve any theme.
*
* <p>Used as placeholder by UiApplicationContextUtils, if a context doesn't
* define its own ThemeSource. Not intended for direct use in applications.
*
* @author Juergen Hoeller
* @since 1.2.4
* @see UiApplicationContextUtils
* @deprecated as of 6.0 in favor of using CSS, without direct replacement
*/
@Deprecated(since = "6.0")
public class DelegatingThemeSource implements HierarchicalThemeSource {
private @Nullable ThemeSource parentThemeSource;
@Override
public void setParentThemeSource(@Nullable ThemeSource parentThemeSource) {
this.parentThemeSource = parentThemeSource;
}
@Override
public @Nullable ThemeSource getParentThemeSource() {
return this.parentThemeSource;
}
@Override
public @Nullable Theme getTheme(String themeName) {
if (this.parentThemeSource != null) {
return this.parentThemeSource.getTheme(themeName);
}
else {
return null;
}
}
}

View File

@@ -1,198 +0,0 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.context.support;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.context.HierarchicalMessageSource;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.ui.context.HierarchicalThemeSource;
import org.springframework.ui.context.Theme;
import org.springframework.ui.context.ThemeSource;
/**
* {@link ThemeSource} implementation that looks up an individual
* {@link java.util.ResourceBundle} per theme. The theme name gets
* interpreted as ResourceBundle basename, supporting a common
* basename prefix for all themes.
*
* @author Jean-Pierre Pawlak
* @author Juergen Hoeller
* @see #setBasenamePrefix
* @see java.util.ResourceBundle
* @see org.springframework.context.support.ResourceBundleMessageSource
* @deprecated as of 6.0 in favor of using CSS, without direct replacement
*/
@Deprecated(since = "6.0")
public class ResourceBundleThemeSource implements HierarchicalThemeSource, BeanClassLoaderAware {
protected final Log logger = LogFactory.getLog(getClass());
private @Nullable ThemeSource parentThemeSource;
private String basenamePrefix = "";
private @Nullable String defaultEncoding;
private @Nullable Boolean fallbackToSystemLocale;
private @Nullable ClassLoader beanClassLoader;
/** Map from theme name to Theme instance. */
private final Map<String, Theme> themeCache = new ConcurrentHashMap<>();
@Override
public void setParentThemeSource(@Nullable ThemeSource parent) {
this.parentThemeSource = parent;
// Update existing Theme objects.
// Usually there shouldn't be any at the time of this call.
synchronized (this.themeCache) {
for (Theme theme : this.themeCache.values()) {
initParent(theme);
}
}
}
@Override
public @Nullable ThemeSource getParentThemeSource() {
return this.parentThemeSource;
}
/**
* Set the prefix that gets applied to the ResourceBundle basenames,
* i.e. the theme names.
* For example: basenamePrefix="test.", themeName="theme" &rarr; basename="test.theme".
* <p>Note that ResourceBundle names are effectively classpath locations: As a
* consequence, the JDK's standard ResourceBundle treats dots as package separators.
* This means that "test.theme" is effectively equivalent to "test/theme",
* just like it is for programmatic {@code java.util.ResourceBundle} usage.
* @see java.util.ResourceBundle#getBundle(String)
*/
public void setBasenamePrefix(@Nullable String basenamePrefix) {
this.basenamePrefix = (basenamePrefix != null ? basenamePrefix : "");
}
/**
* Set the default charset to use for parsing resource bundle files.
* <p>{@link ResourceBundleMessageSource}'s default is the
* {@code java.util.ResourceBundle} default encoding: ISO-8859-1.
* @since 4.2
* @see ResourceBundleMessageSource#setDefaultEncoding
*/
public void setDefaultEncoding(@Nullable String defaultEncoding) {
this.defaultEncoding = defaultEncoding;
}
/**
* Set whether to fall back to the system Locale if no files for a
* specific Locale have been found.
* <p>{@link ResourceBundleMessageSource}'s default is "true".
* @since 4.2
* @see ResourceBundleMessageSource#setFallbackToSystemLocale
*/
public void setFallbackToSystemLocale(boolean fallbackToSystemLocale) {
this.fallbackToSystemLocale = fallbackToSystemLocale;
}
@Override
public void setBeanClassLoader(@Nullable ClassLoader beanClassLoader) {
this.beanClassLoader = beanClassLoader;
}
/**
* 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
* @see #createMessageSource
*/
@Override
public @Nullable 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;
}
/**
* Create a MessageSource for the given basename,
* to be used as MessageSource for the corresponding theme.
* <p>Default implementation creates a ResourceBundleMessageSource.
* for the given basename. A subclass could create a specifically
* configured ReloadableResourceBundleMessageSource, for example.
* @param basename the basename to create a MessageSource for
* @return the MessageSource
* @see org.springframework.context.support.ResourceBundleMessageSource
* @see org.springframework.context.support.ReloadableResourceBundleMessageSource
*/
protected MessageSource createMessageSource(String basename) {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(basename);
if (this.defaultEncoding != null) {
messageSource.setDefaultEncoding(this.defaultEncoding);
}
if (this.fallbackToSystemLocale != null) {
messageSource.setFallbackToSystemLocale(this.fallbackToSystemLocale);
}
if (this.beanClassLoader != null) {
messageSource.setBeanClassLoader(this.beanClassLoader);
}
return messageSource;
}
/**
* Initialize the MessageSource of the given theme with the
* one from the corresponding parent of this ThemeSource.
* @param theme the Theme to (re-)initialize
*/
protected void initParent(Theme theme) {
if (theme.getMessageSource() instanceof HierarchicalMessageSource messageSource) {
if (getParentThemeSource() != null && messageSource.getParentMessageSource() == null) {
Theme parentTheme = getParentThemeSource().getTheme(theme.getName());
if (parentTheme != null) {
messageSource.setParentMessageSource(parentTheme.getMessageSource());
}
}
}
}
}

View File

@@ -1,62 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.context.support;
import org.springframework.context.MessageSource;
import org.springframework.ui.context.Theme;
import org.springframework.util.Assert;
/**
* Default {@link Theme} implementation, wrapping a name and an
* underlying {@link org.springframework.context.MessageSource}.
*
* @author Juergen Hoeller
* @since 17.06.2003
* @deprecated as of 6.0 in favor of using CSS, without direct replacement
*/
@Deprecated(since = "6.0")
public class SimpleTheme implements Theme {
private final String name;
private final MessageSource messageSource;
/**
* Create a SimpleTheme.
* @param name the name of the theme
* @param messageSource the MessageSource that resolves theme messages
*/
public SimpleTheme(String name, MessageSource messageSource) {
Assert.notNull(name, "Name must not be null");
Assert.notNull(messageSource, "MessageSource must not be null");
this.name = name;
this.messageSource = messageSource;
}
@Override
public final String getName() {
return this.name;
}
@Override
public final MessageSource getMessageSource() {
return this.messageSource;
}
}

View File

@@ -1,93 +0,0 @@
/*
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ui.context.support;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.ui.context.HierarchicalThemeSource;
import org.springframework.ui.context.ThemeSource;
/**
* Utility class for UI application context implementations.
* Provides support for a special bean named "themeSource",
* of type {@link org.springframework.ui.context.ThemeSource}.
*
* @author Jean-Pierre Pawlak
* @author Juergen Hoeller
* @since 17.06.2003
* @deprecated as of 6.0 in favor of using CSS, without direct replacement
*/
@Deprecated(since = "6.0")
public abstract class UiApplicationContextUtils {
/**
* Name of the ThemeSource bean in the factory.
* If none is supplied, theme resolution is delegated to the parent.
* @see org.springframework.ui.context.ThemeSource
*/
public static final String THEME_SOURCE_BEAN_NAME = "themeSource";
private static final Log logger = LogFactory.getLog(UiApplicationContextUtils.class);
/**
* Initialize the ThemeSource for the given application context,
* autodetecting a bean with the name "themeSource". If no such
* bean is found, a default (empty) ThemeSource will be used.
* @param context current application context
* @return the initialized theme source (will never be {@code null})
* @see #THEME_SOURCE_BEAN_NAME
*/
public static ThemeSource initThemeSource(ApplicationContext context) {
if (context.containsLocalBean(THEME_SOURCE_BEAN_NAME)) {
ThemeSource themeSource = context.getBean(THEME_SOURCE_BEAN_NAME, ThemeSource.class);
// Make ThemeSource aware of parent ThemeSource.
if (context.getParent() instanceof ThemeSource pts && themeSource instanceof HierarchicalThemeSource hts) {
if (hts.getParentThemeSource() == null) {
// Only set parent context as parent ThemeSource if no parent ThemeSource
// registered already.
hts.setParentThemeSource(pts);
}
}
if (logger.isDebugEnabled()) {
logger.debug("Using ThemeSource [" + themeSource + "]");
}
return themeSource;
}
else {
// Use default ThemeSource to be able to accept getTheme calls, either
// delegating to parent context's default or to local ResourceBundleThemeSource.
HierarchicalThemeSource themeSource = null;
if (context.getParent() instanceof ThemeSource pts) {
themeSource = new DelegatingThemeSource();
themeSource.setParentThemeSource(pts);
}
else {
themeSource = new ResourceBundleThemeSource();
}
if (logger.isDebugEnabled()) {
logger.debug("Unable to locate ThemeSource with name '" + THEME_SOURCE_BEAN_NAME +
"': using default [" + themeSource + "]");
}
return themeSource;
}
}
}

View File

@@ -1,8 +0,0 @@
/**
* Classes supporting the org.springframework.ui.context package.
* Provides support classes for specialized UI contexts, for example, for web UIs.
*/
@NullMarked
package org.springframework.ui.context.support;
import org.jspecify.annotations.NullMarked;