1 25 26 package net.killingar.forum.actions; 27 28 import net.killingar.actions.ActionSupport; 29 import net.killingar.forum.internal.AccessLevel; 30 import net.killingar.forum.internal.User; 31 import net.killingar.forum.internal.managers.ForumManager; 32 import net.killingar.forum.internal.managers.ItemListManager; 33 import net.killingar.forum.internal.managers.OptionsManager; 34 import net.killingar.forum.internal.managers.TimeManager; 35 import webwork.action.SessionAware; 36 37 import java.util.Map ; 38 39 public class ActionForumSupport 40 extends ActionSupport 41 implements SessionAware 42 { 43 protected long start; 44 45 protected static final String CHAIN = "chain"; 46 47 protected Map session; 49 protected ForumManager manager; 50 protected OptionsManager optionmgr; 51 protected TimeManager timemgr; 52 protected ItemListManager itemlistmgr; 53 54 public User getCurrentUser() throws Exception { return manager.getUser(manager.getUserID()); } 55 56 public ForumManager getManager() { return manager; } 57 public OptionsManager getOptionsmgr() { return optionmgr; } 58 public ItemListManager getItemlistmgr() { return itemlistmgr; } 59 60 public void setManager(ForumManager in) { manager = in; } 61 62 public long getExecutionTime() { return System.currentTimeMillis()-start; } 64 65 public long getUnreadFromHereTime(java.util.Date inDate) { return inDate.getTime()-1; } 66 67 public boolean getHasAccess(String s) throws java.sql.SQLException 68 { 69 long access = AccessLevel.everything; 70 try 71 { 72 access = Long.parseLong(s); 73 } 74 catch (NumberFormatException e) 75 { 76 access = AccessLevel.parseAccessLevel(s); 77 } 78 return manager.hasAccess(manager.getUserID(), access); 79 } 80 81 public String execute() throws Exception 82 { 83 start = System.currentTimeMillis(); 84 return super.execute(); 85 } 86 87 public String getOption(String in) throws Exception 88 { 89 return optionmgr.get(in); 90 } 91 92 public void setSession(Map session) 94 { 95 this.session = session; 96 97 try 99 { 100 synchronized (session) 101 { 102 manager = (net.killingar.forum.internal.managers.ForumManager)session.get("manager"); 103 if (manager == null) 104 { 105 manager = new net.killingar.forum.internal.managers.ForumManager(); 106 session.put("manager", manager); 107 } 108 109 optionmgr = (OptionsManager)manager.getManager(OptionsManager.class.getName()); 110 timemgr = (TimeManager)manager.getManager(TimeManager.class.getName()); 111 itemlistmgr = (ItemListManager)manager.getManager(ItemListManager.class.getName()); 112 113 String locale = (String )optionmgr.get("locale"); 114 session.put("locale", locale); 115 } 116 } 117 catch (Exception e) 118 { 119 addErrorMessage("failed to initialize forum manager, exception thrown ("+e.toString()+")"); 120 } 121 122 super.setSession(session); 123 } 124 } | Popular Tags |