Skip to content

Commit

Permalink
load region on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeloffner committed Nov 12, 2024
1 parent 1e9df5b commit 3fc97c7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 48 deletions.
53 changes: 21 additions & 32 deletions core/src/main/java/lucee/runtime/config/ConfigImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;

import lucee.commons.date.TimeZoneConstants;
import lucee.commons.io.CharsetUtil;
import lucee.commons.io.FileUtil;
import lucee.commons.io.SystemUtil;
Expand Down Expand Up @@ -693,6 +694,13 @@ public ClassLoader getClassLoaderCore() {

@Override
public Locale getLocale() {
if (locale == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getLocale")) {
if (locale == null) {
locale = ConfigWebFactory.loadLocale(this, root, getLog(), Locale.US);
}
}
}
return locale;
}

Expand Down Expand Up @@ -760,6 +768,19 @@ public int getMailSpoolInterval() {

@Override
public TimeZone getTimeZone() {
if (timeZone == null) {
synchronized (SystemUtil.createToken("ConfigImpl", "getTimeZone")) {
if (timeZone == null) {
timeZone = ConfigWebFactory.loadTimezone(this, root, getLog(), null);
if (timeZone == null) timeZone = TimeZone.getDefault();
// there was no system default, so we use UTC
if (timeZone == null) {
timeZone = TimeZoneConstants.UTC;
TimeZone.setDefault(timeZone);
}
}
}
}
return timeZone;
}

Expand Down Expand Up @@ -1477,43 +1498,11 @@ protected void setMailSpoolInterval(int spoolInterval) {
this.spoolInterval = spoolInterval;
}

/**
* sets the timezone
*
* @param timeZone
*/
protected void setTimeZone(TimeZone timeZone) {
this.timeZone = timeZone;
}

/**
* sets the locale
*
* @param strLocale
*/
protected void setLocale(String strLocale) {
if (strLocale == null) {
this.locale = Locale.US;
}
else {
try {
this.locale = Caster.toLocale(strLocale);
if (this.locale == null) this.locale = Locale.US;
}
catch (ExpressionException e) {
this.locale = Locale.US;
}
}
}

/**
* sets the locale
*
* @param locale
*/
protected void setLocale(Locale locale) {
this.locale = locale;
}

/**
* @param datasources The datasources to set
Expand Down
34 changes: 20 additions & 14 deletions core/src/main/java/lucee/runtime/config/ConfigWebFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,6 @@ synchronized static void load(ConfigServerImpl config, Struct root, boolean isRe
_loadTag(config, root, log); // load tlds
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded tags");

_loadRegional(config, root, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded regional");

_loadCompiler(config, root, mode, log);
if (LOG) LogUtil.logGlobal(ThreadLocalPageContext.getConfig(config), Log.LEVEL_DEBUG, ConfigWebFactory.class.getName(), "loaded compiler");

Expand Down Expand Up @@ -3130,35 +3127,44 @@ else if (StringUtil.startsWithIgnoreCase(streamtype, "log")) {
* @param config
* @param doc
*/
private static void _loadRegional(ConfigServerImpl config, Struct root, Log log) {
public static TimeZone loadTimezone(ConfigImpl config, Struct root, Log log, TimeZone defaultValue) {
try {
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING);

// timeZone
String strTimeZone = null;
strTimeZone = getAttr(root, new String[] { "timezone", "thisTimezone" });

if (!StringUtil.isEmpty(strTimeZone)) config.setTimeZone(TimeZone.getTimeZone(strTimeZone));
if (!StringUtil.isEmpty(strTimeZone)) return TimeZone.getTimeZone(strTimeZone);
else {
TimeZone def = TimeZone.getDefault();
if (def == null) {
def = TimeZoneConstants.EUROPE_LONDON;
}
config.setTimeZone(def);
return def;
}

// this is necessary, otherwise travis has no default
if (TimeZone.getDefault() == null) TimeZone.setDefault(config.getTimeZone());

// locale
String strLocale = getAttr(root, new String[] { "locale", "thisLocale" });
if (!StringUtil.isEmpty(strLocale)) config.setLocale(strLocale);
else config.setLocale(Locale.US);
}
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
log(config, log, t);
}
return defaultValue;
}

public static Locale loadLocale(ConfigImpl config, Struct root, Log log, Locale defaultValue) {
if (ConfigWebUtil.hasAccess(config, SecurityManager.TYPE_SETTING)) {
try {
// locale
String strLocale = getAttr(root, new String[] { "locale", "thisLocale" });
if (!StringUtil.isEmpty(strLocale)) return Caster.toLocale(strLocale, defaultValue);

}
catch (Throwable t) {
ExceptionUtil.rethrowIfNecessary(t);
log(config, log, t);
}
}
return defaultValue;
}

private static void _loadWS(ConfigServerImpl config, Struct root, Log log) {
Expand Down
2 changes: 1 addition & 1 deletion loader/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="core" basedir="." name="Lucee"
xmlns:resolver="antlib:org.apache.maven.resolver.ant">

<property name="version" value="7.0.0.9-SNAPSHOT"/>
<property name="version" value="7.0.0.10-SNAPSHOT"/>

<taskdef uri="antlib:org.apache.maven.resolver.ant" resource="org/apache/maven/resolver/ant/antlib.xml">
<classpath>
Expand Down
2 changes: 1 addition & 1 deletion loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>org.lucee</groupId>
<artifactId>lucee</artifactId>
<version>7.0.0.9-SNAPSHOT</version>
<version>7.0.0.10-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Lucee Loader Build</name>
Expand Down

0 comments on commit 3fc97c7

Please sign in to comment.