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.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 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 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 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 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 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 119 protected void clearUserData(RunData rundata) 120 { 121 super.clearUserData(rundata); 122 rundata.getUser().removeTemp("charset"); 123 rundata.getUser().removeTemp("mime_type"); 124 } 125 } 126 | Popular Tags |