小编典典

从Struts 2.3.33迁移到Struts 2.5.12 LocalizedTextUtil已删除

java

我们试图从Struts 2.33迁移到Struts 2.5.12。

我们LocalizedTextUtil直接在应用程序中使用过。

我发现将LocalizedTextUtil删除了com.opensymphony.xwork2.util.LocalizedTextUtil。我试图搜索但找不到任何东西

我发现了一些类似的类StrutsLocalizedTextProviderGlobalLocalizedTextProvider但似乎它们不是我可以使用的类。

我已经查看了迁移指南,但找不到对此的任何评论。

有哪一种选择?


阅读 1078

收藏
2020-11-30

共1个答案

小编典典

struts.xml应设置为:

<constant name="struts.xworkTextProvider" value="DefaultTextProvider" />
<bean type="com.opensymphony.xwork2.TextProvider" name="DefaultTextProvider" class="utils.CustomTextProvider" scope="default" />

CustomStrutsTextProviderFactory可以添加捆绑

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);
}

}

完整积分@LukazLenart
https://issues.apache.org/jira/browse/WW-4829

2020-11-30