Skip to content
This repository was archived by the owner on Jun 11, 2023. It is now read-only.

Commit d08923a

Browse files
committed
Revert "#79 [bug] If the ResourceBundle doesn't exist then a spezific MissingResourceException will thrown."
This reverts commit ddd28cf.
1 parent ddd28cf commit d08923a

File tree

3 files changed

+38
-271
lines changed

3 files changed

+38
-271
lines changed

README.md

Lines changed: 24 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ Content
2828
- [How to use the builder I18NBindingBuilder](#HoToUsBiBu)
2929
- [How to use the builder I18NMessageBuilder](#HoToUsMeBu)
3030
* [Conventions](#Conventions)
31-
- [Convention: 'baseBundleName' from ResourceBundle](#CoBaFrRe)
32-
- [Convention: 'Key not found' in ResourceBundle](#CoKeInReBu)
33-
- [Convention: Defined supported Locales, default and actual Locale](#CoDeSuDeAcLo)
34-
- [Convention: Basic validation](#CoBaVa)
3531
* [Features](#Features)
3632
* [JavaDoc](#JavaDoc)
3733
* [Download](#Download)
@@ -245,7 +241,7 @@ public void lastStepWithoutArguments() {
245241
.build();
246242
assertEquals("RB: Test title", result);
247243
}
248-
244+
249245
@Test
250246
public void lastStepWithArguments() {
251247
I18NResourceBundleBuilder.configure()
@@ -276,243 +272,34 @@ Conventions<a name="Conventions" />
276272
---
277273

278274
In this chapter, the interested developer can find out all about the conventions
279-
from the library `Lib-I18N`:
280-
281-
### Convention: 'baseBundleName' from ResourceBundle<a name="CoBaFrRe" />
282-
283-
If a [ResourceBundle] with the defined 'baseBundleName' can't be found a spezific
284-
MissingResourceException will be thrown.
285-
286-
```java
287-
public final class DefaultI18NResourceBundle implements I18NResourceBundle {
288-
...
289-
private ResourceBundle getResourceBundle() {
290-
ResourceBundle bundle = null;
291-
try {
292-
bundle = ResourceBundle.getBundle(this.getBaseBundleName(), this.getActualLocale());
293-
} catch (MissingResourceException mre) {
294-
LoggerFacade.getDefault().error(this.getClass(),
295-
String.format("Can't access the ResourceBundle[path=%s, actual-locale=%s]",
296-
this.getBaseBundleName(), this.getActualLocale().getDisplayLanguage()),
297-
mre);
298-
}
299-
300-
return bundle;
301-
}
302-
...
303-
}
304-
```
305-
306-
### Convention: 'Key not found' in ResourceBundle<a name="CoKeInReBu" />
307-
308-
If a key can't be found in the defined ResourceBundle then
309-
* the String pattern '&lt;key&gt;' will returned instead and
310-
* the 'warning' message will be logged: "Can't find key(%s) in resourcebundle. Return: %s"
311-
312-
```java
313-
public final class DefaultI18NResourceBundle implements I18NResourceBundle {
314-
...
315-
@Override
316-
public String getMessage(final String key, final Object... arguments) {
317-
DefaultI18NValidator.requireNonNullAndNotEmpty(key);
318-
DefaultI18NValidator.requireNonNullAndNotEmpty(arguments);
319-
DefaultI18NValidator.requireResourceBundleExist(this.getBaseBundleName(), this.getActualLocale());
320-
321-
final ResourceBundle bundle = getResourceBundle();
322-
String value = MessageFormat.format(PATTERN_KEY_NAME, key);
323-
324-
if (bundle != null) {
325-
try {
326-
value = MessageFormat.format(bundle.getString(key), arguments);
327-
} catch (MissingResourceException mre) {
328-
LoggerFacade.getDefault().warn(this.getClass(),
329-
String.format("Can't find key(%s) in resourcebundle. Return: %s", key, value),
330-
mre);
331-
}
332-
}
333-
334-
return value;
335-
}
336-
...
337-
}
338-
```
339-
340-
341-
### Convention: Defined supported Locales, default and actual Locale<a name="CoDeSuDeAcLo" />
342-
343-
_Supported Locales_
344-
* Defines all supported [Locale]s in the momentary session.
345-
346-
```java
347-
public final class I18NResourceBundleBuilder {
348-
...
349-
private static final class I18NResourceBundleBuilderImpl implements
350-
FirstStep, ForthStep, LastStep, SecondStep, ThirdStep
351-
{
352-
...
353-
@Override
354-
public ThirdStep supportedLocales(final Locale... locales) {
355-
LoggerFacade.getDefault().debug(this.getClass(), "I18NResourceBundleBuilderImpl.supportedLocales(Locale...)"); // NOI18N
356-
357-
final List<Locale> list = Arrays.asList(locales);
358-
DefaultI18NValidator.requireNonNullAndNotEmpty(list);
359-
360-
final ObservableList<Locale> observableList = FXCollections.observableArrayList();
361-
observableList.addAll(list);
362-
properties.put(ATTR__SUPPORTED_LOCALES, new SimpleObjectProperty(observableList));
363-
364-
return this;
365-
}
366-
367-
@Override
368-
public ThirdStep supportedLocales(final ObservableList<Locale> locales) {
369-
LoggerFacade.getDefault().debug(this.getClass(), "I18NResourceBundleBuilderImpl.supportedLocales(ObservableList<Locale>)"); // NOI18N
370-
371-
DefaultI18NValidator.requireNonNullAndNotEmpty(locales);
372-
properties.put(ATTR__SUPPORTED_LOCALES, new SimpleObjectProperty(locales));
373-
374-
return this;
375-
}
376-
...
377-
}
378-
}
379-
```
380-
381-
```java
382-
public final class I18NFacade implements I18NBinding, I18NResourceBundle {
383-
...
384-
@Override
385-
public ObservableList<Locale> getSupportedLocales() {
386-
return i18NResourceBundle.getSupportedLocales();
387-
}
388-
389-
@Override
390-
public void setSupportedLocales(final ObservableList<Locale> locales) {
391-
i18NResourceBundle.setSupportedLocales(locales);
392-
}
393-
394-
@Override
395-
public void setSupportedLocales(final Locale... locales) {
396-
i18NResourceBundle.setSupportedLocales(locales);
397-
}
398-
...
399-
}
400-
```
401-
402-
```java
403-
public final class DefaultI18NResourceBundle implements I18NResourceBundle {
404-
...
405-
@Override
406-
public ObservableList<Locale> getSupportedLocales() {
407-
DefaultI18NValidator.requireNonNull(supportedLocales);
408-
409-
return supportedLocales;
410-
}
411-
412-
@Override
413-
public void setSupportedLocales(final ObservableList<Locale> locales) {
414-
DefaultI18NValidator.requireNonNullAndNotEmpty(locales);
415-
416-
supportedLocales.clear();
417-
supportedLocales.addAll(locales);
418-
}
419-
420-
@Override
421-
public void setSupportedLocales(final Locale... locales) {
422-
final List<Locale> list = Arrays.asList(locales);
423-
DefaultI18NValidator.requireNonNullAndNotEmpty(list);
424-
425-
supportedLocales.clear();
426-
supportedLocales.addAll(list);
427-
}
428-
...
429-
}
430-
```
431-
432-
_Default Locale_
433-
* If the supported Locales doesn't contained the default Locale then the Locale#ENGLISH
275+
in the library `Lib-I18N`:
276+
277+
__Convention__: 'baseBundleName' from ResourceBundle
278+
* If a [ResourceBundle] with the defined 'baseBundleName' can't be found a
279+
MissingResourceException will be thrown.
280+
281+
__Convention__: 'Key not found' in ResourceBundle
282+
* If a key can't be found in the defined ResourceBundle then
283+
* the String pattern '&lt;key&gt;' will returned instead and
284+
* the 'warning' message will be logged: "Can't find key(%s) in resourcebundle. Return: %s"
285+
286+
__Convention__: Defined supported Locales, default and actual Locale.
287+
* Supported Locales
288+
Defines all supported [Locale]s in the momentary session.
289+
* Default Locale
290+
If the supported Locales doesn't contained the default Locale then the Locale#ENGLISH
434291
will be used instead.
435-
436-
```java
437-
```
438-
439-
```java
440-
```
441-
442-
```java
443-
```
444-
445-
_Actual Locale_
446-
* If the upported Locales doesn't contained the actual Locale then the default Locale
292+
* Actual Locale
293+
If the upported Locales doesn't contained the actual Locale then the default Locale
447294
will be used instead.
448295

449-
```java
450-
```
451-
452-
453-
### Convention: Basic validation<a name="CoBaVa" />
454-
455-
* Every `functionality` in the builders and in the default implementations will checked
456-
against minimal preconditions with the validator [DefaultI18NValidator].
457-
* `Getters` and `Setters` functionalities are only checked if they are initial only
458-
instantiate and not declarated.
296+
__Convention__: Basic validation
297+
* Every attributes in the builders and in all setters will be check against minimal
298+
preconditions with [DefaultI18NValidator].
299+
* Getters attributs will only checked if they are initial only instantiate and not
300+
declarated.
459301
* For example a String will be validate if it's not NULL and not EMPTY.
460302

461-
```java
462-
public final class I18NResourceBundleBuilder {
463-
...
464-
private static final class I18NResourceBundleBuilderImpl implements
465-
FirstStep, ForthStep, LastStep, SecondStep, ThirdStep
466-
{
467-
...
468-
@Override
469-
public SecondStep baseBundleName(final String baseBundleName) {
470-
LoggerFacade.getDefault().debug(this.getClass(), "I18NResourceBundleBuilderImpl.baseBundleName(String)"); // NOI18N
471-
472-
DefaultI18NValidator.requireNonNullAndNotEmpty(baseBundleName);
473-
properties.put(ATTR__BASE_BUNDLE_NAME, new SimpleStringProperty(baseBundleName));
474-
475-
return this;
476-
}
477-
...
478-
}
479-
}
480-
```
481-
482-
```java
483-
public final class DefaultI18NResourceBundle implements I18NResourceBundle {
484-
...
485-
@Override
486-
public String getBaseBundleName() {
487-
DefaultI18NValidator.requireNonNullAndNotEmpty(baseBundleName);
488-
489-
return baseBundleName;
490-
}
491-
492-
@Override
493-
public void setBaseBundleName(final String baseBundleName) {
494-
DefaultI18NValidator.requireNonNullAndNotEmpty(baseBundleName);
495-
496-
this.baseBundleName = baseBundleName;
497-
}
498-
...
499-
}
500-
```
501-
502-
```java
503-
public final class DefaultI18NBinding implements I18NBinding {
504-
...
505-
@Override
506-
public StringBinding createStringBinding(final String key, Object... arguments) {
507-
DefaultI18NValidator.requireNonNullAndNotEmpty(key);
508-
DefaultI18NValidator.requireNonNullAndNotEmpty(arguments);
509-
510-
return Bindings.createStringBinding(() -> I18NFacade.getDefault().getMessage(key, arguments), I18NFacade.getDefault().actualLocaleProperty());
511-
}
512-
...
513-
}
514-
```
515-
516303

517304

518305
Features<a name="Features" />

release/Release_v0.7.1_2019-02-dd_HH-mm.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Lib-I18N is written in JavaFX, [Maven] and [NetBeans].
2222

2323

2424
#### Bug
25-
#79 [bug] If the ResourceBundle doesn't exist then a spezific MissingResourceException will thrown.
2625

2726

2827

@@ -47,7 +46,6 @@ Naoghuman
4746

4847

4948
[//]: # (Issues which will be integrated in this release)
50-
#74 [doc] Update every sub-section from 'Conventions'. Add examples to them.
5149

5250

5351

src/main/java/com/github/naoghuman/lib/i18n/internal/DefaultI18NResourceBundle.java

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,15 @@ public String getMessage(final String key) {
8888
DefaultI18NValidator.requireNonNullAndNotEmpty(key);
8989
DefaultI18NValidator.requireResourceBundleExist(this.getBaseBundleName(), this.getActualLocale());
9090

91-
final ResourceBundle bundle = getResourceBundle();
92-
String value = MessageFormat.format(PATTERN_KEY_NAME, key);
91+
final ResourceBundle bundle = ResourceBundle.getBundle(this.getBaseBundleName(), this.getActualLocale());
9392

94-
if (bundle != null) {
95-
try {
96-
value = bundle.getString(key);
97-
} catch (MissingResourceException mre) {
98-
LoggerFacade.getDefault().warn(this.getClass(),
99-
String.format("Can't find key(%s) in resourcebundle. Return: %s", key, value),
100-
mre);
101-
}
93+
String value = MessageFormat.format(PATTERN_KEY_NAME, key);
94+
try {
95+
value = bundle.getString(key);
96+
} catch (MissingResourceException mre) {
97+
LoggerFacade.getDefault().warn(this.getClass(),
98+
String.format("Can't find key(%s) in resourcebundle. Return: %s", key, value),
99+
mre);
102100
}
103101

104102
return value;
@@ -110,34 +108,18 @@ public String getMessage(final String key, final Object... arguments) {
110108
DefaultI18NValidator.requireNonNullAndNotEmpty(arguments);
111109
DefaultI18NValidator.requireResourceBundleExist(this.getBaseBundleName(), this.getActualLocale());
112110

113-
final ResourceBundle bundle = getResourceBundle();
114-
String value = MessageFormat.format(PATTERN_KEY_NAME, key);
111+
final ResourceBundle bundle = ResourceBundle.getBundle(this.getBaseBundleName(), this.getActualLocale());
115112

116-
if (bundle != null) {
117-
try {
118-
value = MessageFormat.format(bundle.getString(key), arguments);
119-
} catch (MissingResourceException mre) {
120-
LoggerFacade.getDefault().warn(this.getClass(),
121-
String.format("Can't find key(%s) in resourcebundle. Return: %s", key, value),
122-
mre);
123-
}
124-
}
125-
126-
return value;
127-
}
128-
129-
private ResourceBundle getResourceBundle() {
130-
ResourceBundle bundle = null;
113+
String value = MessageFormat.format(PATTERN_KEY_NAME, key);
131114
try {
132-
bundle = ResourceBundle.getBundle(this.getBaseBundleName(), this.getActualLocale());
115+
value = MessageFormat.format(bundle.getString(key), arguments);
133116
} catch (MissingResourceException mre) {
134-
LoggerFacade.getDefault().error(this.getClass(),
135-
String.format("Can't access the ResourceBundle[path=%s, actual-locale=%s]",
136-
this.getBaseBundleName(), this.getActualLocale().getDisplayLanguage()),
117+
LoggerFacade.getDefault().warn(this.getClass(),
118+
String.format("Can't find key(%s) in resourcebundle. Return: %s", key, value),
137119
mre);
138120
}
139121

140-
return bundle;
122+
return value;
141123
}
142124

143125
@Override

0 commit comments

Comments
 (0)