1 16 17 package org.apache.struts.chain; 18 19 20 import org.apache.commons.chain.Command; 21 import org.apache.commons.chain.Context; 22 import org.apache.commons.chain.web.WebContext; 23 import org.apache.struts.Globals; 24 import org.apache.struts.chain.Constants; 25 import org.apache.struts.config.ModuleConfig; 26 import org.apache.struts.util.MessageResources; 27 28 29 37 38 public abstract class AbstractSelectModule implements Command { 39 40 41 43 44 private String messageResourcesKey = Constants.MESSAGE_RESOURCES_KEY; 45 private String moduleConfigKey = Constants.MODULE_CONFIG_KEY; 46 47 48 50 51 56 public String getMessageResourcesKey() { 57 58 return (this.messageResourcesKey); 59 60 } 61 62 63 70 public void setMessageResourcesKey(String messageResourcesKey) { 71 72 this.messageResourcesKey = messageResourcesKey; 73 74 } 75 76 77 82 public String getModuleConfigKey() { 83 84 return (this.moduleConfigKey); 85 86 } 87 88 89 96 public void setModuleConfigKey(String moduleConfigKey) { 97 98 this.moduleConfigKey = moduleConfigKey; 99 100 } 101 102 103 105 106 118 public boolean execute(Context context) throws Exception { 119 120 String prefix = getPrefix(context); 122 123 WebContext wcontext = (WebContext) context; 125 ModuleConfig moduleConfig = (ModuleConfig) 126 wcontext.getApplicationScope().get(Globals.MODULE_KEY + prefix); 127 if (moduleConfig == null) { 128 throw new IllegalArgumentException ("No module config for prefix '" + 129 prefix + "'"); 130 } 131 wcontext.put(getModuleConfigKey(), moduleConfig); 132 wcontext.getRequestScope().put(Globals.MODULE_KEY, moduleConfig); 133 MessageResources messageResources = (MessageResources) 134 wcontext.getApplicationScope().get(Globals.MESSAGES_KEY + prefix); 135 if (messageResources != null) { 136 wcontext.put(getMessageResourcesKey(), 137 messageResources); 138 wcontext.getRequestScope().put(Globals.MESSAGES_KEY, 139 messageResources); 140 } 141 142 return (false); 143 144 } 145 146 147 149 150 159 protected abstract String getPrefix(Context context); 160 161 162 } 163 | Popular Tags |