📄 sweetuserinfomgr.java
字号:
package com.redmoon.forum.plugin.sweet;import java.io.File;import java.util.Calendar;import java.util.Vector;import javax.servlet.ServletContext;import javax.servlet.http.HttpServletRequest;import cn.js.fan.util.ErrMsgException;import cn.js.fan.util.StrUtil;import com.redmoon.forum.BoardManagerDb;import com.redmoon.forum.Privilege;import com.redmoon.kit.util.FileInfo;import com.redmoon.kit.util.FileUpload;import org.apache.log4j.Logger;import cn.js.fan.web.SkinUtil;import cn.js.fan.web.Global;public class SweetUserInfoMgr { Logger logger = Logger.getLogger(SweetUserInfoMgr.class.getName()); public SweetUserInfoMgr() { } public boolean add(HttpServletRequest request) throws ErrMsgException { SweetUserInfoForm suif = new SweetUserInfoForm(); suif.checkAdd(request); return suif.sweetUserInfoDb.create(); } public boolean del(HttpServletRequest request) throws ErrMsgException { SweetUserInfoForm suif = new SweetUserInfoForm(); suif.checkDel(request); SweetUserInfoDb suid = this.getSweetUserInfoDb(suif.sweetUserInfoDb.getName()); boolean re = suid.del(); return re; } public boolean edit(HttpServletRequest request) throws ErrMsgException { SweetUserInfoForm suif = new SweetUserInfoForm(); suif.checkEdit(request); return suif.sweetUserInfoDb.save(); } public SweetUserInfoDb getSweetUserInfoDb(String name) { return new SweetUserInfoDb(name); } public synchronized boolean editPhoto(ServletContext application, HttpServletRequest request) throws ErrMsgException { String photo = ""; FileUpload fileupload = new FileUpload(); boolean re = false; int ret = 0; try { ret = fileupload.doUpload(application, request); } catch (Exception e) { logger.error("modifyLogo: " + e.getMessage()); throw new ErrMsgException(e.getMessage()); } userName = StrUtil.getNullString(fileupload.getFieldValue("userName")); if (userName.equals("")) { throw new ErrMsgException(SkinUtil.LoadString(request,"res.forum.plugin.sweet","ERR_USER_NAME")); } boardCode = StrUtil.getNullString(fileupload.getFieldValue("boardcode")); if (boardCode.equals("")) { throw new ErrMsgException(SkinUtil.LoadString(request,"res.forum.plugin.sweet","ERR_BOARD_NAME")); } SweetUserInfoDb suid = getSweetUserInfoDb(userName); Privilege privilege = new Privilege(); String user = privilege.getUser(request); BoardManagerDb bm = new BoardManagerDb(); bm = bm.getBoardManagerDb(boardCode, user); if (!bm.isLoaded()) { if (user.equals(userName)) { if (suid.isChecked()) throw new ErrMsgException(SkinUtil.LoadString(request,"res.forum.plugin.sweet","ERR_MSG_CHECKED")); } else throw new ErrMsgException(SkinUtil.LoadString(request,"res.forum.plugin.sweet","ERR_PRIVILIGE")); } if (fileupload.getRet()==fileupload.RET_SUCCESS) { try { String sPhoto = StrUtil.getNullString(suid.getPhoto()); if (!sPhoto.equals("")) { File file = new File(Global.getRealPath() + sPhoto); file.delete(); } } catch (Exception e) { logger.info(e.getMessage()); } Vector v = fileupload.getFiles(); FileInfo fi = null; if (v.size()>0) fi = (FileInfo)v.get(0); String vpath = ""; if (fi!=null) { Calendar cal = Calendar.getInstance(); String year = "" + (cal.get(cal.YEAR)); String month = "" + (cal.get(cal.MONTH) + 1); vpath = "forum/upfile/" + fi.getExt() + "/" + year + "/" + month + "/"; String filepath = Global.realPath + vpath; fileupload.setSavePath(filepath); fileupload.setMaxAllFileSize(600); fileupload.setMaxFileSize(200); String[] ext = {"gif", "jpg", "png", "jpeg"}; fileupload.setValidExtname(ext); fileupload.writeFile(true); photo = fi.getDiskName(); photo = vpath + photo; suid.setPhoto(photo); re = suid.save(); } else { photo = ""; suid.setPhoto(photo); re = suid.save(); } } else { throw new ErrMsgException(fileupload.getErrMessage(request)); } return re; } public void setUserName(String userName) { this.userName = userName; } public void setBoardCode(String boardCode) { this.boardCode = boardCode; } public String getUserName() { return userName; } public String getBoardCode() { return boardCode; } private String userName; private String boardCode;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -