📄 auctionshopmgr.java
字号:
package com.redmoon.forum.plugin.auction;
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.Privilege;
import com.redmoon.kit.util.FileInfo;
import com.redmoon.kit.util.FileUpload;
import org.apache.log4j.Logger;
import cn.js.fan.web.SkinUtil;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class AuctionShopMgr {
Logger logger = Logger.getLogger(AuctionShopMgr.class.getName());
public AuctionShopMgr() {
}
public synchronized boolean modifyLogo(ServletContext application, HttpServletRequest request) throws
ErrMsgException {
String logo = "";
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.getNullStr(fileupload.getFieldValue("userName"));
if (userName.equals("")) {
throw new ErrMsgException(SkinUtil.LoadString(request,"res.forum.plugin.auction","err_userName"));//用户名不能为空!
}
Privilege privilege = new Privilege();
String user = privilege.getUser(request);
if (!userName.equals(user)) {
if (!privilege.isMasterLogin(request)) {
throw new ErrMsgException(SkinUtil.PVG_INVALID);//对不起,您无权访问!
}
}
AuctionShopDb as = new AuctionShopDb();
as = as.getAuctionShopDb(userName);
if (fileupload.getRet()==fileupload.RET_SUCCESS) {
// 删除原来的logo
try {
String slogo = StrUtil.getNullString(as.getLogo());
if (!slogo.equals("")) {
String rootpath = application.getRealPath("/");
File file = new File(rootpath + as.getLogo());
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 = application.getRealPath("/") + vpath;
fileupload.setSavePath(filepath);
// 置总的上传文件的大小的最大值为600K
fileupload.setMaxAllFileSize(600);
// 设置单个文件的最大值为200k
fileupload.setMaxFileSize(200);
// 设置合法的扩展名
String[] ext = {"gif", "jpg", "png", "jpeg"};
fileupload.setValidExtname(ext);
// 使用随机名称写入磁盘
fileupload.writeFile(true);
logo = fi.getDiskName();
logo = vpath + logo;
as.setLogo(logo);
re = as.save();
}
else {
logo = "";
as.setLogo(logo);
re = as.save();
}
}
else {
throw new ErrMsgException(fileupload.getErrMessage());
}
return re;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
private String userName;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -