PageRenderTime 47ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/src/main/java/cn/javaeye/lonlysky/lforum/AdminBaseAction.java

http://fishkang.googlecode.com/
Java | 333 lines | 236 code | 50 blank | 47 comment | 36 complexity | 532d9914812066d6afd8d11804017f82 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  1. package cn.javaeye.lonlysky.lforum;
  2. import java.util.Date;
  3. import java.util.List;
  4. import org.apache.commons.lang.time.DateUtils;
  5. import org.dom4j.Document;
  6. import org.dom4j.Element;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import cn.javaeye.lonlysky.lforum.comm.LForumRequest;
  9. import cn.javaeye.lonlysky.lforum.comm.utils.ForumUtils;
  10. import cn.javaeye.lonlysky.lforum.comm.utils.Utils;
  11. import cn.javaeye.lonlysky.lforum.comm.utils.XmlElementUtil;
  12. import cn.javaeye.lonlysky.lforum.entity.forum.Online;
  13. import cn.javaeye.lonlysky.lforum.entity.forum.Usergroups;
  14. import cn.javaeye.lonlysky.lforum.entity.forum.Users;
  15. import cn.javaeye.lonlysky.lforum.interceptor.ActionInitAware;
  16. import cn.javaeye.lonlysky.lforum.service.OnlineUserManager;
  17. import cn.javaeye.lonlysky.lforum.service.UserManager;
  18. import cn.javaeye.lonlysky.lforum.service.admin.AdminVistLogManager;
  19. import cn.javaeye.lonlysky.lforum.service.admin.GroupManager;
  20. /**
  21. * ????????
  22. *
  23. * @author fishkang
  24. *
  25. */
  26. public class AdminBaseAction extends BaseAction implements ActionInitAware {
  27. private static final long serialVersionUID = 1118380429041990169L;
  28. protected String username;
  29. /**
  30. * ???????
  31. */
  32. protected Users user;
  33. /**
  34. * ????????
  35. */
  36. protected Usergroups usergroup;
  37. /**
  38. * ????????ID
  39. */
  40. protected int useradminid = 0;
  41. /**
  42. * ???????
  43. */
  44. protected String grouptitle;
  45. /**
  46. * ??IP??
  47. */
  48. protected String ip;
  49. protected StringBuilder htmlBuilder = new StringBuilder();
  50. private final int maxShortcutMenuCount = 15; //?????????
  51. protected String footer = "<div align=\"center\" style=\" padding-top:60px;font-size:11px; font-family: Arial;\">Powered by <a style=\"COLOR: #000000\" href=\"http://lonlysk.javaeye.com\" target=\"_blank\">LForum For Java</a> &nbsp;&copy; 2001-"
  52. + Utils.dateFormat(new Date(), "yyyy")
  53. + ", <a style=\"COLOR: #000000;font-weight:bold\" href=\"http://lonlysk.javaeye.com\" target=\"_blank\">Lonlysky Blog.</a></div>";
  54. @Autowired
  55. protected OnlineUserManager onlineUserManager;
  56. @Autowired
  57. protected GroupManager groupManager;
  58. @Autowired
  59. protected UserManager userManager;
  60. @Autowired
  61. protected AdminVistLogManager adminVistLogManager;
  62. /*
  63. * (non-Javadoc)
  64. * @see com.javaeye.lonlysky.lforum.interceptor.ActionInitAware#initAction()
  65. */
  66. public String initAction() throws Exception {
  67. registerAdminPageClientScriptBlock();
  68. // ??IP????????????
  69. if (!config.getAdminipaccess().trim().equals("")) {
  70. String[] regctrl = config.getAdminipaccess().trim().split("\n");
  71. if (!Utils.inIPArray(LForumRequest.getIp(), regctrl)) {
  72. response.sendRedirect(config.getWeburl() + "admin/syslogin.action");
  73. return null;
  74. }
  75. }
  76. // ??????
  77. Online oluserinfo = onlineUserManager.updateInfo(config.getPasswordkey(), config.getOnlinetimeout());
  78. usergroup = groupManager.adminGetUserGroupInfo(oluserinfo.getUsergroups().getGroupid());
  79. if (oluserinfo.getUsers().getUid() <= 0 || usergroup.getAdmingroups().getAdmingid() != 1) {
  80. response.sendRedirect(config.getWeburl() + "admin/syslogin.action");
  81. return null;
  82. }
  83. String secques = userManager.getUserInfo(oluserinfo.getUsers().getUid()).getSecques();
  84. // ???????
  85. // ???????
  86. if (ForumUtils.getCookie("lforumkey").equals("")
  87. || !ForumUtils.getCookiePassword(ForumUtils.getCookie("lforumkey"), config.getPasswordkey()).equals(
  88. (oluserinfo.getPassword() + secques + oluserinfo.getUsers().getUid()))) {
  89. response.sendRedirect(config.getWeburl() + "admin/syslogin.action");
  90. return null;
  91. } else {
  92. ForumUtils.writeCookie("lforumkey", ForumUtils.setCookiePassword(oluserinfo.getPassword() + secques
  93. + oluserinfo.getUsers().getUid(), config.getPasswordkey()), Utils.null2Int(DateUtils.addMinutes(
  94. new Date(), 30).getTime()));
  95. }
  96. user = userManager.getUserInfo(oluserinfo.getUsers().getUid());
  97. username = oluserinfo.getUsername();
  98. useradminid = usergroup.getAdmingroups().getAdmingid();
  99. grouptitle = usergroup.getGrouptitle();
  100. ip = LForumRequest.getIp();
  101. String headerStr = "<script type=\"text/javascript\" src=\"../js/ajaxhelper.js\"></script><script type='text/javascript'>\nfunction ResetShortcutMenu(){window.parent.LoadShortcutMenu();}\nfunction FavoriteFunction(url){\nAjaxHelper.Updater('../UserControls/favoritefunction','resultmessage','url='+url,ResetShortcutMenu);\n}\n</script>\n";
  102. headerStr += "<div align='right' style=''>";
  103. //??????????????
  104. FavoriteStatus status = getFavoriteStatus();
  105. //??????????????????????
  106. if (status != FavoriteStatus.Hidden) {
  107. if (status == FavoriteStatus.Exist) {
  108. headerStr += headerStr += "<span id='resultmessage' title='????????????????'><img src='../images/existmenu.gif' style='vertical-align:middle' /> ????</span>";
  109. } else if (status == FavoriteStatus.Full) {
  110. headerStr += headerStr += "<span id='resultmessage' title='????????????" + maxShortcutMenuCount
  111. + "?'><img src='../images/fullmenu.gif' style='vertical-align:middle' /> ????</span>\n</b>";
  112. } else if (status == FavoriteStatus.Show) {
  113. headerStr += "<span align='right' id='resultmessage'>\n<a href='javascript:;' title='????????????' onclick='FavoriteFunction(window.location.pathname.toLowerCase().replace(\"/admin/\",\"\") + window.location.search.toLowerCase());' style='text-decoration:none;color:#333;' onfocus=\"this.blur();\"><img src='../images/addmenu.gif' align='absmiddle' /> ????</a>\n</span>";
  114. }
  115. }
  116. headerStr += "<span><a href='#' onclick='window.parent.showNavigation()' title='?ESC????????????' style='text-decoration:none;color:#333;'><img src='../images/navigation.gif' style='vertical-align:middle'> ????</a></span></div>";
  117. headerStr += "<input type='hidden' name='submitMethod' value=''/>";
  118. headerStr += "<script type=\"text/javascript\">function doPost(method){";
  119. headerStr += "if(method!=''){document.getElementById('submitMethod').value='method:'+method;}";
  120. headerStr += "var theForm = document.forms['Form1'];";
  121. headerStr += "if (!theForm) {theForm = document.Form1;}";
  122. headerStr += "if (!theForm.onsubmit || (theForm.onsubmit() != false)) {theForm.submit();}}</script>";
  123. htmlBuilder.append(headerStr);
  124. return GlobalsKeys.ACTION_INIT;
  125. }
  126. /**
  127. * ????????
  128. * @return
  129. */
  130. @SuppressWarnings("unchecked")
  131. private FavoriteStatus getFavoriteStatus() {
  132. String configPath = config.getWebpath() + "admin/xml/navmenu.xml";
  133. String url = LForumRequest.getUrl().toLowerCase();
  134. String pagename = url.substring(url.lastIndexOf('/') + 1);
  135. Document doc = XmlElementUtil.readXML(configPath);
  136. List<Element> submains = doc.selectNodes("/dataset/submain");
  137. boolean findmenu = false;
  138. for (Element submain : submains) {
  139. if (submain.selectSingleNode("link").getText().indexOf('/') == -1)
  140. continue;
  141. if (submain.selectSingleNode("link").getText().split("/")[1].toLowerCase().equals(pagename))
  142. findmenu = true;
  143. }
  144. //??????????????????
  145. if (!findmenu)
  146. return FavoriteStatus.Hidden; //?????
  147. List<Element> shortcuts = doc.selectNodes("/dataset/shortcut");
  148. for (Element singleshortcut : shortcuts) {
  149. if (singleshortcut.selectSingleNode("link").getText().indexOf(pagename) != -1)
  150. return FavoriteStatus.Exist; //????????
  151. }
  152. if (shortcuts.size() >= maxShortcutMenuCount)
  153. return FavoriteStatus.Full; //??????????15?
  154. return FavoriteStatus.Show; //????
  155. }
  156. /**
  157. * ??????JS??
  158. */
  159. public void registerAdminPageClientScriptBlock() {
  160. String script = "<div id=\"success\" style=\"position:absolute;z-index:300;height:120px;width:284px;left:50%;top:50%;margin-left:-150px;margin-top:-80px;\">\r\n"
  161. + " <div id=\"Layer2\" style=\"position:absolute;z-index:300;width:270px;height:90px;background-color: #FFFFFF;border:solid #000000 1px;font-size:14px;\">\r\n"
  162. + " <div id=\"Layer4\" style=\"height:26px;background:#f1f1f1;line-height:26px;padding:0px 3px 0px 3px;font-weight:bolder;\">????</div>\r\n"
  163. + " <div id=\"Layer5\" style=\"height:64px;line-height:150%;padding:0px 3px 0px 3px;\" align=\"center\"><BR /><table><tr><td valign=top><img border=\"0\" src=\"../images/ajax_loading.gif\" /></td><td valign=middle style=\"font-size: 14px;\" >????????, ???...<BR /></td></tr></table><BR /></div>\r\n"
  164. + " </div>\r\n"
  165. + " <div id=\"Layer3\" style=\"position:absolute;width:270px;height:90px;z-index:299;left:4px;top:5px;background-color: #E8E8E8;\"></div>\r\n"
  166. + "</div>\r\n"
  167. + "<script> \r\n"
  168. + "document.getElementById('success').style.display = \"none\"; \r\n"
  169. + "</script> \r\n" + "<script type=\"text/javascript\" src=\"../js/divcover.js\"></script>\r\n";
  170. htmlBuilder.append(script);
  171. }
  172. public void registerStartupScript(String key, String scriptstr) {
  173. key = key.toLowerCase();
  174. if ((key.equals("pagetemplate")) || (key.equals("page"))) {
  175. String script = "";
  176. if (key.equals("page")) {
  177. script = "<script> \r\n" + "var bar=0;\r\n"
  178. + "document.getElementById('success').style.display = \"block\"; \r\n"
  179. + "document.getElementById('Layer5').innerHTML ='<BR>??????<BR>'; \r\n" + "count() ; \r\n"
  180. + "function count(){ \r\n" + "bar=bar+4; \r\n" + "if (bar<99) \r\n"
  181. + "{setTimeout(\"count()\",100);} \r\n" + "else { \r\n"
  182. + "document.getElementById('success').style.display = \"none\";HideOverSels('success'); \r\n"
  183. + scriptstr + "} \r\n" + "} \r\n" + "</script> \r\n"
  184. + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
  185. }
  186. if (key.equals("pagetemplate")) {
  187. script = "<script> \r\n" + "var bar=0;\r\n success.style.display = \"block\"; \r\n"
  188. + "document.getElementById('Layer5').innerHTML = '<BR>" + scriptstr + "<BR>'; \r\n"
  189. + "count() ; \r\n" + "function count(){ \r\n" + "bar=bar+4; \r\n" + "if (bar<99) \r\n"
  190. + "{setTimeout(\"count()\",100);} \r\n" + "else { \r\n"
  191. + "document.getElementById('success').style.display = \"none\";HideOverSels('success'); \r\n"
  192. + "}} \r\n" + "</script> \r\n"
  193. + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
  194. }
  195. htmlBuilder.append(script);
  196. } else {
  197. htmlBuilder.append(scriptstr);
  198. }
  199. }
  200. /**
  201. * ??????
  202. * @return
  203. */
  204. protected String getShowMessage() {
  205. String message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
  206. message += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>???????????!</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
  207. message += "<link href=\"../styles/default.css\" type=\"text/css\" rel=\"stylesheet\"></head><body><br><br><div style=\"width:100%\" align=\"center\">";
  208. message += "<div align=\"center\" style=\"width:660px; border:1px dotted #FF6600; background-color:#FFFCEC; margin:auto; padding:20px;\"><img src=\"../images/hint.gif\" border=\"0\" alt=\"??:\" align=\"absmiddle\" width=\"11\" height=\"13\" /> &nbsp;";
  209. message += "???????????,??????????????????!</div></div></body></html>";
  210. return message;
  211. }
  212. public void loadRegisterStartupScript(String scriptstr) {
  213. String message = "?????... <BR /> ?????????????.<BR />????????????<BR /><BR />";
  214. String script = "<script> \r\n" + "var bar=0;\r\n success.style.display = \"block\"; \r\n"
  215. + "document.getElementById('Layer5').innerHTML ='" + message + "'; \r\n" + "count() ; \r\n"
  216. + "function count(){ \r\n" + "bar=bar+2; \r\n" + "if (bar<99) \r\n"
  217. + "{setTimeout(\"count()\",100);} \r\n" + "else { \r\n"
  218. + " document.getElementById('success').style.display = \"none\";HideOverSels('success'); \r\n"
  219. + scriptstr + "} \r\n" + "} \r\n" + "</script> \r\n"
  220. + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
  221. htmlBuilder.append(script);
  222. }
  223. private void registerMessage(String scriptstr, boolean autoHidd, String autoJumpUrl) {
  224. String script = "<script type='text/javascript'>\r\n" + "var bar=0;\r\n"
  225. + "document.getElementById('success').style.display = \"block\";\r\n"
  226. + "document.getElementById('Layer5').innerHTML = '<BR>" + scriptstr + "<BR>';\r\n";
  227. if (autoHidd) {
  228. script += "count();\r\n" + "function count()\r\n" + "{\r\n" + "\tbar=bar+4;\r\n" + "\tif (bar<99)\r\n"
  229. + "\t{\r\n" + "\t\tsetTimeout(\"count()\",200);\r\n" + "\t}\r\n" + "\telse\r\n" + "\t{\r\n";
  230. if (autoJumpUrl == "") {
  231. script += "\t\tdocument.getElementById('success').style.display = \"none\";HideOverSels('success');\r\n";
  232. } else {
  233. script += "\t\twindow.location='" + autoJumpUrl + "';\r\n";
  234. }
  235. script += "\t}\r\n" + "}\r\n";
  236. }
  237. script += "</script>\r\n" + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
  238. htmlBuilder.append(script);
  239. }
  240. protected void registerMessage(String scriptstr, String autoJumpUrl) {
  241. registerMessage(scriptstr, true, autoJumpUrl);
  242. }
  243. protected void registerMessage(String scriptstr, boolean autoHidd) {
  244. registerMessage(scriptstr, autoHidd, "");
  245. }
  246. protected void registerMessage(String scriptstr) {
  247. registerMessage(scriptstr, false);
  248. }
  249. public String getUsername() {
  250. return username;
  251. }
  252. public Users getUser() {
  253. return user;
  254. }
  255. public Usergroups getUsergroup() {
  256. return usergroup;
  257. }
  258. public int getUseradminid() {
  259. return useradminid;
  260. }
  261. public String getGrouptitle() {
  262. return grouptitle;
  263. }
  264. public String getIp() {
  265. return ip;
  266. }
  267. public int getMaxShortcutMenuCount() {
  268. return maxShortcutMenuCount;
  269. }
  270. public String getFooter() {
  271. return footer;
  272. }
  273. public StringBuilder getHtmlBuilder() {
  274. return htmlBuilder;
  275. }
  276. /**
  277. * ???????Show?????Hidden??????Full??????Exist???????
  278. *
  279. */
  280. private enum FavoriteStatus {
  281. Show, Hidden, Full, Exist
  282. }
  283. }