1 package org.tigris.scarab.actions.base; 2 3 48 49 51 import org.apache.fulcrum.parser.ParameterParser; 53 import org.apache.log4j.Logger; 54 import org.apache.turbine.RunData; 55 import org.apache.turbine.TemplateAction; 56 import org.apache.turbine.TemplateContext; 57 import org.apache.turbine.tool.IntakeTool; 58 import org.tigris.scarab.tools.ScarabLocalizationTool; 59 import org.tigris.scarab.tools.ScarabRequestTool; 60 import org.tigris.scarab.util.ScarabConstants; 61 62 69 public abstract class ScarabTemplateAction extends TemplateAction 70 { 71 private static final Logger LOG = Logger.getLogger("org.tigris.scarab"); 72 73 protected static final String ERROR_MESSAGE = 74 "MoreInformationWasRequired"; 75 protected static final String NO_PERMISSION_MESSAGE = 76 "YouDoNotHavePermissionToAction"; 77 protected static final String DEFAULT_MSG = "YourChangesWereSaved"; 78 protected static final String EMAIL_ERROR = "CouldNotSendEmail"; 79 80 83 public IntakeTool getIntakeTool(TemplateContext context) 84 { 85 return (IntakeTool) getTool(context, 86 ScarabConstants.INTAKE_TOOL); 87 } 88 89 92 public ScarabRequestTool getScarabRequestTool(TemplateContext context) 93 { 94 return (ScarabRequestTool)context 95 .get(ScarabConstants.SCARAB_REQUEST_TOOL); 96 } 97 98 101 protected final ScarabLocalizationTool 102 getLocalizationTool(TemplateContext context) 103 { 104 return (ScarabLocalizationTool) 105 context.get(ScarabConstants.LOCALIZATION_TOOL); 106 } 107 108 112 public String getCurrentTemplate(RunData data) 113 { 114 return data.getParameters() 115 .getString(ScarabConstants.TEMPLATE, null); 116 } 117 118 122 public String getCurrentTemplate(RunData data, String defaultValue) 123 { 124 return data.getParameters() 125 .getString(ScarabConstants.TEMPLATE, defaultValue); 126 } 127 128 131 public String getNextTemplate(RunData data) 132 { 133 return data.getParameters() 134 .getString(ScarabConstants.NEXT_TEMPLATE, null); 135 } 136 137 140 public String getNextTemplate(RunData data, String defaultValue) 141 { 142 return data.getParameters() 143 .getString(ScarabConstants.NEXT_TEMPLATE, defaultValue); 144 } 145 146 149 public String getLastTemplate(RunData data) 150 { 151 return data.getParameters() 152 .getString(ScarabConstants.LAST_TEMPLATE, null); 153 } 154 155 158 public String getCancelTemplate(RunData data) 159 { 160 return data.getParameters() 161 .getString(ScarabConstants.CANCEL_TEMPLATE, null); 162 } 163 164 168 public String getCancelTemplate(RunData data, String defaultValue) 169 { 170 return data.getParameters() 171 .getString(ScarabConstants.CANCEL_TEMPLATE, 172 defaultValue); 173 } 174 175 178 public String getBackTemplate(RunData data) 179 { 180 return data.getParameters() 181 .getString(ScarabConstants.BACK_TEMPLATE, null); 182 } 183 184 188 public String getBackTemplate(RunData data, String defaultValue) 189 { 190 return data.getParameters() 191 .getString(ScarabConstants.BACK_TEMPLATE, defaultValue); 192 } 193 194 198 public String getOtherTemplate(RunData data) 199 { 200 return data.getParameters() 201 .getString(ScarabConstants.OTHER_TEMPLATE); 202 } 203 204 public void doSave(RunData data, TemplateContext context) 205 throws Exception 206 { 207 } 208 209 public void doGonext(RunData data, TemplateContext context) 210 throws Exception 211 { 212 setTarget(data, getNextTemplate(data)); 213 } 214 215 public void doGotoothertemplate(RunData data, 216 TemplateContext context) 217 throws Exception 218 { 219 data.getParameters().setString(ScarabConstants.CANCEL_TEMPLATE, 220 getCurrentTemplate(data)); 221 setTarget(data, getOtherTemplate(data)); 222 } 223 224 public void doRefresh(RunData data, TemplateContext context) 225 throws Exception 226 { 227 setTarget(data, getCurrentTemplate(data)); 228 } 229 230 public void doReset(RunData data, TemplateContext context) 231 throws Exception 232 { 233 IntakeTool intake = getIntakeTool(context); 234 intake.removeAll(); 235 setTarget(data, getCurrentTemplate(data)); 236 } 237 238 public void doCancel(RunData data, TemplateContext context) 239 throws Exception 240 { 241 setTarget(data, getCancelTemplate(data)); 242 } 243 244 public void doDone(RunData data, TemplateContext context) 245 throws Exception 246 { 247 doSave(data, context); 248 doCancel(data, context); 249 } 250 251 protected Logger log() 252 { 253 return LOG; 254 } 255 256 public void doRefreshresultsperpage(RunData data, TemplateContext context) 257 throws Exception 258 { 259 ParameterParser params = data.getParameters(); 260 int oldResultsPerPage = params.getInt("oldResultsPerPage"); 261 int newResultsPerPage = params.getInt("resultsPerPage"); 262 int oldPageNum = params.getInt("pageNum"); 263 264 int firstItem = (oldPageNum - 1) * oldResultsPerPage + 1; 269 int newPageNum = (firstItem / newResultsPerPage) + 1; 270 params.remove("oldResultsPerPage"); 271 params.remove("pageNum"); 272 params.add("pageNum", newPageNum); 273 setTarget(data, getCurrentTemplate(data)); 274 } 275 } 276 | Popular Tags |