📄 messageform.java
字号:
package com.redmoon.oa.message;import cn.js.fan.base.AbstractForm;import cn.js.fan.util.ErrMsgException;import javax.servlet.http.HttpServletRequest;import cn.js.fan.util.ParamUtil;import cn.js.fan.db.SQLFilter;import com.redmoon.oa.person.UserDb;import com.redmoon.kit.util.FileUpload;import java.io.IOException;import cn.js.fan.web.Global;import javax.servlet.ServletContext;import com.redmoon.oa.Config;import java.util.StringTokenizer;import cn.js.fan.util.StrUtil;public class MessageForm extends AbstractForm { MessageDb md; HttpServletRequest request; ServletContext application; public FileUpload fileUpload; public MessageForm() { } public MessageForm(ServletContext application, HttpServletRequest request, MessageDb md) { this.application = application; this.request = request; this.md = md; } public FileUpload doUpload() throws ErrMsgException { fileUpload = new FileUpload(); Config cfg = new Config(); fileUpload.setMaxAllFileSize(cfg.getInt("shortMsgFileSize")); String exts = cfg.get("shortMsgFileExt"); String[] extAry = StrUtil.split(exts, ","); if (extAry!=null) fileUpload.setValidExtname(extAry); int ret = 0; try { ret = fileUpload.doUpload(application, request); if (ret != fileUpload.RET_SUCCESS) { throw new ErrMsgException("ret=" + ret + " " + fileUpload.getErrMessage()); } } catch (IOException e) { logger.error("doUpload:" + e.getMessage()); } return fileUpload; } public String chkIp() { md.ip = request.getRemoteAddr(); return md.ip; } public String chkTitle() throws ErrMsgException { String title = fileUpload.getFieldValue("title"); if (title.equals("")) { log("标题必须填写!"); } Config cfg = new Config(); int minLen = cfg.getInt("shortMsgTitleLengthMin"); int maxLen = cfg.getInt("shortMsgTitleLengthMax"); if (title.trim().length() > maxLen || title.trim().length() < minLen) { throw new ErrMsgException("短消息标题字数大于" + minLen + "小于" + maxLen); } if (!SQLFilter.isValidSqlParam(title)) { log("请勿使用' ; 等字符!"); } md.title = title; return title; } public String chkContent() throws ErrMsgException{ String content = fileUpload.getFieldValue("content"); if (!SQLFilter.isValidSqlParam(content)) { log("请勿使用' ; 等字符!"); } Config cfg = new Config(); int minLen = cfg.getInt("shortMsgTitleLengthMin"); int maxLen = cfg.getInt("shortMsgTitleLengthMax"); if (content.trim().length() > maxLen || content.trim().length() < minLen) { throw new ErrMsgException("短消息内容字数大于" + minLen + "小于" + maxLen); } md.content = content; return content; } public String chkReceiver() { String receiver = fileUpload.getFieldValue("receiver"); if (receiver.equals("")) { log("接收者必须填写!"); } if (!SQLFilter.isValidSqlParam(receiver)) { log("请勿使用' ; 等字符!"); } md.receiver = receiver; return receiver; } public String checkIp() { String ip = request.getRemoteAddr(); md.ip = ip; return ip; } public int chkType() { String type = fileUpload.getFieldValue("type"); if (type == null || type.equals("")) { type = "0"; } md.type = Integer.parseInt(type); return md.type; } public boolean chkIsDraft() { String strDraft = fileUpload.getFieldValue("isDraft"); if (strDraft == null) { md.setDraft(false); return false; } if (strDraft.equals("true")) { md.setDraft(true); return true; } else { md.setDraft(false); return false; } } public boolean checkCreate() throws ErrMsgException { init(); doUpload(); chkTitle(); chkContent(); chkReceiver(); chkIp(); chkIsDraft(); report(); return true; } public boolean checkTransmit() throws ErrMsgException { init(); md.setTitle(ParamUtil.get(request, "title")); md.setContent(ParamUtil.get(request, "content")); chkIp(); md.receiver = ParamUtil.get(request, "receiver"); md.setDraft(false); report(); return true; } public FileUpload getFileUpload() { return this.fileUpload; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -