1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 /***
33 * This action enables to update the skin entries
34 *
35 * @author <a href="mailto:caius1440@hotmail.com">Jeremy Ford</a>
36 * @version $Id: SkinUpdateAction.java,v 1.6 2004/02/23 02:56:58 jford Exp $
37 */
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 /***
45 * Static initialization of the logger for this class
46 */
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 /***
57 * Subclasses must override this method to provide default behavior
58 * for the portlet action
59 */
60 /***
61 * Build the normal state content for this portlet.
62 *
63 * @param portlet The velocity-based portlet that is being built.
64 * @param context The velocity context for this request.
65 * @param rundata The turbine rundata context for this request.
66 */
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 /***
90 * @see org.apache.jetspeed.modules.actions.portlets.RegistryUpdateAction#updateRegistryEntry(org.apache.turbine.util.RunData, org.apache.jetspeed.om.registry.RegistryEntry)
91 */
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 /***
102 * Populates the user's temp storage with form data
103 * @param rundata The turbine rundata context for this request.
104 */
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 /***
131 * Adds parameters to a skin entry
132 * @param rundata The turbine rundata context for this request.
133 * @param skinEntry
134 */
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 /***
162 * Clears the temporary storage of any data that was used
163 * @param rundata
164 */
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 }