Migrate from Struts 2.3.33 to Struts 2.5.12 LocalizedTextUtil is removed

前端 未结 2 1711
天命终不由人
天命终不由人 2021-01-26 00:41

We tried to migrate from Struts 2.33 to Struts 2.5.12.

We used LocalizedTextUtil in our application directly.

I found that the LocalizedTextU

2条回答
  •  感情败类
    2021-01-26 01:21

    The struts.xml should be set as:

    
    
    

    And CustomStrutsTextProviderFactory could add bundles

    public class MyTextProviderFactory implements TextProviderFactory {
    
    protected LocaleProviderFactory localeProviderFactory;
    protected LocalizedTextProvider localizedTextProvider;
    
    @Inject
    public MyTextProviderFactory(LocaleProviderFactory localeProviderFactory, LocalizedTextProvider localizedTextProvider) {
        this.localeProviderFactory = localeProviderFactory;
        this.localizedTextProvider = localizedTextProvider;
    
        this.localizedTextProvider.addDefaultResourceBundle("messages/label");
        this.localizedTextProvider.addDefaultResourceBundle("messages/customerA/label");
    
    }
    
    @Override
    public TextProvider createInstance(Class clazz) {
        TextProvider instance = getTextProvider(clazz);
        if (instance instanceof ResourceBundleTextProvider) {
            ((ResourceBundleTextProvider) instance).setClazz(clazz);
            ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
        }
        return instance;
    }
    
    @Override
    public TextProvider createInstance(ResourceBundle bundle) {
        TextProvider instance = getTextProvider(bundle);
        if (instance instanceof ResourceBundleTextProvider) {
            ((ResourceBundleTextProvider) instance).setBundle(bundle);
            ((ResourceBundleTextProvider) instance).setLocaleProvider(localeProviderFactory.createLocaleProvider());
        }
        return instance;
    }
    
    protected TextProvider getTextProvider(Class clazz) {
        return new TextProviderSupport(clazz, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
    }
    
    protected TextProvider getTextProvider(ResourceBundle bundle) {
        return new TextProviderSupport(bundle, localeProviderFactory.createLocaleProvider(), localizedTextProvider);
    }
    

    }

    Complete credits to @LukazLenart https://issues.apache.org/jira/browse/WW-4829

提交回复
热议问题