Skip to content

Commit

Permalink
Injects user defined provider and uses it if available
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Oct 25, 2017
1 parent 5325f78 commit d821c27
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class StrutsTextProviderFactory implements TextProviderFactory {

protected LocaleProviderFactory localeProviderFactory;
protected LocalizedTextProvider localizedTextProvider;
protected TextProvider defaultTextProvider;

@Inject
public void setLocaleProviderFactory(LocaleProviderFactory localeProviderFactory) {
Expand All @@ -40,6 +41,11 @@ public void setLocalizedTextProvider(LocalizedTextProvider localizedTextProvider
this.localizedTextProvider = localizedTextProvider;
}

@Inject(required = false)
public void setDefaultTextProvider(TextProvider defaultTextProvider) {
this.defaultTextProvider = defaultTextProvider;
}

@Override
public TextProvider createInstance(Class clazz) {
TextProvider instance = getTextProvider(clazz);
Expand All @@ -61,10 +67,18 @@ public TextProvider createInstance(ResourceBundle bundle) {
}

protected TextProvider getTextProvider(Class clazz) {
if (defaultTextProvider != null) {
return defaultTextProvider;
}

return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
}

protected TextProvider getTextProvider(ResourceBundle bundle) {
if (defaultTextProvider != null) {
return defaultTextProvider;
}

return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
}

Expand Down

0 comments on commit d821c27

Please sign in to comment.