1 16 17 package org.apache.jetspeed.modules.actions.portlets; 18 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.apache.jetspeed.modules.actions.portlets.security.SecurityConstants; 23 import org.apache.jetspeed.om.registry.RegistryEntry; 24 import org.apache.jetspeed.om.registry.SkinEntry; 25 import org.apache.jetspeed.portal.portlets.VelocityPortlet; 26 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 27 import org.apache.jetspeed.services.logging.JetspeedLogger; 28 import org.apache.jetspeed.services.Registry; 29 import org.apache.turbine.util.RunData; 30 import org.apache.velocity.context.Context; 31 32 38 public class SkinUpdateAction extends RegistryUpdateAction 39 { 40 41 private static final String PARAMETER = "parameter."; 42 private static final String SKIN_UPDATE_PANE = "SkinForm"; 43 44 47 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(SkinUpdateAction.class.getName()); 48 49 public SkinUpdateAction() 50 { 51 registryEntryName = "skinname"; 52 registry = Registry.SKIN; 53 pane = SKIN_UPDATE_PANE; 54 } 55 56 60 67 protected void buildNormalContext( 68 VelocityPortlet portlet, 69 Context context, 70 RunData rundata) 71 throws Exception 72 { 73 super.buildNormalContext(portlet, context, rundata); 74 75 String mode = 76 rundata.getParameters().getString(SecurityConstants.PARAM_MODE); 77 78 if (mode != null 79 && (mode.equals(SecurityConstants.PARAM_MODE_DELETE) 80 || mode.equals(SecurityConstants.PARAM_MODE_UPDATE))) 81 { 82 String skinName = rundata.getParameters().getString("skinname"); 83 SkinEntry skinEntry = 84 (SkinEntry) Registry.getEntry(Registry.SKIN, skinName); 85 context.put("entry", skinEntry); 86 } 87 } 88 89 92 protected void updateRegistryEntry( 93 RunData rundata, 94 RegistryEntry registryEntry) throws Exception 95 { 96 super.updateRegistryEntry(rundata, registryEntry); 97 updateParameters(rundata, (SkinEntry) registryEntry); 98 99 } 100 101 105 protected void resetForm(RunData rundata) 106 { 107 super.resetForm(rundata); 108 109 Object [] keys = rundata.getParameters().getKeys(); 110 if (keys != null) 111 { 112 for (int i = 0; i < keys.length; i++) 113 { 114 String key = (String ) keys[i]; 115 116 if (key.startsWith(PARAMETER)) 117 { 118 String parameterValue = 119 rundata.getParameters().getString(key); 120 121 if (parameterValue != null && parameterValue.length() > 0) 122 { 123 rundata.getUser().setTemp(key, parameterValue); 124 } 125 } 126 } 127 } 128 } 129 130 135 private void updateParameters(RunData rundata, SkinEntry skinEntry) 136 { 137 Object [] keys = rundata.getParameters().getKeys(); 138 if (keys != null) 139 { 140 for (int i = 0; i < keys.length; i++) 141 { 142 String key = (String ) keys[i]; 143 144 if (key.startsWith(PARAMETER)) 145 { 146 String parameterValue = 147 rundata.getParameters().getString(key); 148 149 if (parameterValue != null && parameterValue.length() > 0) 150 { 151 String parameterName = 152 key.substring(PARAMETER.length()); 153 skinEntry.removeParameter(parameterName); 154 skinEntry.addParameter(parameterName, parameterValue); 155 } 156 } 157 } 158 } 159 } 160 161 165 protected void clearUserData(RunData rundata) 166 { 167 try 168 { 169 super.clearUserData(rundata); 170 171 Map tempStorage = rundata.getUser().getTempStorage(); 172 if (tempStorage != null) 173 { 174 Iterator keyIter = tempStorage.keySet().iterator(); 175 while (keyIter.hasNext()) 176 { 177 Object keyObj = keyIter.next(); 178 if (keyObj instanceof String ) 179 { 180 String key = (String ) keyObj; 181 if (key.startsWith(PARAMETER)) 182 { 183 keyIter.remove(); 184 } 185 } 186 } 187 } 188 } 189 catch (Exception e) 190 { 191 if (logger.isDebugEnabled()) 192 { 193 logger.debug("SkinUpdateAction: Failed to clear user data"); 194 } 195 } 196 } 197 } 198 | Popular Tags |