开发者

Is there a PropertyPlaceholderConfigurer for <portlet-preferences>?

开发者 https://www.devze.com 2023-01-23 18:27 出处:网络
I understand that there is the ServletContextPropertyPlaceholderConfigurer which: resolves placeholders as ServletContext in开发者_如何学编程it parameters (that is, web.xml context-param entries).

I understand that there is the ServletContextPropertyPlaceholderConfigurer which:

resolves placeholders as ServletContext in开发者_如何学编程it parameters (that is, web.xml context-param entries).

Does anyone know of a PropertyPlaceholderConfigurer that would similarly resolve placeholders as portlet-preferences (that is, portlet.xml portlet-preference entries)?


Here's how I solved the problem, I ended up writing a class similar to 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);
    }
}

Cheers, Gerson

0

精彩评论

暂无评论...
验证码 换一张
取 消