📄 sysmyset.java
字号:
/* * 作者: 胡李青 * qq: 31703299 * Copyright (c) 2007 huliqing * 主页 http://www.tbuy.biz/ * 你可以免费使用该软件,未经许可请勿作用于任何商业目的,如有技术问题请与本人联系! */package biz.tbuy.common.bean;import biz.tbuy.common.ConfigOper;import biz.tbuy.common.Constants;import biz.tbuy.common.UploadedFileOper;import biz.tbuy.common.Utils;import java.util.HashMap;import java.util.Map;import org.apache.myfaces.custom.fileupload.UploadedFile;/** * @author huliqing * <p><b>qq:</b>31703299 * <p><b>E-mail:</b><a href="mailto:huliqing.cn@gmail.com">huliqing.cn@gmail.com</a> * <p><b>Homepage:</b><a href="http://www.tbuy.biz/">http://www.tbuy.biz/</a> */public class SysMySet extends BaseBean{ private UploadedFileOper _fileOper; // 用于处理上传文件的自定义类 private UploadedFile _myFileLogo; // logo文件 private UploadedFile _myFileBanner; // banner文件 private String _bannerScript; // 使用代码设置banner private String _webname; // 网站名称 private String _icp; // icp备案信息 private String _comment; // 额外信息 /** Creates a new instance of SysMySet */ public SysMySet() { loadInfo(); } public void setMyFileLogo(UploadedFile myFileLogo) { _myFileLogo = myFileLogo; } public UploadedFile getMyFileLogo() { return _myFileLogo; } public void setMyFileBanner(UploadedFile myFileBanner) { _myFileBanner = myFileBanner; } public UploadedFile getMyFileBanner() { return _myFileBanner; } public void setBannerScript(String bannerScript) { _bannerScript = bannerScript; } public String getBannerScript() { return _bannerScript; } public void setWebname(String webname) { _webname = webname; } public String getWebname() { return _webname; } public void setIcp(String icp) { _icp = icp; } public String getIcp() { return _icp; } public void setComment(String comment) { _comment = comment; } public String getComment() { return _comment; } /** * 设置logo * 保存上传文件后更新appConfig配置文件,更新成功后重新载入配置 */ public String setLogo() throws Exception { if (_myFileLogo == null) { return null; } _fileOper = new UploadedFileOper(_myFileLogo); if (!_fileOper.getType().toLowerCase().startsWith("image")) { Utils.addErrorMessage(getBundle(), "必须为图片类型才能上传"); return Constants.OUT_FAILURE; } if (_fileOper.saveTo(getSavePath() + _fileOper.getNewName())) { ConfigOper configOper = new ConfigOper(); Map<String, String> myset = new HashMap<String, String>(1); myset.put("logo", Constants.PATH_MYSETTING + _fileOper.getNewName()); configOper.updateMySetting(myset); Utils.addInfoMessage(getBundle(), "设置Logo成功!"); getComApplication().reloadMySetting(); return Constants.OUT_SUCCESS; } else { Utils.addInfoMessage(getBundle(), "设置Logo时遇到问题"); return Constants.OUT_FAILURE; } } /** * 设置banner,更新成功后重新载入配置 */ public String setBanner() throws Exception { if (_myFileBanner == null) return null; _fileOper = new UploadedFileOper(_myFileBanner); if (!_fileOper.getType().toLowerCase().startsWith("image")) { Utils.addErrorMessage(getBundle(), "必须为图片类型才能上传"); return Constants.OUT_FAILURE; } String contextPath = getFacesContext().getExternalContext().getRequestContextPath(); if (_fileOper.saveTo(getSavePath() + _fileOper.getNewName())) { ConfigOper configOper = new ConfigOper(); Map<String, String> myset = new HashMap<String, String>(1); String banner = "<img src='" + contextPath + Constants.PATH_MYSETTING + _fileOper.getNewName() + "'/>"; myset.put("banner", banner); configOper.updateMySetting(myset); Utils.addInfoMessage(getBundle(), "设置Banner成功!"); getComApplication().reloadMySetting(); loadInfo(); return Constants.OUT_SUCCESS; } else { Utils.addInfoMessage(getBundle(), "设置Banner时遇到问题"); return Constants.OUT_FAILURE; } } /** * 使用网页代码直接设置banner信息 */ public String setBannerScript() { try { ConfigOper configOper = new ConfigOper(); Map<String, String> myset = new HashMap<String, String>(1); myset.put("banner", _bannerScript); configOper.updateMySetting(myset); Utils.addInfoMessage(getBundle(), "设置Banner成功!"); getComApplication().reloadMySetting(); return Constants.OUT_SUCCESS; } catch (Exception ex) { return Constants.OUT_FAILURE; } } /** * clearBanner,清除已经设置的banner */ public String clearBanner() throws Exception { ConfigOper configOper = new ConfigOper(); Map<String, String> myset = new HashMap<String, String>(1); myset.put("banner", ""); configOper.updateMySetting(myset); Utils.addInfoMessage(getBundle(), "清除Banner成功!"); getComApplication().reloadMySetting(); loadInfo(); return Constants.OUT_SUCCESS; } /** * 设置页脚信息,更新成功后重新载入配置 */ public String setOther() { try { ConfigOper configOper = new ConfigOper(); Map<String, String> myset = new HashMap<String, String>(4); myset.put("webname", _webname); myset.put("icp", _icp); myset.put("comment", _comment); configOper.updateMySetting(myset); Utils.addInfoMessage(getBundle(), "设置信息成功!"); } catch (Exception e) { Utils.addErrorMessage(getBundle(), "设置信息时遇到问题!"); return Constants.OUT_FAILURE; } getComApplication().reloadMySetting(); return Constants.OUT_SUCCESS; } /** * 获取需要保存上传文件的文件夹路径 */ private String getSavePath() { return getComApplication().getServletContextPath() + Constants.PATH_MYSETTING; } /** * 载入信息 */ private void loadInfo() { Map<String, String> myset = getComApplication().getMySetting(); _webname = myset.get("webname"); _icp = myset.get("icp"); _comment = myset.get("comment"); _bannerScript = myset.get("banner"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -