Several small bug fixes

master
Jens Pelzetter 2023-05-13 17:55:18 +02:00
parent 06922b6425
commit 7e023cfaa9
4 changed files with 126 additions and 118 deletions

View File

@ -713,7 +713,7 @@ public class PagesController {
private String buildQueryParamsStr( private String buildQueryParamsStr(
final String previewParam, final String themeParam final String previewParam, final String themeParam
) { ) {
return List final String queryString = List
.of( .of(
Optional Optional
.of(themeParam) .of(themeParam)
@ -729,6 +729,12 @@ public class PagesController {
.stream() .stream()
.filter(String::isBlank) .filter(String::isBlank)
.collect(Collectors.joining("&", "?", "")); .collect(Collectors.joining("&", "?", ""));
if (queryString.length() <= 1) {
return "";
}
return queryString;
} }
private ThemeInfo getTheme( private ThemeInfo getTheme(

View File

@ -95,6 +95,9 @@ public class PageUrlModel {
} }
public String getQueryString() { public String getQueryString() {
if (queryParameters == null || queryParameters.isEmpty()) {
return "";
}
return queryParameters return queryParameters
.entrySet() .entrySet()
.stream() .stream()

View File

@ -99,50 +99,41 @@ public class StaticThemeProvider implements ThemeProvider {
@Override @Override
public List<ThemeInfo> getThemes() { public List<ThemeInfo> getThemes() {
LOGGER.debug("Retrieving static themes..."); LOGGER.debug("Retrieving static themes...");
final Reflections reflections = new Reflections( final Reflections reflections = new Reflections(
new ConfigurationBuilder() new ConfigurationBuilder()
.setUrls(ClasspathHelper.forPackage("")) .setUrls(ClasspathHelper.forPackage(""))
.setScanners(new ResourcesScanner() .setScanners(new ResourcesScanner())
// .filterResultsBy(new FilterBuilder() );
// .include(THEMES_PACKAGE)
// .include(THEMES_PACKAGE + "/([\\w\\d\\s\\.]*)/theme.json")
// .include(THEMES_PACKAGE + "/([\\w\\d\\s\\.]*)/theme.xml")
// .exclude(THEMES_PACKAGE + "(.*)/(.*)")
// )
));
final Set<String> jsonThemes = reflections final Set<String> jsonThemes = reflections.getResources(
.getResources(Pattern.compile(THEME_MANIFEST_JSON)); Pattern.compile(THEME_MANIFEST_JSON)
final Set<String> xmlThemes = reflections );
.getResources(Pattern.compile(THEME_MANIFEST_XML)); final Set<String> xmlThemes = reflections.getResources(
Pattern.compile(THEME_MANIFEST_XML)
);
final List<String> themes = new ArrayList<>(); final List<String> themes = new ArrayList<>();
themes.addAll(jsonThemes themes.addAll(
.stream() jsonThemes
.filter(themePackage -> { .stream()
return themePackage .filter(
.matches(THEMES_PACKAGE + "/([\\w\\d\\s\\.\\-_])*/theme.json"); themePackage -> themePackage.matches(
}) THEMES_PACKAGE + "/([\\w\\d\\s\\.\\-_])*/theme.json"
// .map(themePackage -> { )
// return themePackage )
// .substring((THEMES_PACKAGE + "/").length(), .collect(Collectors.toList()));
// ("/" + THEME_MANIFEST_JSON).length() - 1); themes.addAll(
// }) xmlThemes
.collect(Collectors.toList())); .stream()
themes.addAll(xmlThemes .filter(
.stream() themePackage -> themePackage
.filter(themePackage -> { .matches(
return themePackage THEMES_PACKAGE + "/([\\w\\d\\s\\.])*/theme.xml"
.matches(THEMES_PACKAGE + "/([\\w\\d\\s\\.])*/theme.xml"); )
}) )
// .map(themePackage -> { .collect(Collectors.toList())
// return themePackage );
// .substring((THEMES_PACKAGE + "/").length(),
// ("/" + THEME_MANIFEST_XML).length() - 1);
// })
.collect(Collectors.toList()));
Collections.sort(themes); Collections.sort(themes);
LOGGER.debug("Found static themes:"); LOGGER.debug("Found static themes:");
@ -151,9 +142,10 @@ public class StaticThemeProvider implements ThemeProvider {
for (final String theme : themes) { for (final String theme : themes) {
final InputStream inputStream = StaticThemeProvider.class final InputStream inputStream = StaticThemeProvider.class
.getResourceAsStream(String.format("/%s", theme)); .getResourceAsStream(String.format("/%s", theme));
final ThemeManifest manifest = manifestUtil final ThemeManifest manifest = manifestUtil.loadManifest(
.loadManifest(inputStream, inputStream,
theme); theme
);
LOGGER.debug("Got manifest: {}", Objects.toString(manifest)); LOGGER.debug("Got manifest: {}", Objects.toString(manifest));
} }
@ -165,19 +157,7 @@ public class StaticThemeProvider implements ThemeProvider {
} }
// private boolean isThemeDir(final String dirPath) {
//
// Objects.requireNonNull(dirPath);
//
// final URL manifestJsonUrl = StaticThemeProvider.class.getResource(
// String.format(THEME_MANIFEST_JSON_PATH, dirPath));
// final URL manifestXmlUrl = StaticThemeProvider.class.getResource(
// String.format(THEME_MANIFEST_XML_PATH, dirPath));
//
// return (manifestJsonUrl != null) || (manifestXmlUrl != null);
// }
private ThemeManifest loadThemeManifest(final String manifestPath) { private ThemeManifest loadThemeManifest(final String manifestPath) {
Objects.requireNonNull(manifestPath); Objects.requireNonNull(manifestPath);
final String pathToManifest; final String pathToManifest;
@ -190,9 +170,7 @@ public class StaticThemeProvider implements ThemeProvider {
final ThemeManifest manifest; final ThemeManifest manifest;
try (final InputStream inputStream = StaticThemeProvider.class try (final InputStream inputStream = StaticThemeProvider.class
.getResourceAsStream(pathToManifest)) { .getResourceAsStream(pathToManifest)) {
manifest = manifestUtil.loadManifest(inputStream, manifestPath); manifest = manifestUtil.loadManifest(inputStream, manifestPath);
} catch (IOException ex) { } catch (IOException ex) {
throw new UnexpectedErrorException(ex); throw new UnexpectedErrorException(ex);
} }
@ -218,22 +196,23 @@ public class StaticThemeProvider implements ThemeProvider {
} }
@Override @Override
public Optional<ThemeInfo> getThemeInfo(final String theme, public Optional<ThemeInfo> getThemeInfo(
final ThemeVersion version) { final String theme,
final ThemeVersion version
) {
Objects.requireNonNull(theme); Objects.requireNonNull(theme);
final String manifestJsonPath = String.format("/" + THEMES_PACKAGE final String manifestJsonPath = String.format(
+ "/%s/" "/" + THEMES_PACKAGE + "/%s/" + THEME_MANIFEST_JSON,
+ THEME_MANIFEST_JSON, theme
theme); );
final String manifestXmlPath = String.format("/" + THEMES_PACKAGE final String manifestXmlPath = String.format(
+ "/%s/" "/" + THEMES_PACKAGE + "/%s/" + THEME_MANIFEST_XML, theme
+ THEME_MANIFEST_XML, );
theme);
final URL manifestJsonUrl = StaticThemeProvider.class final URL manifestJsonUrl = StaticThemeProvider.class.getResource(
.getResource(manifestJsonPath); manifestJsonPath
);
final URL manifestXmlUrl = StaticThemeProvider.class final URL manifestXmlUrl = StaticThemeProvider.class
.getResource(manifestXmlPath); .getResource(manifestXmlPath);

View File

@ -50,39 +50,50 @@ public class L10NUtils implements Serializable {
@Inject @Inject
private GlobalizationHelper globalizationHelper; private GlobalizationHelper globalizationHelper;
public ResourceBundle getBundle(final ThemeInfo fromTheme, public ResourceBundle getBundle(
final ThemeProvider themeProvider, final ThemeInfo fromTheme,
final String bundleName) { final ThemeProvider themeProvider,
final String bundleName
) {
return ResourceBundle return ResourceBundle
.getBundle( .getBundle(
bundleName, bundleName,
globalizationHelper.getNegotiatedLocale(), globalizationHelper.getNegotiatedLocale(),
new LocalizedResourceBundleControl(fromTheme, new LocalizedResourceBundleControl(
themeProvider)); fromTheme,
themeProvider
)
);
} }
public String getText(final ThemeInfo fromTheme, public String getText(
final ThemeProvider themeProvider, final ThemeInfo fromTheme,
final String bundleName, final ThemeProvider themeProvider,
final String key) { final String bundleName,
final String key
) {
final ResourceBundle bundle = getBundle(fromTheme, final ResourceBundle bundle = getBundle(
themeProvider, fromTheme,
bundleName); themeProvider,
bundleName
);
return bundle.getString(key); return bundle.getString(key);
} }
public String getText(final ThemeInfo fromTheme, public String getText(
final ThemeProvider themeProvider, final ThemeInfo fromTheme,
final String bundleName, final ThemeProvider themeProvider,
final String key, final String bundleName,
final String arguments) { final String key,
final String arguments
final ResourceBundle bundle = getBundle(fromTheme, ) {
themeProvider, final ResourceBundle bundle = getBundle(
bundleName); fromTheme,
themeProvider,
bundleName
);
return MessageFormat.format(bundle.getString(key), arguments); return MessageFormat.format(bundle.getString(key), arguments);
} }
@ -91,6 +102,7 @@ public class L10NUtils implements Serializable {
extends ResourceBundle.Control { extends ResourceBundle.Control {
private final ThemeInfo theme; private final ThemeInfo theme;
private final ThemeProvider themeProvider; private final ThemeProvider themeProvider;
public LocalizedResourceBundleControl( public LocalizedResourceBundleControl(
@ -109,41 +121,49 @@ public class L10NUtils implements Serializable {
} }
@Override @Override
public ResourceBundle newBundle(final String baseName, public ResourceBundle newBundle(
final Locale locale, final String baseName,
final String format, final Locale locale,
final ClassLoader classLoader, final String format,
final boolean reload) final ClassLoader classLoader,
final boolean reload
)
throws IllegalAccessException, throws IllegalAccessException,
InstantiationException, InstantiationException,
IOException { IOException {
if ("java.properties".equals(format)) { if ("java.properties".equals(format)) {
final String bundleName = toBundleName(baseName, locale); final String bundleName = toBundleName(baseName, locale);
final Optional<InputStream> inputStream = themeProvider final Optional<InputStream> inputStream = themeProvider
.getThemeFileAsStream(theme.getName(), .getThemeFileAsStream(
theme.getVersion(), theme.getName(),
String.format("%s.properties", theme.getVersion(),
bundleName)); String.format(
"%s.properties",
bundleName
)
);
if (inputStream.isPresent()) { if (inputStream.isPresent()) {
return new PropertyResourceBundle(inputStream.get()); return new PropertyResourceBundle(inputStream.get());
} else { } else {
return super.newBundle(baseName, return super.newBundle(
locale, baseName,
format, locale,
classLoader, format,
reload); classLoader,
reload
);
} }
} else { } else {
return super.newBundle(baseName, return super.newBundle(
locale, baseName,
format, locale,
classLoader, format,
reload); classLoader,
reload
);
} }
} }
} }
} }