Fix so widgets can invoke I18N method.
This commit is contained in:
parent
9a7a385b87
commit
dbcc75dc20
1 changed files with 12 additions and 2 deletions
|
@ -10,6 +10,7 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -107,6 +108,7 @@ public abstract class Widget {
|
||||||
|
|
||||||
private String processMacroToString(Environment env, String widgetName, Macro macro, Map<String, Object> map) {
|
private String processMacroToString(Environment env, String widgetName, Macro macro, Map<String, Object> map) {
|
||||||
StringWriter out = new StringWriter();
|
StringWriter out = new StringWriter();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String templateString = macro.getChildNodes().get(0).toString();
|
String templateString = macro.getChildNodes().get(0).toString();
|
||||||
// NB Using this method of creating a template from a string does not allow the widget template to import
|
// NB Using this method of creating a template from a string does not allow the widget template to import
|
||||||
|
@ -118,7 +120,15 @@ public abstract class Widget {
|
||||||
// We need to give each widget macro template a unique key in the StringTemplateLoader, and check
|
// We need to give each widget macro template a unique key in the StringTemplateLoader, and check
|
||||||
// if it's already there or else add it. Leave this for later.
|
// if it's already there or else add it. Leave this for later.
|
||||||
Template template = new Template("widget", new StringReader(templateString), env.getConfiguration());
|
Template template = new Template("widget", new StringReader(templateString), env.getConfiguration());
|
||||||
template.process(map, out);
|
|
||||||
|
// JB KLUGE The widget is processed in its own environment, which doesn't include these custom attributes.
|
||||||
|
// JB KLUGE Put them in.
|
||||||
|
Environment widgetEnv = template.createProcessingEnvironment(map, out);
|
||||||
|
ServletRequest request = (ServletRequest) env.getCustomAttribute("request");
|
||||||
|
widgetEnv.setCustomAttribute("request", request);
|
||||||
|
widgetEnv.setCustomAttribute("context", env.getCustomAttribute("context"));
|
||||||
|
widgetEnv.setLocale(request.getLocale());
|
||||||
|
widgetEnv.process();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Could not process widget " + widgetName, e);
|
log.error("Could not process widget " + widgetName, e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue