126126import org .slf4j .Logger ;
127127import org .slf4j .LoggerFactory ;
128128
129+ import com .google .common .base .Joiner ;
129130import com .google .common .base .Strings ;
130131import com .google .common .collect .ImmutableList ;
131132import com .google .common .collect .ImmutableMap ;
@@ -655,6 +656,20 @@ public EnvDep(final Predicate<String> predicate, final Consumer<Config> callback
655656
656657 private ServerLookup server = new ServerLookup ();
657658
659+ private String dateFormat ;
660+
661+ private Charset charset ;
662+
663+ private String [] languages ;
664+
665+ private ZoneId zoneId ;
666+
667+ private Integer port ;
668+
669+ private Integer securePort ;
670+
671+ private String numberFormat ;
672+
658673 public Jooby () {
659674 this (null );
660675 }
@@ -3773,6 +3788,83 @@ public <T> Jooby bind(final Function<Config, T> provider) {
37733788 return this ;
37743789 }
37753790
3791+ /**
3792+ * Set application date format.
3793+ *
3794+ * @param dateFormat A date format.
3795+ * @return This instance.
3796+ */
3797+ public Jooby dateFormat (final String dateFormat ) {
3798+ this .dateFormat = requireNonNull (dateFormat , "DateFormat required." );
3799+ return this ;
3800+ }
3801+
3802+ /**
3803+ * Set application number format.
3804+ *
3805+ * @param numberFormat A number format.
3806+ * @return This instance.
3807+ */
3808+ public Jooby numberFormat (final String numberFormat ) {
3809+ this .numberFormat = requireNonNull (numberFormat , "NumberFormat required." );
3810+ return this ;
3811+ }
3812+
3813+ /**
3814+ * Set application/default charset.
3815+ *
3816+ * @param charset A charset.
3817+ * @return This instance.
3818+ */
3819+ public Jooby charset (final Charset charset ) {
3820+ this .charset = requireNonNull (charset , "Charset required." );
3821+ return this ;
3822+ }
3823+
3824+ /**
3825+ * Set application locale (first listed are higher priority).
3826+ *
3827+ * @param Languages list of locale using the language tag format.
3828+ * @return This instance.
3829+ */
3830+ public Jooby lang (final String ... languages ) {
3831+ this .languages = languages ;
3832+ return this ;
3833+ }
3834+
3835+ /**
3836+ * Set application time zone.
3837+ *
3838+ * @param zoneId ZoneId.
3839+ * @return This instance.
3840+ */
3841+ public Jooby timezone (final ZoneId zoneId ) {
3842+ this .zoneId = requireNonNull (zoneId , "ZoneId required." );
3843+ return this ;
3844+ }
3845+
3846+ /**
3847+ * Set the HTTP port.
3848+ *
3849+ * @param port HTTP port.
3850+ * @return This instance.
3851+ */
3852+ public Jooby port (final int port ) {
3853+ this .port = port ;
3854+ return this ;
3855+ }
3856+
3857+ /**
3858+ * Set the HTTPS port.
3859+ *
3860+ * @param port HTTPS port.
3861+ * @return This instance.
3862+ */
3863+ public Jooby securePort (final int port ) {
3864+ this .securePort = port ;
3865+ return this ;
3866+ }
3867+
37763868 /**
37773869 * Run app in javascript.
37783870 *
@@ -4337,7 +4429,9 @@ private Config defaultConfig(final Config config) {
43374429 // locale
43384430 final List <Locale > locales ;
43394431 if (!config .hasPath ("application.lang" )) {
4340- locales = ImmutableList .of (Locale .getDefault ());
4432+ locales = Optional .ofNullable (this .languages )
4433+ .map (langs -> LocaleUtils .parse (Joiner .on ("," ).join (langs )))
4434+ .orElse (ImmutableList .of (Locale .getDefault ()));
43414435 } else {
43424436 locales = LocaleUtils .parse (config .getString ("application.lang" ));
43434437 }
@@ -4347,15 +4441,16 @@ private Config defaultConfig(final Config config) {
43474441 // time zone
43484442 final String tz ;
43494443 if (!config .hasPath ("application.tz" )) {
4350- tz = ZoneId .systemDefault ().getId ();
4444+ tz = Optional . ofNullable ( zoneId ). orElse ( ZoneId .systemDefault () ).getId ();
43514445 } else {
43524446 tz = config .getString ("application.tz" );
43534447 }
43544448
43554449 // number format
43564450 final String nf ;
43574451 if (!config .hasPath ("application.numberFormat" )) {
4358- nf = ((DecimalFormat ) DecimalFormat .getInstance (locale )).toPattern ();
4452+ nf = Optional .ofNullable (numberFormat )
4453+ .orElseGet (() -> ((DecimalFormat ) DecimalFormat .getInstance (locale )).toPattern ());
43594454 } else {
43604455 nf = config .getString ("application.numberFormat" );
43614456 }
@@ -4378,6 +4473,20 @@ private Config defaultConfig(final Config config) {
43784473 .withValue ("runtime.concurrencyLevel" , ConfigValueFactory
43794474 .fromAnyRef (Math .max (4 , processors )));
43804475
4476+ if (charset != null ) {
4477+ defs = defs .withValue ("application.charset" , ConfigValueFactory .fromAnyRef (charset .name ()));
4478+ }
4479+ if (port != null ) {
4480+ defs = defs .withValue ("application.port" , ConfigValueFactory .fromAnyRef (port .intValue ()));
4481+ }
4482+ if (securePort != null ) {
4483+ defs = defs .withValue ("application.securePort" ,
4484+ ConfigValueFactory .fromAnyRef (securePort .intValue ()));
4485+ }
4486+ if (dateFormat != null ) {
4487+ defs = defs .withValue ("application.dateFormat" , ConfigValueFactory .fromAnyRef (dateFormat ));
4488+ }
4489+
43814490 return defs ;
43824491 }
43834492
0 commit comments