1 16 package org.apache.jetspeed.modules.actions.portlets; 17 18 import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants; 19 import org.apache.jetspeed.om.registry.MediaTypeRegistry; 20 import org.apache.jetspeed.om.registry.PortletControllerEntry; 21 import org.apache.jetspeed.om.registry.RegistryEntry; 22 import org.apache.jetspeed.portal.portlets.VelocityPortlet; 23 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 24 import org.apache.jetspeed.services.logging.JetspeedLogger; 25 26 import org.apache.jetspeed.services.Registry; 27 import org.apache.turbine.util.RunData; 28 import org.apache.velocity.context.Context; 29 30 36 public class ControllerUpdateAction extends RegistryUpdateAction 37 { 38 private static final String CONTROLLER_UPDATE_PANE = "ControllerForm"; 39 40 43 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(ControllerUpdateAction.class.getName()); 44 45 public ControllerUpdateAction() 46 { 47 registryEntryName = "controller_name"; 48 registry = Registry.PORTLET_CONTROLLER; 49 pane = CONTROLLER_UPDATE_PANE; 50 } 51 52 55 protected void buildNormalContext( 56 VelocityPortlet portlet, 57 Context context, 58 RunData rundata) 59 throws Exception 60 { 61 super.buildNormalContext(portlet, context, rundata); 62 63 String mode = 64 rundata.getParameters().getString(SecurityConstants.PARAM_MODE); 65 66 if (mode != null) 67 { 68 if(mode.equals(SecurityConstants.PARAM_MODE_DELETE) 69 || mode.equals(SecurityConstants.PARAM_MODE_UPDATE)) 70 { 71 String controllerName = 72 rundata.getParameters().getString(registryEntryName); 73 PortletControllerEntry controllerEntry = 74 (PortletControllerEntry) Registry.getEntry( 75 registry, 76 controllerName); 77 context.put("entry", controllerEntry); 78 } 79 80 if(mode.equals(SecurityConstants.PARAM_MODE_UPDATE)) 81 { 82 MediaTypeRegistry mediaTypeReg = (MediaTypeRegistry)Registry.get(Registry.MEDIA_TYPE); 83 context.put("media_types", iteratorToCollection(mediaTypeReg.listEntryNames())); 84 } 85 } 86 } 87 88 protected void updateRegistryEntry( 89 RunData rundata, 90 RegistryEntry registryEntry) 91 throws Exception 92 { 93 super.updateRegistryEntry(rundata, registryEntry); 94 95 PortletControllerEntry controllerEntry = 96 (PortletControllerEntry) registryEntry; 97 String className = rundata.getParameters().getString("class_name"); 98 if (hasChanged(controllerEntry.getClassname(), className)) 99 { 100 controllerEntry.setClassname(className); 101 } 102 } 103 104 107 protected void clearUserData(RunData rundata) 108 { 109 try 110 { 111 super.clearUserData(rundata); 112 113 rundata.getUser().removeTemp("media_type_ref"); 114 } 115 catch (Exception e) 116 { 117 if (logger.isDebugEnabled()) 118 { 119 logger.debug("ControllerUpdateAction: Failed to clear user data"); 120 } 121 } 122 123 } 124 125 128 protected void resetForm(RunData rundata) 129 { 130 super.resetForm(rundata); 131 String mediaTypeRef = 132 rundata.getParameters().getString("media_type_ref"); 133 134 rundata.getUser().setTemp("media_type_ref", mediaTypeRef); 135 } 136 } 137 | Popular Tags |