1 16 17 package org.apache.jetspeed.portal.controllers; 18 19 import org.apache.turbine.modules.ActionLoader; 21 import org.apache.turbine.services.velocity.TurbineVelocity; 22 import org.apache.turbine.services.pull.TurbinePull; 23 import org.apache.turbine.util.RunData; 24 25 import org.apache.jetspeed.services.TemplateLocator; 27 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 28 import org.apache.jetspeed.services.logging.JetspeedLogger; 29 30 import org.apache.ecs.ConcreteElement; 32 import org.apache.ecs.StringElement; 33 34 import org.apache.velocity.context.Context; 36 37 45 public class VelocityPortletController extends AbstractPortletController 46 { 47 48 51 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(VelocityPortletController.class.getName()); 52 53 public ConcreteElement getContent( RunData rundata ) 54 { 55 Context context = TurbineVelocity.getContext(); 58 59 context.put( "data", rundata ); 60 context.put( "controller", this ); 61 context.put( "portlets", this.getPortlets().toArray() ); 62 context.put( "config", this.getConfig() ); 63 context.put( "skin", this.getPortlets().getPortletConfig().getPortletSkin() ); 64 context.put( "template", getConfig().getInitParameter("template") ); 65 66 TurbinePull.populateContext(context, rundata); 68 69 buildContext(rundata, context); 71 72 String actionName = getConfig().getInitParameter("action"); 73 74 if (actionName != null) 75 { 76 rundata.getTemplateInfo().setTemplateContext( "VelocityControllerContext", context ); 78 79 try 81 { 82 ActionLoader.getInstance().exec( rundata, actionName ); 83 } 84 catch( Exception e) 85 { 86 logger.error("Exception", e); 87 } 88 } 89 90 String template = (String )context.get( "template" ); 93 94 String s = ""; 96 97 try 98 { 99 if (-1 == template.indexOf(".vm")) 100 { 101 template = template + ".vm"; 102 } 103 104 String templatePath = TemplateLocator.locateControllerTemplate(rundata, template); 105 TurbineVelocity.handleRequest(context, templatePath, rundata.getOut()); 106 } 107 catch( Exception e) 108 { 109 logger.error( "Error generating content: ", e ); 110 s= e.toString(); 111 } 112 113 TurbineVelocity.requestFinished(context); 114 115 return new StringElement( s ); 116 } 117 118 public void buildContext(RunData data, Context context) 119 { 120 } 122 } 123 124 | Popular Tags |