1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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.MediaTypeEntry;
20 import org.apache.jetspeed.om.registry.RegistryEntry;
21 import org.apache.jetspeed.portal.portlets.VelocityPortlet;
22 import org.apache.jetspeed.services.Registry;
23 import org.apache.turbine.util.RunData;
24 import org.apache.velocity.context.Context;
25
26 /***
27 * This action enables to update the media entries
28 *
29 * @author <a href="mailto:caius1440@hotmail.com">Jeremy Ford</a>
30 * @version $Id: MediaUpdateAction.java,v 1.2 2004/02/23 02:56:58 jford Exp $
31 */
32 public class MediaUpdateAction extends RegistryUpdateAction
33 {
34 private static final String MEDIA_UPDATE_PANE = "MediaForm";
35
36 public MediaUpdateAction()
37 {
38 registryEntryName = "media_type_name";
39 registry = Registry.MEDIA_TYPE;
40 pane = MEDIA_UPDATE_PANE;
41 }
42
43 /***
44 * @see org.apache.jetspeed.modules.actions.portlets.VelocityPortletAction#buildNormalContext(org.apache.jetspeed.portal.portlets.VelocityPortlet, org.apache.velocity.context.Context, org.apache.turbine.util.RunData)
45 */
46 protected void buildNormalContext(
47 VelocityPortlet portlet,
48 Context context,
49 RunData rundata)
50 throws Exception
51 {
52 super.buildNormalContext(portlet, context, rundata);
53
54 String mode =
55 rundata.getParameters().getString(SecurityConstants.PARAM_MODE);
56
57 if (mode != null
58 && (mode.equals(SecurityConstants.PARAM_MODE_DELETE)
59 || mode.equals(SecurityConstants.PARAM_MODE_UPDATE)))
60 {
61 String mediaTypeName =
62 rundata.getParameters().getString(registryEntryName);
63 MediaTypeEntry mediaEntry =
64 (MediaTypeEntry) Registry.getEntry(
65 registry,mediaTypeName);
66 context.put("entry", mediaEntry);
67 }
68 }
69
70 /***
71 * @see org.apache.jetspeed.modules.actions.portlets.RegistryUpdateAction#updateRegistryEntry(org.apache.turbine.util.RunData, org.apache.jetspeed.om.registry.RegistryEntry)
72 */
73 protected void updateRegistryEntry(RunData rundata, RegistryEntry registryEntry) throws Exception
74 {
75 super.updateRegistryEntry(rundata, registryEntry);
76
77 updateMediaTypeEntry(rundata, (MediaTypeEntry) registryEntry);
78 }
79
80 /***
81 * @param rundata
82 * @param mediaTypeName
83 */
84 protected void updateMediaTypeEntry(
85 RunData rundata,
86 MediaTypeEntry mediaTypeEntry)
87 {
88 String charSet = rundata.getParameters().getString("charset");
89 String mimeType = rundata.getParameters().getString("mime_type");
90
91 if(hasChanged(mediaTypeEntry.getCharacterSet(), charSet))
92 {
93 mediaTypeEntry.setCharacterSet(charSet);
94 }
95 if(hasChanged(mediaTypeEntry.getMimeType(), mimeType))
96 {
97 mediaTypeEntry.setMimeType(mimeType);
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 String charSet = rundata.getParameters().getString("charset");
109 String mimeType = rundata.getParameters().getString("mime_type");
110
111 rundata.getUser().setTemp("charset", charSet);
112 rundata.getUser().setTemp("mime_type", mimeType);
113 }
114
115 /***
116 * Clears the temporary storage of any data that was used
117 * @param rundata The turbine rundata context for this request.
118 */
119 protected void clearUserData(RunData rundata)
120 {
121 super.clearUserData(rundata);
122 rundata.getUser().removeTemp("charset");
123 rundata.getUser().removeTemp("mime_type");
124 }
125 }