1 23 24 package org.infoglue.cms.applications.tasktool.actions; 25 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import javax.servlet.http.HttpServletRequest ; 30 31 import org.apache.log4j.Logger; 32 import org.exolab.castor.jdo.Database; 33 import org.infoglue.cms.controllers.kernel.impl.simple.CastorDatabaseService; 34 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController; 35 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 36 import org.infoglue.cms.controllers.kernel.impl.simple.LanguageController; 37 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController; 38 import org.infoglue.cms.controllers.kernel.impl.simple.ServiceBindingController; 39 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeController; 40 import org.infoglue.cms.controllers.kernel.impl.simple.SiteNodeVersionController; 41 import org.infoglue.cms.exception.SystemException; 42 import org.infoglue.cms.security.InfoGluePrincipal; 43 44 import webwork.action.ActionContext; 45 46 49 50 public class BasicScriptController implements ScriptController 51 { 52 private final static Logger logger = Logger.getLogger(BasicScriptController.class.getName()); 53 54 private Database db = null; 55 private HttpServletRequest request = null; 56 private Map outputParameters = new HashMap (); 57 private final InfoGluePrincipal infoGluePrincipal; 58 59 60 64 65 public BasicScriptController(InfoGluePrincipal infoGluePrincipal) throws SystemException, Exception 66 { 67 this.db = CastorDatabaseService.getDatabase(); 68 this.infoGluePrincipal = infoGluePrincipal; 69 } 70 71 74 75 public HttpServletRequest getRequest() 76 { 77 return this.request; 78 } 79 80 83 84 public void setRequest(HttpServletRequest request) 85 { 86 this.request = request; 87 } 88 89 90 93 94 public SiteNodeController getSiteNodeController() 95 { 96 return new SiteNodeController(); 97 } 98 99 102 103 public RepositoryController getRepositoryController() 104 { 105 return new RepositoryController(); 106 } 107 108 111 112 public ServiceBindingController getServiceBindingController() 113 { 114 return new ServiceBindingController(); 115 } 116 117 120 121 public SiteNodeVersionController getSiteNodeVersionController() 122 { 123 return new SiteNodeVersionController(); 124 } 125 126 127 130 131 public ContentController getContentController() 132 { 133 return new ContentController(); 134 } 135 136 139 140 public ContentVersionController getContentVersionController() 141 { 142 return new ContentVersionController(); 143 } 144 145 148 149 public LanguageController getLanguageController() 150 { 151 return new LanguageController(); 152 } 153 154 157 158 public InfoGluePrincipal getInfoGluePrincipal() 159 { 160 return infoGluePrincipal; 161 } 162 163 166 167 public Integer getInteger(String value) 168 { 169 return new Integer (value); 170 } 171 172 175 176 public boolean isNull(Object object) 177 { 178 if(object == null) 179 return true; 180 else 181 return false; 182 } 183 184 187 188 public ActionContext getActionContext() 189 { 190 return ActionContext.getContext(); 191 } 192 193 196 197 public Object getObjectWithName(String className) 198 { 199 try 200 { 201 Class theClass = null; 202 try 203 { 204 theClass = Thread.currentThread().getContextClassLoader().loadClass( className ); 205 } 206 catch (ClassNotFoundException e) 207 { 208 theClass = getClass().getClassLoader().loadClass( className ); 209 } 210 return theClass.newInstance(); 211 212 } 213 catch (InstantiationException e) 214 { 215 e.printStackTrace(); 216 } 217 catch (IllegalAccessException e) 218 { 219 e.printStackTrace(); 220 } 221 catch (ClassNotFoundException e) 222 { 223 e.printStackTrace(); 224 } 225 226 return null; 227 } 228 229 232 233 public Database getDatabase() 234 { 235 return this.db; 236 } 237 238 241 242 public Object getOutputParameter(String parameter) 243 { 244 return this.outputParameters.get(parameter); 245 } 246 247 250 251 public void setOutputParameter(String parameter, Object value) 252 { 253 this.outputParameters.put(parameter, value); 254 } 255 256 257 260 261 public void beginTransaction() throws SystemException 262 { 263 try 264 { 265 this.db.begin(); 266 } 267 catch(Exception e) 268 { 269 e.printStackTrace(); 270 throw new SystemException("An error occurred when we tried to begin an transaction. Reason:" + e.getMessage(), e); 271 } 272 } 273 274 277 278 public void commitTransaction() throws SystemException 279 { 280 try 281 { 282 this.db.commit(); 283 this.db.close(); 284 } 285 catch(Exception e) 286 { 287 e.printStackTrace(); 288 throw new SystemException("An error occurred when we tried to commit an transaction. Reason:" + e.getMessage(), e); 289 } 290 } 291 292 293 296 297 public void rollbackTransaction() throws SystemException 298 { 299 try 300 { 301 if (this.db.isActive()) 302 { 303 this.db.rollback(); 304 this.db.close(); 305 } 306 } 307 catch(Exception e) 308 { 309 logger.info("An error occurred when we tried to rollback an transaction. Reason:" + e.getMessage()); 310 } 312 } 313 314 315 318 319 public void logInfo(String info) 320 { 321 logger.info(info); 322 } 323 324 327 328 public void logInfo(String header, String info) 329 { 330 logger.info(header + ": " + info); 331 } 332 333 336 337 public void logInfo(String header, boolean info) 338 { 339 logger.info(header + ": " + info); 340 } 341 342 345 346 public void logInfo(String header, int info) 347 { 348 logger.info(header + ": " + info); 349 } 350 351 354 355 public void logInfo(String header, Object info) 356 { 357 logger.info(header + ": " + info); 358 } 359 360 361 364 365 public void logWarning(String info) 366 { 367 logger.warn(info); 368 } 369 370 373 374 public void logWarning(String header, String info) 375 { 376 logger.warn(header + ": " + info); 377 } 378 379 382 383 public void logWarning(String header, boolean info) 384 { 385 logger.warn(header + ": " + info); 386 } 387 388 391 392 public void logWarning(String header, int info) 393 { 394 logger.info(header + ": " + info); 395 } 396 397 400 401 public void logWarning(String header, Object info) 402 { 403 logger.warn(header + ": " + info); 404 } 405 406 } 407 | Popular Tags |