Skip to content

Commit

Permalink
4.15.0 (#186)
Browse files Browse the repository at this point in the history
* start 5.0.0 development

* clean imports

* #185 cache for resourcebundle

* change version

* update version

---------

Co-authored-by: Thorsten Marx <t.marx@eggheads.de>
  • Loading branch information
thmarx and Thorsten Marx authored Mar 14, 2024
1 parent b32928c commit b99c409
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 37 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ see wiki for more information: [wiki](https://github.com/thmarx/cms/wiki)

# changelog

## 4.15.0

* **FEATURE** Cache ResourceBundles in messages [#185](https://github.com/thmarx/cms/issues/185)

## 4.14.1

* **BUGFIX** TaxonomyResolver does not set page properties correctly [#184](https://github.com/thmarx/cms/issues/184)
Expand Down
2 changes: 1 addition & 1 deletion cms-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-api</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.github.thmarx.cms.api.extensions;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.util.Callback;

/*-
* #%L
* cms-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import com.github.thmarx.cms.api.SiteProperties;
import java.io.File;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.text.MessageFormat;
import java.util.Arrays;
import java.time.Duration;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
Expand All @@ -42,17 +42,22 @@
@Slf4j
@RequiredArgsConstructor
public class DefaultMessageSource implements MessageSource {

final SiteProperties siteProperties;
final Path messageFolder;


final Cache<String, ResourceBundle> bundles = CacheBuilder.newBuilder()
.maximumSize(10)
.expireAfterWrite(Duration.ofSeconds(10))
.build();

@Override
public String getLabel (final String bundle, final String label) {
public String getLabel(final String bundle, final String label) {
return getLabel(bundle, label, List.of());
}

@Override
public String getLabel (final String bundle, final String label, final List<Object> data) {
public String getLabel(final String bundle, final String label, final List<Object> data) {
try {
var resourceBundle = fromClassLoader(bundle, siteProperties.locale());
if (resourceBundle != null) {
Expand All @@ -64,14 +69,17 @@ public String getLabel (final String bundle, final String label, final List<Obje
}
return "[" + label + "]";
}

protected ResourceBundle fromClassLoader(final String bundleName) throws Exception {
return fromClassLoader(bundleName, Locale.getDefault());
}
return fromClassLoader(bundleName, Locale.getDefault());
}

protected ResourceBundle fromClassLoader(final String bundleName, final Locale locale) throws Exception {
URL[] urls = {messageFolder.toUri().toURL()};
ClassLoader loader = new URLClassLoader(urls);
return ResourceBundle.getBundle(bundleName, locale, loader);
}
var cacheKey = "%s-%s".formatted(bundleName, locale.toLanguageTag());
return bundles.get(bundleName, () -> {
URL[] urls = {messageFolder.toUri().toURL()};
ClassLoader loader = new URLClassLoader(urls);
return ResourceBundle.getBundle(bundleName, locale, loader);
});
}
}
2 changes: 1 addition & 1 deletion cms-content/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-content</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-extensions</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-filesystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-filesystem</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-git</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-markdown/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-markdown</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-media/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-media</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-sandbox/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-sandbox</artifactId>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-server</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion cms-template/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>cms-template</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion distribution/build.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="distribution" default="distribution" basedir=".">
<property name="cms.version">4.14.1</property>
<property name="cms.version">4.15.0</property>

<property name="pebble.version">v1.1.0</property>
<property name="thymeleaf.version">v1.1.0</property>
Expand Down
2 changes: 1 addition & 1 deletion modules-framework/api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.module.framework</groupId>
<artifactId>module-framework</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>modules-api</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules-framework/manager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.module.framework</groupId>
<artifactId>module-framework</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>modules-manager</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules-framework/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<groupId>com.github.thmarx.cms.module.framework</groupId>
<artifactId>module-framework</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion modules/example-module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<artifactId>example-module</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion modules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
</parent>
<groupId>com.github.thmarx.cms.modules</groupId>
<artifactId>cms-modules</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>4.14.1</version>
<version>4.15.0</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down

0 comments on commit b99c409

Please sign in to comment.