1 16 17 package org.apache.jetspeed.modules.parameters; 18 19 import org.apache.turbine.util.RunData; 21 import org.apache.turbine.services.velocity.TurbineVelocity; 22 import org.apache.turbine.services.localization.LocalizationTool; 23 import java.util.Map ; 25 26 import org.apache.jetspeed.services.TemplateLocator; 28 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 29 import org.apache.jetspeed.services.logging.JetspeedLogger; 30 import org.apache.jetspeed.util.template.BaseJetspeedLink; 31 32 import org.apache.velocity.context.Context; 34 35 57 58 public class VelocityParameterPresentationStyle extends ParameterPresentationStyle 59 { 60 61 64 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(VelocityParameterPresentationStyle.class.getName()); 65 66 75 public String getContent(RunData data, String name, String value, Map parms) 76 { 77 String result = null; 78 79 Context context = TurbineVelocity.getContext(); 81 82 context.put("data", data); 84 context.put("name", name); 85 context.put("value", value); 86 context.put("parms", parms); 87 context.put("events", this.getJavascriptEvents()); 88 LocalizationTool lt = new LocalizationTool(); 89 lt.init(data); 90 context.put("l10n", lt); 91 context.put("jslink", new BaseJetspeedLink(data)); 92 93 try 94 { 95 this.buildContext(data, name, value, parms, context); 97 98 String className = this.getClass().getName(); 100 int pos = className.lastIndexOf("."); 101 pos = pos < 0 ? 0 : pos + 1; 102 className = className.substring(pos); 103 104 String template = (String ) this.getParm("template", className + ".vm"); 106 String templatePath = TemplateLocator.locateParameterTemplate(data, template); 107 result = TurbineVelocity.handleRequest(context, templatePath); 108 } 109 catch (Exception e) 110 { 111 logger.error("Exception", e); 112 result = "<input type=\"text\" name=\"" + name + "\" value=\"" + value + "\""; 114 } 115 116 TurbineVelocity.requestFinished(context); 117 118 return result; 119 120 } 121 122 131 public void buildContext(RunData data, String name, String value, Map parms, Context context) 132 { 133 134 } 135 } | Popular Tags |