📄 msgmgr.java~73~
字号:
if (pu.getType().equals(pu.TYPE_BOARD))
isPlugin = true;
else if (pu.getType().equals(pu.TYPE_TOPIC) && pluginCode.equals(pu.getCode()))
isPlugin = true;
if (isPlugin) {
IPluginMsgAction ipa = pu.getMsgAction();
try {
re = ipa.AddNew(application, request, md, fu);
} catch (ErrMsgException e) {
// 删除新发的贴子,但是贴子作者的相关经验值则不受影响
try {
md.delTopic(md.getId(), true);
} catch (ResKeyException e1) {
logger.error("AddNewWE:" +
e1.getMessage(request));
}
throw e;
}
}
}
}
}
// 得分处理
if (re) {
ScoreMgr sm = new ScoreMgr();
Vector v = sm.getAllScore();
Iterator ir = v.iterator();
while (ir.hasNext()) {
ScoreUnit su = (ScoreUnit) ir.next();
IPluginScore ips = su.getScore();
if (ips != null)
ips.AddNew(application, request, md);
}
}
return true;
}
public String LoadString(HttpServletRequest request, String key) {
return SkinUtil.LoadString(request, "res.forum.MsgMgr", key);
}
/**
* 普通及UBB发贴
* @param application ServletContext
* @param request HttpServletRequest
* @return boolean
* @throws ErrMsgException
*/
public boolean AddNew(ServletContext application,
HttpServletRequest request) throws
ErrMsgException {
FileUpload fu = doUpload(application, request);
String boardcode = StrUtil.getNullString(fu.getFieldValue("boardcode"));
if (boardcode.equals(""))
throw new ErrMsgException(LoadString(request, "err_need_board"));
if (!privilege.canAddNew(request, boardcode, fu))
throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
// 检查版块是否存在
Leaf lf = new Leaf();
lf = lf.getLeaf(boardcode);
if (lf==null || !lf.isLoaded())
throw new ErrMsgException(LoadString(request, "err_board_lost")); // "版块 " + boardcode + " 不存在!");
// 这种插件发贴的方式能防止因addtopic_new.jsp发贴时,原来在同城交易中发贴,结果选了其它版块
// 因为其它版块无插件功能,所以下面的检查并取得版块的所有插件,能防止发贴信息的混乱
String pluginCode = StrUtil.getNullString(fu.getFieldValue("pluginCode"));
boolean isPluginValid = false;
// 插件的权限检查
PluginMgr pm = new PluginMgr();
Vector vplugin = pm.getAllPluginUnitOfBoard(boardcode);
if (vplugin.size() > 0) {
Iterator irplugin = vplugin.iterator();
while (irplugin.hasNext()) {
PluginUnit pu = (PluginUnit) irplugin.next();
IPluginPrivilege ipp = pu.getPrivilege();
// logger.info("plugin name:" + pu.getName(request));
if (!ipp.canAddNew(request, boardcode)) {
String str = LoadString(request, "err_pvg_plugin");
str = str.replaceFirst("\\$p", pu.getName(request));
throw new ErrMsgException(str);
}
// 检查指定的pluginCode是否被允许
if (!pluginCode.equals(""))
if (pu.getCode().equals(pluginCode))
isPluginValid = true;
}
}
// 如果指定的pluginCode不被允许,则报错
if (!pluginCode.equals("") && !isPluginValid) {
throw new ErrMsgException(LoadString(request, "err_plugin_invalid"));
}
String name;
// 如果已登录,则先使用登录信息,如果未登录,则使用随表单一起发送的用户信息
name = privilege.getUser(request); // cookiebean.getCookieValue(request, "name");
boolean re = false;
MsgDb msgDb = new MsgDb();
try {
re = msgDb.AddNew(application, request, name, fu);
if (re) {
id = msgDb.getId();
blog = msgDb.isBlog();
name = msgDb.getName();
}
} catch (ErrMsgException e) {
throw e;
}
catch (ResKeyException e) {
throw new ErrMsgException(e.getMessage(request));
}
if (re) {
// 如果有plugin2Code传递过来
String plugin2Code = StrUtil.getNullString(fu.getFieldValue("plugin2Code")).trim();
if (!plugin2Code.equals("")) {
Plugin2Mgr p2m = new Plugin2Mgr();
Plugin2Unit p2u = p2m.getPlugin2Unit(plugin2Code);
logger.info("AddNew: p2u=" + p2u);
if (p2u!=null) {
try {
p2u.getMsgAction().AddNew(application, request, msgDb,
fu);
}
catch (ErrMsgException e) {
// 删除新发的贴子,但是贴子作者的相关经验值则不受影响
try {
msgDb.delTopic(msgDb.getId(), true);
}
catch (ResKeyException e1) {
logger.error("AddNew:" + e1.getMessage(request));
}
throw e;
}
}
}
}
if (re) {
// 插件对应加入新贴的action
if (vplugin.size() > 0) {
Iterator irplugin = vplugin.iterator();
while (irplugin.hasNext()) {
PluginUnit pu = (PluginUnit) irplugin.next();
IPluginMsgAction ipa = pu.getMsgAction();
// logger.info("plugin name:" + pu.getName(request));
boolean isPlugin = false;
if (pu.getType().equals(pu.TYPE_BOARD))
isPlugin = true;
else if (pu.getType().equals(pu.TYPE_TOPIC) && pluginCode.equals(pu.getCode()))
isPlugin = true;
if (isPlugin) {
try {
re = ipa.AddNew(application, request, msgDb, fu);
} catch (ErrMsgException e) {
// 删除新发的贴子,但是贴子作者的相关经验值则不受影响
try {
msgDb.delTopic(msgDb.getId(), true);
} catch (ResKeyException e1) {
logger.error("AddNew:" + e1.getMessage(request));
}
throw e;
}
}
}
}
}
// 得分处理
if (re) {
ScoreMgr sm = new ScoreMgr();
Vector v = sm.getAllScore();
Iterator ir = v.iterator();
while (ir.hasNext()) {
ScoreUnit su = (ScoreUnit) ir.next();
IPluginScore ips = su.getScore();
if (ips!=null)
ips.AddNew(application, request, msgDb);
}
}
return re;
}
public MsgDb getMsgDb(long id) {
MsgDb md = new MsgDb();
return md.getMsgDb(id);
}
/**
* 普通及UBB方式发表回复
* @param application ServletContext
* @param request HttpServletRequest
* @return boolean
* @throws ErrMsgException
*/
public boolean AddReply(ServletContext application,
HttpServletRequest request) throws ErrMsgException {
FileUpload fu = doUpload(application, request);
String boardcode = StrUtil.getNullString(fu.getFieldValue("boardcode"));
if (boardcode.equals(""))
throw new ErrMsgException(LoadString(request, "err_need_board"));
if (!privilege.canAddReply(request, boardcode, fu))
throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
MsgDb replymsg = new MsgDb();
long replyid = replymsg.getReplyid();
replymsg = getMsgDb(replyid);
long rootid = replymsg.getRootid();
// 插件的权限检查
PluginMgr pm = new PluginMgr();
Vector vplugin = pm.getAllPluginUnitOfBoard(boardcode);
if (vplugin.size() > 0) {
Iterator irplugin = vplugin.iterator();
while (irplugin.hasNext()) {
PluginUnit pu = (PluginUnit) irplugin.next();
IPluginPrivilege ipp = pu.getPrivilege();
// logger.info("plugin name:" + pu.getName(request));
if (!ipp.canAddReply(request, boardcode, rootid)) {
String s = LoadString(request, "err_pvg_plugin");
s = s.replaceFirst("\\$p", pu.getName(request));
throw new ErrMsgException(s);
}
}
}
String name = privilege.getUser(request);
boolean re = false;
MsgDb msgDb = new MsgDb();
try {
re = msgDb.AddReply(application, request, name, fu);
} catch (ErrMsgException e) {
throw e;
}
if (re) {
// 插件对应加入回贴的action
String pluginCode = StrUtil.getNullString(fu.getFieldValue("pluginCode"));
if (vplugin.size() > 0) {
Iterator irplugin = vplugin.iterator();
while (irplugin.hasNext()) {
PluginUnit pu = (PluginUnit) irplugin.next();
boolean isPlugin = false;
if (pu.getType().equals(pu.TYPE_BOARD))
isPlugin = true;
else if (pu.getType().equals(pu.TYPE_TOPIC) && pluginCode.equals(pu.getCode()))
isPlugin = true;
if (isPlugin) {
IPluginMsgAction ipa = pu.getMsgAction();
// logger.info("plugin name:" + pu.getName(request));
re = ipa.AddReply(application, request, msgDb, fu);
}
}
}
}
// 得分处理
if (re) {
ScoreMgr sm = new ScoreMgr();
Vector v = sm.getAllScore();
Iterator ir = v.iterator();
while (ir.hasNext()) {
ScoreUnit su = (ScoreUnit) ir.next();
IPluginScore ips = su.getScore();
if (ips!=null)
ips.AddReply(application, request, msgDb);
}
}
return true;
}
/**
* 高级方式回复
* @param application ServletContext
* @param request HttpServletRequest
* @return boolean
* @throws ErrMsgException
*/
public boolean AddReplyWE(ServletContext application,
HttpServletRequest request) throws ErrMsgException {
MultiFileUpload fu = (MultiFileUpload)doUpload(application, request);
String boardcode = StrUtil.getNullString(fu.getFieldValue("boardcode"));
if (boardcode.equals(""))
throw new ErrMsgException(LoadString(request, "err_need_board"));
if (!privilege.canAddReply(request, boardcode, fu))
throw new ErrMsgException(SkinUtil.LoadString(request, SkinUtil.PVG_INVALID));
MsgDb replymsg = new MsgDb();
long replyid = replymsg.getReplyid();
replymsg = getMsgDb(replyid);
long rootid = replymsg.getRootid();
// 插件的权限检查
PluginMgr pm = new PluginMgr();
Vector vplugin = pm.getAllPluginUnitOfBoard(boardcode);
if (vplugin.size() > 0) {
Iterator irplugin = vplugin.iterator();
while (irplugin.hasNext()) {
PluginUnit pu = (PluginUnit) irplugin.next();
IPluginPrivilege ipp = pu.getPrivilege();
// logger.info("plugin name:" + pu.getName(request));
if (!ipp.canAddReply(request, boardcode, rootid)) {
String s = LoadString(request, "err_pvg_plugin");
s = s.replaceFirst("\\$p", pu.getName(request));
throw new ErrMsgException(s);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -