/src/main/java/cn/javaeye/lonlysky/lforum/AdminBaseAction.java
Java | 333 lines | 236 code | 50 blank | 47 comment | 36 complexity | 532d9914812066d6afd8d11804017f82 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
- package cn.javaeye.lonlysky.lforum;
-
- import java.util.Date;
- import java.util.List;
-
- import org.apache.commons.lang.time.DateUtils;
- import org.dom4j.Document;
- import org.dom4j.Element;
- import org.springframework.beans.factory.annotation.Autowired;
-
- import cn.javaeye.lonlysky.lforum.comm.LForumRequest;
- import cn.javaeye.lonlysky.lforum.comm.utils.ForumUtils;
- import cn.javaeye.lonlysky.lforum.comm.utils.Utils;
- import cn.javaeye.lonlysky.lforum.comm.utils.XmlElementUtil;
- import cn.javaeye.lonlysky.lforum.entity.forum.Online;
- import cn.javaeye.lonlysky.lforum.entity.forum.Usergroups;
- import cn.javaeye.lonlysky.lforum.entity.forum.Users;
- import cn.javaeye.lonlysky.lforum.interceptor.ActionInitAware;
- import cn.javaeye.lonlysky.lforum.service.OnlineUserManager;
- import cn.javaeye.lonlysky.lforum.service.UserManager;
- import cn.javaeye.lonlysky.lforum.service.admin.AdminVistLogManager;
- import cn.javaeye.lonlysky.lforum.service.admin.GroupManager;
-
- /**
- * ????????
- *
- * @author fishkang
- *
- */
- public class AdminBaseAction extends BaseAction implements ActionInitAware {
-
- private static final long serialVersionUID = 1118380429041990169L;
-
- protected String username;
-
- /**
- * ???????
- */
- protected Users user;
-
- /**
- * ????????
- */
- protected Usergroups usergroup;
-
- /**
- * ????????ID
- */
- protected int useradminid = 0;
-
- /**
- * ???????
- */
- protected String grouptitle;
-
- /**
- * ??IP??
- */
- protected String ip;
-
- protected StringBuilder htmlBuilder = new StringBuilder();
-
- private final int maxShortcutMenuCount = 15; //?????????
-
- 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> © 2001-"
- + Utils.dateFormat(new Date(), "yyyy")
- + ", <a style=\"COLOR: #000000;font-weight:bold\" href=\"http://lonlysk.javaeye.com\" target=\"_blank\">Lonlysky Blog.</a></div>";
-
- @Autowired
- protected OnlineUserManager onlineUserManager;
-
- @Autowired
- protected GroupManager groupManager;
-
- @Autowired
- protected UserManager userManager;
-
- @Autowired
- protected AdminVistLogManager adminVistLogManager;
-
- /*
- * (non-Javadoc)
- * @see com.javaeye.lonlysky.lforum.interceptor.ActionInitAware#initAction()
- */
- public String initAction() throws Exception {
-
- registerAdminPageClientScriptBlock();
-
- // ??IP????????????
- if (!config.getAdminipaccess().trim().equals("")) {
- String[] regctrl = config.getAdminipaccess().trim().split("\n");
- if (!Utils.inIPArray(LForumRequest.getIp(), regctrl)) {
- response.sendRedirect(config.getWeburl() + "admin/syslogin.action");
- return null;
- }
- }
-
- // ??????
- Online oluserinfo = onlineUserManager.updateInfo(config.getPasswordkey(), config.getOnlinetimeout());
- usergroup = groupManager.adminGetUserGroupInfo(oluserinfo.getUsergroups().getGroupid());
- if (oluserinfo.getUsers().getUid() <= 0 || usergroup.getAdmingroups().getAdmingid() != 1) {
- response.sendRedirect(config.getWeburl() + "admin/syslogin.action");
- return null;
- }
-
- String secques = userManager.getUserInfo(oluserinfo.getUsers().getUid()).getSecques();
-
- // ???????
- // ???????
- if (ForumUtils.getCookie("lforumkey").equals("")
- || !ForumUtils.getCookiePassword(ForumUtils.getCookie("lforumkey"), config.getPasswordkey()).equals(
- (oluserinfo.getPassword() + secques + oluserinfo.getUsers().getUid()))) {
- response.sendRedirect(config.getWeburl() + "admin/syslogin.action");
- return null;
- } else {
- ForumUtils.writeCookie("lforumkey", ForumUtils.setCookiePassword(oluserinfo.getPassword() + secques
- + oluserinfo.getUsers().getUid(), config.getPasswordkey()), Utils.null2Int(DateUtils.addMinutes(
- new Date(), 30).getTime()));
- }
-
- user = userManager.getUserInfo(oluserinfo.getUsers().getUid());
- username = oluserinfo.getUsername();
- useradminid = usergroup.getAdmingroups().getAdmingid();
- grouptitle = usergroup.getGrouptitle();
- ip = LForumRequest.getIp();
-
- 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";
- headerStr += "<div align='right' style=''>";
- //??????????????
- FavoriteStatus status = getFavoriteStatus();
- //??????????????????????
- if (status != FavoriteStatus.Hidden) {
- if (status == FavoriteStatus.Exist) {
- headerStr += headerStr += "<span id='resultmessage' title='????????????????'><img src='../images/existmenu.gif' style='vertical-align:middle' /> ????</span>";
- } else if (status == FavoriteStatus.Full) {
- headerStr += headerStr += "<span id='resultmessage' title='????????????" + maxShortcutMenuCount
- + "?'><img src='../images/fullmenu.gif' style='vertical-align:middle' /> ????</span>\n</b>";
- } else if (status == FavoriteStatus.Show) {
- 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>";
- }
- }
- 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>";
- headerStr += "<input type='hidden' name='submitMethod' value=''/>";
- headerStr += "<script type=\"text/javascript\">function doPost(method){";
- headerStr += "if(method!=''){document.getElementById('submitMethod').value='method:'+method;}";
- headerStr += "var theForm = document.forms['Form1'];";
- headerStr += "if (!theForm) {theForm = document.Form1;}";
- headerStr += "if (!theForm.onsubmit || (theForm.onsubmit() != false)) {theForm.submit();}}</script>";
- htmlBuilder.append(headerStr);
- return GlobalsKeys.ACTION_INIT;
- }
-
- /**
- * ????????
- * @return
- */
- @SuppressWarnings("unchecked")
- private FavoriteStatus getFavoriteStatus() {
- String configPath = config.getWebpath() + "admin/xml/navmenu.xml";
- String url = LForumRequest.getUrl().toLowerCase();
- String pagename = url.substring(url.lastIndexOf('/') + 1);
- Document doc = XmlElementUtil.readXML(configPath);
- List<Element> submains = doc.selectNodes("/dataset/submain");
- boolean findmenu = false;
- for (Element submain : submains) {
- if (submain.selectSingleNode("link").getText().indexOf('/') == -1)
- continue;
- if (submain.selectSingleNode("link").getText().split("/")[1].toLowerCase().equals(pagename))
- findmenu = true;
- }
- //??????????????????
- if (!findmenu)
- return FavoriteStatus.Hidden; //?????
- List<Element> shortcuts = doc.selectNodes("/dataset/shortcut");
- for (Element singleshortcut : shortcuts) {
- if (singleshortcut.selectSingleNode("link").getText().indexOf(pagename) != -1)
- return FavoriteStatus.Exist; //????????
- }
- if (shortcuts.size() >= maxShortcutMenuCount)
- return FavoriteStatus.Full; //??????????15?
- return FavoriteStatus.Show; //????
- }
-
- /**
- * ??????JS??
- */
- public void registerAdminPageClientScriptBlock() {
- 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"
- + " <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"
- + " <div id=\"Layer4\" style=\"height:26px;background:#f1f1f1;line-height:26px;padding:0px 3px 0px 3px;font-weight:bolder;\">????</div>\r\n"
- + " <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"
- + " </div>\r\n"
- + " <div id=\"Layer3\" style=\"position:absolute;width:270px;height:90px;z-index:299;left:4px;top:5px;background-color: #E8E8E8;\"></div>\r\n"
- + "</div>\r\n"
- + "<script> \r\n"
- + "document.getElementById('success').style.display = \"none\"; \r\n"
- + "</script> \r\n" + "<script type=\"text/javascript\" src=\"../js/divcover.js\"></script>\r\n";
- htmlBuilder.append(script);
- }
-
- public void registerStartupScript(String key, String scriptstr) {
- key = key.toLowerCase();
- if ((key.equals("pagetemplate")) || (key.equals("page"))) {
- String script = "";
-
- if (key.equals("page")) {
- script = "<script> \r\n" + "var bar=0;\r\n"
- + "document.getElementById('success').style.display = \"block\"; \r\n"
- + "document.getElementById('Layer5').innerHTML ='<BR>??????<BR>'; \r\n" + "count() ; \r\n"
- + "function count(){ \r\n" + "bar=bar+4; \r\n" + "if (bar<99) \r\n"
- + "{setTimeout(\"count()\",100);} \r\n" + "else { \r\n"
- + "document.getElementById('success').style.display = \"none\";HideOverSels('success'); \r\n"
- + scriptstr + "} \r\n" + "} \r\n" + "</script> \r\n"
- + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
- }
-
- if (key.equals("pagetemplate")) {
- script = "<script> \r\n" + "var bar=0;\r\n success.style.display = \"block\"; \r\n"
- + "document.getElementById('Layer5').innerHTML = '<BR>" + scriptstr + "<BR>'; \r\n"
- + "count() ; \r\n" + "function count(){ \r\n" + "bar=bar+4; \r\n" + "if (bar<99) \r\n"
- + "{setTimeout(\"count()\",100);} \r\n" + "else { \r\n"
- + "document.getElementById('success').style.display = \"none\";HideOverSels('success'); \r\n"
- + "}} \r\n" + "</script> \r\n"
- + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
- }
- htmlBuilder.append(script);
-
- } else {
- htmlBuilder.append(scriptstr);
- }
- }
-
- /**
- * ??????
- * @return
- */
- protected String getShowMessage() {
- String message = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">";
- message += "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>???????????!</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
- message += "<link href=\"../styles/default.css\" type=\"text/css\" rel=\"stylesheet\"></head><body><br><br><div style=\"width:100%\" align=\"center\">";
- 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\" /> ";
- message += "???????????,??????????????????!</div></div></body></html>";
- return message;
- }
-
- public void loadRegisterStartupScript(String scriptstr) {
- String message = "?????... <BR /> ?????????????.<BR />????????????<BR /><BR />";
-
- String script = "<script> \r\n" + "var bar=0;\r\n success.style.display = \"block\"; \r\n"
- + "document.getElementById('Layer5').innerHTML ='" + message + "'; \r\n" + "count() ; \r\n"
- + "function count(){ \r\n" + "bar=bar+2; \r\n" + "if (bar<99) \r\n"
- + "{setTimeout(\"count()\",100);} \r\n" + "else { \r\n"
- + " document.getElementById('success').style.display = \"none\";HideOverSels('success'); \r\n"
- + scriptstr + "} \r\n" + "} \r\n" + "</script> \r\n"
- + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
-
- htmlBuilder.append(script);
- }
-
- private void registerMessage(String scriptstr, boolean autoHidd, String autoJumpUrl) {
- String script = "<script type='text/javascript'>\r\n" + "var bar=0;\r\n"
- + "document.getElementById('success').style.display = \"block\";\r\n"
- + "document.getElementById('Layer5').innerHTML = '<BR>" + scriptstr + "<BR>';\r\n";
- if (autoHidd) {
- script += "count();\r\n" + "function count()\r\n" + "{\r\n" + "\tbar=bar+4;\r\n" + "\tif (bar<99)\r\n"
- + "\t{\r\n" + "\t\tsetTimeout(\"count()\",200);\r\n" + "\t}\r\n" + "\telse\r\n" + "\t{\r\n";
- if (autoJumpUrl == "") {
- script += "\t\tdocument.getElementById('success').style.display = \"none\";HideOverSels('success');\r\n";
- } else {
- script += "\t\twindow.location='" + autoJumpUrl + "';\r\n";
- }
- script += "\t}\r\n" + "}\r\n";
- }
- script += "</script>\r\n" + "<script> window.onload = function(){HideOverSels('success')};</script>\r\n";
- htmlBuilder.append(script);
- }
-
- protected void registerMessage(String scriptstr, String autoJumpUrl) {
- registerMessage(scriptstr, true, autoJumpUrl);
- }
-
- protected void registerMessage(String scriptstr, boolean autoHidd) {
- registerMessage(scriptstr, autoHidd, "");
- }
-
- protected void registerMessage(String scriptstr) {
- registerMessage(scriptstr, false);
- }
-
- public String getUsername() {
- return username;
- }
-
- public Users getUser() {
- return user;
- }
-
- public Usergroups getUsergroup() {
- return usergroup;
- }
-
- public int getUseradminid() {
- return useradminid;
- }
-
- public String getGrouptitle() {
- return grouptitle;
- }
-
- public String getIp() {
- return ip;
- }
-
- public int getMaxShortcutMenuCount() {
- return maxShortcutMenuCount;
- }
-
- public String getFooter() {
- return footer;
- }
-
- public StringBuilder getHtmlBuilder() {
- return htmlBuilder;
- }
-
- /**
- * ???????Show?????Hidden??????Full??????Exist???????
- *
- */
- private enum FavoriteStatus {
- Show, Hidden, Full, Exist
- }
- }