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
精彩评论