📄 replyproxy.java
字号:
/*
* Created on 2007-3-24
* Last modified on 2007-8-22
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.topic;
import java.util.List;
import org.apache.log4j.Logger;
import com.yeqiangwei.club.exception.ClubException;
import com.yeqiangwei.club.param.TopicParameter;
import com.yeqiangwei.club.service.ServiceLocator;
import com.yeqiangwei.club.service.ServiceWrapper;
import com.yeqiangwei.club.service.model.ManageLogModel;
import com.yeqiangwei.club.service.model.ReplyModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.security.UserPower;
import com.yeqiangwei.club.service.user.UserService;
import com.yeqiangwei.club.service.util.ManageLogService;
import com.yeqiangwei.club.service.util.NoAllowedCharService;
import com.yeqiangwei.club.util.LocalizeFile;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.club.controller.form.TopicTrashForm;
import com.yeqiangwei.util.FormatDateTime;
import com.yeqiangwei.util.IpUtils;
import com.yeqiangwei.util.StringHelper;
import com.yeqiangwei.util.Validator;
public class ReplyProxy implements ReplyService{
private static final Logger logger = Logger.getLogger(ReplyProxy.class);
private static ReplyService REPLYSERVICE;
private static UserPower USER_POWER;
static{
if(REPLYSERVICE==null)REPLYSERVICE = new ReplyServiceImpl();
if(USER_POWER==null)USER_POWER = new UserPower();
}
public int trash(List<Integer> list, boolean isDeleted) throws ClubException {
if(!Validator.isEmpty(list)){
return REPLYSERVICE.trash(list,isDeleted);
}else{
throw new ClubException(MessageUtils.getMessage("error_parameter"));
}
}
public int delete(List<Integer> ids) {
int c = 0;
if(!Validator.isEmpty(ids)){
c = REPLYSERVICE.delete(ids);
}
return c;
}
public ReplyModel trash(TopicTrashForm form) throws ClubException {
ReplyModel model = REPLYSERVICE.trash(form);
if(!Validator.isEmpty(model)){
UserModel byuser = form.getUserModel(); //操作人员
UserModel umodel = this.getUserService().findById(form.getUserId()); //帖子作者
if(!Validator.isEmpty(umodel)){
ManageLogModel log = new ManageLogModel();
log.setTopicId(model.getTopicId());
log.setReplyId(model.getReplyId());
log.setTitle(model.getTitle());
if(!Validator.isEmpty(byuser)){
log.setByUserId(byuser.getUserId() );
log.setByUserName(byuser.getUserName());
log.setByUserIp(form.getUserIp());
}
log.setCreateDateTime(FormatDateTime.now());
log.setForumId(model.getForumId());
log.setUserName(umodel.getUserName());
log.setUserId(umodel.getUserId());
log.setIsList(form.getIsList());
log.setListByUserName(form.getListByUserName());
if(form.getIsDeleted()){
this.getUserService().ruleUtils(umodel,model.getForumId(),8); //获取用户积分变动
this.getUserService().update(umodel,false);
this.getUserService().ruleUtils(log,model.getForumId(),8); //获取日志积分变动
log.setMemo("删除文章");
}else{
log.setMemo("恢复文章");
}
StringBuffer temp = new StringBuffer();
temp.append(form.getContent());
log.setContent(temp.toString());
this.getManageLogService().create(log);
}
}
return model;
}
public List<ReplyModel> findReplyAndContent(TopicParameter param) {
return REPLYSERVICE.findReplyAndContent(param);
}
public ReplyModel findReplyAndContentById(int id) {
return REPLYSERVICE.findReplyAndContentById(id);
}
public List<ReplyModel> findReplyByTopicId(TopicParameter param) {
return REPLYSERVICE.findReplyByTopicId(param);
}
public ReplyModel findById(int id) {
return REPLYSERVICE.findById(id);
}
public ReplyModel createOrUpdate(ReplyModel model) throws ClubException {
if(model.getReplyId()>0){
return this.update(model);
}else{
return this.create(model);
}
}
private void localizeFile(ReplyModel model){
if(model.getLocalizeImage()==1
&&USER_POWER.canAccess(
model.getUserModel(),model.getForumId(),UserPower.OPERATEPOWER,6))
{ //本地化图片
String temp = model.getReContentModel().getContent();
temp = LocalizeFile.localizeImage(temp,LocalizeFile.imagepath(model.getForumId()));
model.getReContentModel().setContent(temp);
}
}
private void noAllowed(ReplyModel model) throws ClubException{
if(!this.getNoAllowedCharService().permissionTopic(model)){
throw new ClubException(MessageUtils.getMessage("error_noAllowedChar"));
}else{
if(!Validator.isEmpty(model.getUserModel())){
model.setUserId(model.getUserModel().getUserId());
model.setUserName(model.getUserModel().getUserName().trim());
}else{//判断用户是否在页面同时输入了用户名和密码,如果是则请求数据库验证,否则只当作过客提交
UserModel user = null;
if(!Validator.isEmpty(model.getPassword())&&!Validator.isEmpty(model.getUserName())){
user = new UserModel();
user.setUserName(model.getUserName());
user.setPassword(model.getPassword());
user = this.getUserService().findByUserNameAndPassword(user,true);
if(Validator.isEmpty(user)){//如果登录失败
//this.setMessage(MessageUtils.getMessage("error_login"));
throw new ClubException(MessageUtils.getMessage("error_login"));
}else{
model.setUserId(user.getUserId());
model.setUserName(user.getUserName());
model.setUserModel(user);
}
}else{//如果密码为空则为过客取名
String eip = IpUtils.enAddr(model.getUserIp());
eip = eip.substring(eip.length()-6,eip.length());
model.setUserName("过客"+eip);
}
}
}
}
/**
* 自动从内容中过去Titile
* @param model
*/
private void autoTitle(ReplyModel model){
if(Validator.isEmpty(model.getTitle())){
String content = model.getReContentModel().getContent();
content = StringHelper.substring(content,0,500,"");
content = StringHelper.ubbPattern(content,"\\[(.*?)\\](.*?)\\[/(.*?)\\]","","");
content = StringHelper.ubbPattern(content,"\\[(.*?)\\]","","");
content = StringHelper.ubbPattern(content,"<(.*?)>","","");
if(content.length()>0){
content = content.replace("\r\n","{r-n}");
if(content.startsWith("{r-n}")){
content = StringHelper.substring(content,5,content);
}
int n = content.indexOf("{r-n}");
if(n==-1||n>30){
n = 30;
}
String str = StringHelper.substring(content,0,n,"");
int i1 = str.length();
int i2 = model.getReContentModel().getContent().length();
logger.debug("model.getReContentModel().getContent(): "+content);
logger.debug("original content: "+content);
logger.debug("auto title: "+str);
logger.debug("model.getReContentModel().getContent().length(): "+i2);
logger.debug("str.length(): "+i1);
if(i1==i2){
model.getReContentModel().setContent("");
logger.debug("model.getReContentModel().getContent(): "+model.getReContentModel().getContent());
}
else if(!Validator.isEmpty(str)){
str+="...";
}
model.setTitle(str);
}
}
}
public static void main(String args[]){
String content = "<afdafds>sdf</dafds>";
String str = StringHelper.ubbPattern(content,"<(.*?)>","","");
System.out.println(str);
}
public ReplyModel create(ReplyModel model) throws ClubException {
this.autoTitle(model);
this.noAllowed(model);
this.localizeFile(model);
return REPLYSERVICE.create(model);
}
public ReplyModel update(ReplyModel model) throws ClubException {
this.autoTitle(model);
/*
* 是否具备编辑他人文章的权限
*/
boolean updateadmin = USER_POWER.canAccess(model.getSessionUserModel()
,model.getForumId()
,UserPower.ADMINPOWER
,0);
/*
* 是否具备编辑被回复过的文章的权限
*/
boolean updatereplyed = USER_POWER.canAccess(model.getSessionUserModel()
,model.getForumId()
,UserPower.OPERATEPOWER
,4);
/*
* 是否具备编辑自己文章的权限
*/
boolean updatemy = USER_POWER.canAccess(model.getSessionUserModel()
,model.getForumId()
,UserPower.OPERATEPOWER
,3);
if(!updateadmin){
//this.setMessage(MessageUtils.getMessage("error_power"));
/*
* 如果用户编辑的是自己的文章
*/
if(model.getSessionUserModel()!=null
&& model.getSessionUserModel().getUserId()==model.getUserId())
{
/*
* 如果用户编辑的是自己的文章
*/
if(!updatemy){
throw new ClubException(MessageUtils.getMessage("error_power"));
}
/*
* 判断是否具备编辑被回复过的文章权限
*/
if(model.getReplys()>0&&!updatereplyed){
//this.setMessage(MessageUtils.getMessage("error_update_replyed"));
throw new ClubException(MessageUtils.getMessage("error_update_replyed"));
}
}else{
//this.setMessage(MessageUtils.getMessage("error_power"));
throw new ClubException(MessageUtils.getMessage("error_power"));
}
}
this.localizeFile(model);
return REPLYSERVICE.update(model);
}
public int delete(ReplyModel model) {
return 0;
}
public int delete(String[] ids) {
return 0;
}
public List<ReplyModel> findByParameter(TopicParameter param) {
return REPLYSERVICE.findByParameter(param);
}
public long countByParameter(TopicParameter param) {
return REPLYSERVICE.countByParameter(param);
}
public UserService getUserService() {
return ServiceWrapper.<UserService>getSingletonInstance(ServiceLocator.USER);
}
public NoAllowedCharService getNoAllowedCharService(){
return ServiceWrapper.<NoAllowedCharService>getSingletonInstance(ServiceLocator.NOALLOWEDCHAR);
}
public ManageLogService getManageLogService() {
return ServiceWrapper.<ManageLogService>getSingletonInstance(ServiceLocator.MANAGELOG);
}
/*
public TopicDAO getTopicDAO() {
return DAOWrapper.<TopicDAO>getSingletonInstance(DAOLocator.TOPIC);
}
public UserPower getUserPower() {
if(Validator.isEmpty(userPower)){
userPower = new UserPower();
}
return userPower;
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -