📄 themeuploadmgr.java~31~
字号:
package com.redmoon.forum.ui;
import javax.servlet.http.HttpServletRequest;
import cn.js.fan.util.ErrMsgException;
import javax.servlet.ServletContext;
import com.redmoon.kit.util.FileUpload;
import java.io.IOException;
import cn.js.fan.web.Global;
import org.apache.log4j.Logger;
import java.util.*;
import org.jdom.*;
import com.redmoon.kit.util.FileInfo;
import cn.js.fan.util.ParamUtil;
import cn.js.fan.util.StrUtil;
import cn.js.fan.web.SkinUtil;
import java.io.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ThemeUploadMgr {
FileUpload fileUpload = null;
public Logger logger;
public ThemeUploadMgr() {
}
public void modify(ServletContext application,
HttpServletRequest request) throws ErrMsgException {
String filename = "", code = "", name = "", height = "", path = "",
banner = "";
doUpload(application, request);
Vector v = fileUpload.getFiles();
FileInfo fi = null;
if (v.size() > 0) {
fi = (FileInfo) v.get(0);
String vpath = "";
vpath = "forum/images/theme/";
String filepath = Global.getRealPath() + vpath;
fileUpload.setSavePath(filepath);
fileUpload.writeFile(true);
filename = vpath + fi.getDiskName();
}
code = fileUpload.getFieldValue("code");
name = fileUpload.getFieldValue("name");
height = fileUpload.getFieldValue("height");
String picSrc = fileUpload.getFieldValue("picSrc");
delimg(picSrc);
if (!StrUtil.isNumeric(height)) {
throw new ErrMsgException(SkinUtil.LoadString(request,
"res.forum.plugin.ThemeConfig", "height_is_numbic"));
}
ThemeConfig tc = new ThemeConfig();
if (!filename.equals("")) {
int lastIndex = filename.indexOf("images");
path = filename.substring(0, lastIndex - 1);
banner = filename.substring(lastIndex);
tc.set(code, "banner", banner);
tc.set(code, "path", "/" + path);
}
tc.set(code, "height", height);
tc.set(code, "name", name);
tc.writemodify();
ThemeMgr tm = new ThemeMgr();
tm.reload();
}
public FileUpload doUpload(ServletContext application,
HttpServletRequest request) throws
ErrMsgException {
fileUpload = new FileUpload();
String[] extnames = {"gif", "jpg", "png"};
fileUpload.setValidExtname(extnames);
int ret = 0;
try {
ret = fileUpload.doUpload(application, request);
if (ret != fileUpload.RET_SUCCESS) {
throw new ErrMsgException(fileUpload.getErrMessage(request));
}
} catch (IOException e) {
logger.error("doUpload:" + e.getMessage());
}
return fileUpload;
}
public void create(ServletContext application,
HttpServletRequest request) throws ErrMsgException {
String path = "", banner = "";
ThemeForm tf = new ThemeForm();
tf.init();
tf.doUpload(application, request);
String code = tf.checkCode(request);
String name = tf.checkName(request);
String height = tf.checkHeight(request);
String filename = tf.checkFiles(request);
tf.report();
ThemeConfig tc = new ThemeConfig();
int lastIndex = filename.indexOf("images");
path = "/" + filename.substring(0, lastIndex - 1);
banner = filename.substring(lastIndex);
Element root = tc.getRootElement();
List list = root.getChildren();
Element theme = new Element("theme");
theme.setAttribute(new Attribute("code", code));
Element elementName = new Element("name");
elementName.setText(name);
theme.addContent(elementName);
Element elementPath = new Element("path");
elementPath.setText(path);
theme.addContent(elementPath);
Element elementBanner = new Element("banner");
elementBanner.setText(banner);
theme.addContent(elementBanner);
Element elementHeight = new Element("height");
elementHeight.setText(height);
theme.addContent(elementHeight);
list.add(theme);
tc.writemodify();
ThemeMgr tm = new ThemeMgr();
tm.reload();
}
public void del(HttpServletRequest request) throws ErrMsgException {
ThemeConfig tc = new ThemeConfig();
Element root = tc.getRootElement();
List list = root.getChildren();
String picsrc = "";
String code = ParamUtil.get(request, "code");
if (list != null) {
Iterator ir = list.listIterator();
while (ir.hasNext()) {
Element child = (Element) ir.next();
String ecode = child.getAttributeValue("code");
if (ecode.equals(code)) {
picsrc = Global.getRealPath() + child.getChildText("path") + "/" + child.getChildText("banner");
root.removeContent(child);
tc.writemodify();
break;
}
}
}
System.out.print("picSrc" + picsrc);
delimg(picsrc);
ThemeMgr tm = new ThemeMgr();
tm.reload();
}
public void delimg(String src) throws ErrMsgException {
try {
File file = new File(src);
file.delete();
} catch (Exception e) {
logger.error("ThemeUploadMgr modify fail!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -