是否有<portlet-preferences>的PropertyPlaceholderConfigurer?</portlet-preferences>

时间:2010-11-02 18:25:03

标签: spring portlet preferences

我知道有ServletContextPropertyPlaceholderConfigurer

  

将占位符解析为ServletContext init参数(即web.xml context-param条目)。

是否有人知道PropertyPlaceholderConfigurer类似地将占位符解析为portlet-preferences(即portlet.xml portlet-preference个条目?

1 个答案:

答案 0 :(得分:4)

以下是我解决问题的方法,最后编写了一个类似于ServletContextPropertyPlaceholderConfigurer的类: - )

public class PortletConfigPropertyPlaceholderConfigurer extends
        PropertyPlaceholderConfigurer implements PortletConfigAware {

    private PortletConfig portletConfig;

    private boolean configOverride = false;

    public void setPortletConfig(PortletConfig portletConfig) {
        this.portletConfig = portletConfig;
    }

    public void setConfigOverride(boolean configOverride) {
        this.configOverride = configOverride;
    }

    @Override
    protected String resolvePlaceholder(String placeholder, Properties props) {
        String value = null;
        if (this.configOverride && this.portletConfig != null) {
            value = resolvePlaceholder(placeholder, this.portletConfig);
        }
        if (value == null) {
            value = super.resolvePlaceholder(placeholder, props);
        }
        return value;
    }

    protected String resolvePlaceholder(String placeholder,
            PortletConfig portletConfig) {
        return portletConfig.getInitParameter(placeholder);
    }
}

干杯, 格