Liggy
Liggy

Reputation: 1201

Is there a PropertyPlaceholderConfigurer for <portlet-preferences>?

I understand that there is the ServletContextPropertyPlaceholderConfigurer which:

resolves placeholders as ServletContext init 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)?

Upvotes: 2

Views: 610

Answers (1)

Gerson Galang
Gerson Galang

Reputation: 196

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

Upvotes: 4

Related Questions