1 16 17 package org.apache.jetspeed.modules.actions.controllers; 18 19 import org.apache.jetspeed.portal.PortletController; 21 import org.apache.jetspeed.services.rundata.JetspeedRunData; 22 import org.apache.jetspeed.services.statemanager.SessionState; 23 24 import org.apache.turbine.util.RunData; 26 import org.apache.turbine.services.velocity.TurbineVelocity; 27 import org.apache.turbine.modules.actions.VelocityAction; 28 import org.apache.turbine.services.localization.Localization; 29 30 import org.apache.velocity.context.Context; 32 33 42 public abstract class VelocityControllerAction extends VelocityAction 43 { 44 45 53 protected void perform( RunData rundata ) 54 throws Exception 55 { 56 Context context = getContext(rundata); 59 if (context != null) 60 { 61 doPerform(rundata); 64 } 65 else 66 { 67 context = TurbineVelocity.getContext(); 68 rundata.getTemplateInfo().setTemplateContext("VelocityActionContext",context); 69 try 70 { 71 executeEvents(rundata, context ); 72 } 73 catch (NoSuchMethodException e) 74 { 75 doPerform(rundata); 77 } 78 } 79 } 80 81 88 public void setTemplate(RunData data, 89 String template) 90 { 91 getContext(data).put( "template" , template ); 92 } 93 94 100 protected Context getContext(RunData data) 101 { 102 return (Context)data.getTemplateInfo() 103 .getTemplateContext( "VelocityControllerContext" ); 104 } 105 106 public void doPerform( RunData rundata, Context context ) 107 { 108 PortletController controller = (PortletController)context.get( "controller" ); 109 110 if (((JetspeedRunData)rundata).getMode()==JetspeedRunData.CUSTOMIZE) 113 { 114 buildCustomizeContext( controller, context, rundata); 115 return; 116 } 117 118 buildNormalContext( controller, context, rundata); 119 } 120 121 125 protected void buildCustomizeContext( PortletController controller, 126 Context context, 127 RunData rundata ) 128 { 129 String name = controller.getPortlets().getName(); 130 String template = (String )context.get("template"); 131 132 int dotIdx = template.lastIndexOf('.'); 133 if (dotIdx > -1) 134 { 135 template = template.substring(0,dotIdx) 136 + "-customize.vm"; 137 } 138 else 139 { 140 template = template+"-customize"; 141 } 142 143 setTemplate(rundata, template); 144 145 context.put( "action", controller.getConfig().getInitParameter("action")); 146 147 JetspeedRunData jdata = (JetspeedRunData) rundata; 150 151 SessionState customizationState = jdata.getPageSessionState(); 153 154 String saveLabel = null; 155 if (((String ) customizationState.getAttribute("customize-paneName")).equalsIgnoreCase("*")) 156 { 157 saveLabel = Localization.getString(rundata, "CUSTOMIZER_SAVEAPPLY"); 158 } 159 else 160 { 161 saveLabel = Localization.getString(rundata, "CUSTOMIZER_APPLY"); 162 } 163 context.put("saveLabel", saveLabel); 164 165 } 166 167 171 protected abstract void buildNormalContext( PortletController controller, 172 Context context, 173 RunData rundata ); 174 175 176 178 public void doCancel(RunData data, Context context) 179 { 180 } 182 } 183 | Popular Tags |