postopt.java

来自「一个jsp写的bbs」· Java 代码 · 共 797 行 · 第 1/3 页

JAVA
797
字号
          }

          this.getTempConfiguration().setDirectoryForTemplateLoading(new File(Constant.ROOTPATH +
              Constant.FTL_PATH));
          this.getTempConfiguration().setDefaultEncoding(Constant.CHARSET);
          this.getTempConfiguration().setLocale(request.getLocale());
          this.getTempConfiguration().setNumberFormat("0.##########");

          Map root = new HashMap();
          root.put("website", this.getSysConfig().getForumName());
          root.put("title", f.getTitle());
          root.put("detail", detail);

          Template temp = this.getTempConfiguration().getTemplate("mailSend.ftl");
          StringWriter sw = new StringWriter();
          temp.process(root, sw);
          this.getHtmlEmail().setHtmlMsg(sw.toString());
          this.getHtmlEmail().setTextMsg("Your email client does not support HTML messages");
          this.getHtmlEmail().addTo(us.getEmail());
          this.getHtmlEmail().setCharset(Constant.CHARSET);
          this.getHtmlEmail().send();
          sw.flush();
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                               mr.getMessage(locale, "post.mailsend.ok"));
        }
        catch (Exception ex7) {
          ex7.printStackTrace();
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_MAILSEND_ERROR,
                                               mr.getMessage(locale, "post.mailsend.error"));
        }
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      else {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_MAILSEND_ERROR,
                                             mr.getMessage(locale, "post.mailsend.error"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
    }

    if (optForm.getAction().equalsIgnoreCase("mailsendtopic")) {
      List l = this.getForumService().findForumsTopic(optForm.getBid(), optForm.getMainid(), 0, 0, "postTime",
          Constant.ORDER_ASC);
      if (l == null || l.isEmpty()) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_NOT_EXIST,
                                             mr.getMessage(locale, "error.post.getpost"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      if (StringUtils.isNotBlank(us.getEmail()) && this.getSysConfig().getUseEmail() == 1) {
        try {
          Forum mainForum = (Forum) l.get(0);
          if (this.getSysConfig().getSmtpAuth() == 1) {
            DefaultAuthenticator defaultAuthenticator = new DefaultAuthenticator(this.getSysConfig().
                getSmtpUser(), this.getSysConfig().getSmtpPasswd());
            this.getHtmlEmail().setAuthenticator(defaultAuthenticator);
          }
          this.getHtmlEmail().setHostName(this.getSysConfig().getSmtpServer());
          this.getHtmlEmail().setSmtpPort(this.getSysConfig().getSmtpPort());
          this.getHtmlEmail().setFrom(this.getSysConfig().getSenderEmail());
          this.getHtmlEmail().setSubject(mainForum.getTitle());
          List nl = new ArrayList();
          for (int i = 0; i < l.size(); i++) {
            Forum f = (Forum) l.get(i);
            if (f.getEditType() == 0) {
              f.setDetail(BBSCSUtil.filterText(f.getDetail(), (board.getAllowHTML() == 1),
                                               (board.getAllowUBB() == 1), true));
            }
            nl.add(f);
          }
          this.getTempConfiguration().setDirectoryForTemplateLoading(new File(Constant.ROOTPATH +
              Constant.FTL_PATH));
          this.getTempConfiguration().setDefaultEncoding(Constant.CHARSET);
          this.getTempConfiguration().setLocale(request.getLocale());
          this.getTempConfiguration().setNumberFormat("0.##########");

          Map root = new HashMap();
          root.put("website", this.getSysConfig().getForumName());
          root.put("nl", nl);

          Template temp = this.getTempConfiguration().getTemplate("mailSendTopic.ftl");
          StringWriter sw = new StringWriter();
          temp.process(root, sw);
          this.getHtmlEmail().setHtmlMsg(sw.toString());
          this.getHtmlEmail().setTextMsg("Your email client does not support HTML messages");
          this.getHtmlEmail().addTo(us.getEmail());
          this.getHtmlEmail().setCharset(Constant.CHARSET);
          this.getHtmlEmail().send();
          sw.flush();
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                               mr.getMessage(locale, "post.mailsend.ok"));
          this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
          return mapping.findForward(this.FORWARD_AJAX);
        }
        catch (Exception ex8) {
          ex8.printStackTrace();
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_MAILSEND_ERROR,
                                               mr.getMessage(locale, "post.mailsend.error"));
          this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
          return mapping.findForward(this.FORWARD_AJAX);
        }
      }
      else {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_MAILSEND_ERROR,
                                             mr.getMessage(locale, "post.mailsend.error"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
    }

    if (optForm.getAction().equalsIgnoreCase("report")) {
      Forum f = this.getForumService().findForumByID(optForm.getId(), bid);
      if (f == null) {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_NOT_EXIST,
                                             mr.getMessage(locale, "error.post.getpost"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      if (this.getSysConfig().getUseEmail() == 1) {
        try {
          if (this.getSysConfig().getSmtpAuth() == 1) {
            DefaultAuthenticator defaultAuthenticator = new DefaultAuthenticator(this.getSysConfig().
                getSmtpUser(), this.getSysConfig().getSmtpPasswd());
            this.getHtmlEmail().setAuthenticator(defaultAuthenticator);
          }
          this.getHtmlEmail().setHostName(this.getSysConfig().getSmtpServer());
          this.getHtmlEmail().setSmtpPort(this.getSysConfig().getSmtpPort());
          this.getHtmlEmail().setFrom(this.getSysConfig().getSenderEmail());
          String title = mr.getMessage(request.getLocale(), "post.report.msg", us.getUserName(),
                                       board.getBoardName(), f.getTitle());
          this.getHtmlEmail().setSubject(title);
          String detail = "";
          if (f.getEditType() == 0) {
            detail = BBSCSUtil.filterText(f.getDetail(), (board.getAllowHTML() == 1),
                                          (board.getAllowUBB() == 1), true);
          }
          else {
            detail = f.getDetail();
          }

          this.getTempConfiguration().setDirectoryForTemplateLoading(new File(Constant.ROOTPATH +
              Constant.FTL_PATH));
          this.getTempConfiguration().setDefaultEncoding(Constant.CHARSET);
          this.getTempConfiguration().setLocale(request.getLocale());
          this.getTempConfiguration().setNumberFormat("0.##########");

          Map root = new HashMap();
          root.put("userName", us.getUserName());
          root.put("title", f.getTitle());
          root.put("detail", detail);

          Template temp = this.getTempConfiguration().getTemplate("report.ftl");
          StringWriter sw = new StringWriter();
          temp.process(root, sw);
          this.getHtmlEmail().setHtmlMsg(sw.toString());

          this.getHtmlEmail().setTextMsg("Your email client does not support HTML messages");
          this.getHtmlEmail().addTo(this.getSysConfig().getWebmasterEmail());
          this.getHtmlEmail().setCharset(Constant.CHARSET);
          this.getHtmlEmail().send();
          sw.flush();
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_OK,
                                               mr.getMessage(locale, "post.report.ok"));
        }
        catch (Exception ex7) {
          ex7.printStackTrace();
          this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_REPORT_ERROR,
                                               mr.getMessage(locale, "error.post.report.error"));
        }
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
      else {
        this.getAjaxMessagesXML().setMessage(Constant.CODEID_POST_REPORT_ERROR,
                                             mr.getMessage(locale, "error.post.report.error"));
        this.setAjaxMessagesXMLRepuest(request, this.getAjaxMessagesXML());
        return mapping.findForward(this.FORWARD_AJAX);
      }
    }

    return mapping.getInputForward();
  }

  public BoardService getBoardService() {
    return boardService;
  }

  public ForumService getForumService() {
    return forumService;
  }

  public SysConfig getSysConfig() {
    return sysConfig;
  }

  public UserService getUserService() {
    return userService;
  }

  public AjaxMessagesXML getAjaxMessagesXML() {
    return ajaxMessagesXML;
  }

  public AgreeAgainstService getAgreeAgainstService() {
    return agreeAgainstService;
  }

  public SubscibeFactory getSubscibeFactory() {
    return subscibeFactory;
  }

  public SubscibeService getSubscibeService() {
    return subscibeService;
  }

  public HtmlEmail getHtmlEmail() {
    return htmlEmail;
  }

  public Configuration getTempConfiguration() {
    return tempConfiguration;
  }

  public void setBoardService(BoardService boardService) {
    this.boardService = boardService;
  }

  public void setForumService(ForumService forumService) {
    this.forumService = forumService;
  }

  public void setSysConfig(SysConfig sysConfig) {
    this.sysConfig = sysConfig;
  }

  public void setUserService(UserService userService) {
    this.userService = userService;
  }

  public void setAjaxMessagesXML(AjaxMessagesXML ajaxMessagesXML) {
    this.ajaxMessagesXML = ajaxMessagesXML;
  }

  public void setAgreeAgainstService(AgreeAgainstService agreeAgainstService) {
    this.agreeAgainstService = agreeAgainstService;
  }

  public void setSubscibeFactory(SubscibeFactory subscibeFactory) {
    this.subscibeFactory = subscibeFactory;
  }

  public void setSubscibeService(SubscibeService subscibeService) {
    this.subscibeService = subscibeService;
  }

  public void setHtmlEmail(HtmlEmail htmlEmail) {
    this.htmlEmail = htmlEmail;
  }

  public void setTempConfiguration(Configuration tempConfiguration) {
    this.tempConfiguration = tempConfiguration;
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?