📄 noallowedcharserviceimpl.java
字号:
/*
* Created on 2007-1-15
* Last modified on 2007-3-21
* Powered by YeQiangWei.com
*/
package com.yeqiangwei.club.service.util.impl;
import java.util.List;
import java.util.StringTokenizer;
import org.apache.log4j.Logger;
import com.yeqiangwei.club.service.model.NoAllowedCharModel;
import com.yeqiangwei.club.service.model.ReplyModel;
import com.yeqiangwei.club.service.model.TopicModel;
import com.yeqiangwei.club.service.model.UserModel;
import com.yeqiangwei.club.service.util.NoAllowedCharService;
import com.yeqiangwei.club.cache.Cache;
import com.yeqiangwei.club.cache.CacheRegion;
import com.yeqiangwei.club.cache.singleton.CacheFactory;
import com.yeqiangwei.club.dao.DAOLocator;
import com.yeqiangwei.club.dao.DAOWrapper;
import com.yeqiangwei.club.dao.NoAllowedCharDAO;
import com.yeqiangwei.club.dao.model.NoAllowedChar;
import com.yeqiangwei.club.dao.model.ReContent;
import com.yeqiangwei.club.dao.model.Reply;
import com.yeqiangwei.club.param.BaseParameter;
import com.yeqiangwei.club.util.BeanUtils;
import com.yeqiangwei.club.util.MessageUtils;
import com.yeqiangwei.util.Validator;
public class NoAllowedCharServiceImpl extends MessageUtils implements NoAllowedCharService{
private static final Logger logger = Logger.getLogger(NoAllowedCharServiceImpl.class);
private Cache cache = CacheFactory.creator(CacheRegion.NOALLOWEDCHAR);
public static NoAllowedCharDAO getNoAllowedCharDAO(){
return DAOWrapper.<NoAllowedCharDAO>getSingletonInstance(DAOLocator.NOALLOWEDCHAR);
}
public UserModel replaceUser(UserModel model) {
if(Validator.isEmpty(model)){
model.setIntro(replaceOfUser(model.getIntro()));
model.setArea(replaceOfUser(model.getArea()));
model.setCity(replaceOfUser(model.getCity()));
model.setEmailAddress(replaceOfUser(model.getEmailAddress()));
model.setHomepage(replaceOfUser(model.getHomepage()));
model.setPenName(replaceOfUser(model.getPenName()));
model.setSignatures(replaceOfUser(model.getSignatures()));
model.setUserName(replaceOfUser(model.getUserName()));
model.setWork(replaceOfUser(model.getWork()));
}
return model;
}
public TopicModel replaceTopic(TopicModel model) {
if(Validator.isEmpty(model)){
model.setTitle(this.replaceOfTopic(model.getTitle()));
}
return model;
}
public Reply replaceReply(TopicModel model) {
return null;
}
public Reply replaceReply(Reply item) {
if(Validator.isEmpty(item)){
item.setTitle(this.replaceOfTopic(item.getTitle()));
}
return item;
}
public ReContent replaceReContent(ReContent item) {
if(Validator.isEmpty(item)){
item.setContent(this.replaceOfTopic(item.getContent()));
}
return item;
}
public boolean permissionUser(UserModel model) {
if(this.noAllowedOfuser(model.getUserName())
|| this.noAllowedOfuser(model.getPenName())
|| this.noAllowedOfuser(model.getIntro())
|| this.noAllowedOfuser(model.getArea())
|| this.noAllowedOfuser(model.getCity())
|| this.noAllowedOfuser(model.getSignatures())
){
return false;
}else{
return true;
}
}
public boolean permissionTopic(TopicModel model)
{
boolean permission = true;
if(!Validator.isEmpty(model)){
if(this.noAllowedOfTopic(model.getTitle())
||this.noAllowedOfTopic(model.getContentModel().getContent())
){
permission = false;
}
}
return permission;
}
public boolean permissionTopic(ReplyModel model)
{
boolean permission = true;
if(!Validator.isEmpty(model)){
if(this.noAllowedOfTopic(model.getTitle())
||this.noAllowedOfTopic(model.getReContentModel().getContent())
){
permission = false;
}
}
return permission;
}
public NoAllowedCharModel createOrUpdate(NoAllowedCharModel model) {
if(model.getNoAllowedId()>0){
model = this.update(model);
}
else{
model = this.create(model);
}
return model;
}
public NoAllowedCharModel create(NoAllowedCharModel model) {
if(!Validator.isEmpty(model)){
NoAllowedChar item = new NoAllowedChar();
BeanUtils.copyProperties(item,model);
item = getNoAllowedCharDAO().create(item);
this.setMessage(MessageUtils.getMessage(item));
return model;
}else{
this.setMessage(MessageUtils.getMessage("error_system"));
return null;
}
}
public NoAllowedCharModel update(NoAllowedCharModel model) {
if(!Validator.isEmpty(model)){
NoAllowedChar item = new NoAllowedChar();
BeanUtils.copyProperties(item,model);
item = getNoAllowedCharDAO().update(item);
this.setMessage(MessageUtils.getMessage(item));
cache.remove("NoAllowedCharModel");
return model;
}else{
this.setMessage(super.getMessage("error_system"));
return null;
}
}
public boolean noAllowedOfuser(String str) {
String theChars = findOnly().getNoAllowedUser();
return this.noAllowedChar(str,theChars);
}
public String replaceOfUser(String str) {
//String theChars = findOnly().getReplaceUser();
return this.replace(str,findOnly().getReplaceUser());
}
public boolean noAllowedOfTopic(String str) {
//String theChars = findOnly().getNoAllowedTopic();
return this.noAllowedChar(str,findOnly().getNoAllowedTopic());
}
public String replaceOfTopic(String str) {
//String theChars = findOnly().getReplaceTopic();
return this.replace(str,findOnly().getReplaceTopic());
}
public boolean noAllowedOfMessage(String str) {
//String theChars = findOnly().getNoAllowedMessage();
return this.noAllowedChar(str,findOnly().getNoAllowedMessage());
}
public String replaceOfMessage(String str) {
String theChars = findOnly().getReplaceMessage();
return this.replace(str,theChars);
}
/**
*
* @param str 字符串内容
* @param theChars 被摒闭的字符
* @return
*/
private boolean noAllowedChar(String str, String theChars) {
boolean bea = false;
if(!Validator.isEmpty(theChars)){
theChars = theChars.replaceAll("\r\n","");
//theChars = theChars.replaceAll("\n","");
StringTokenizer st = new StringTokenizer(theChars, "|");
for(int i=0;st.hasMoreTokens();i++){
String s = st.nextToken().trim();
if(str.indexOf(s)!=-1){
bea = true;; //表示关键字key含过滤字符
}
}
}
return bea;
}
private String replace(String str, String theChars) {
if(!Validator.isEmpty(str) && !Validator.isEmpty(theChars))
{
StringTokenizer st1 = new StringTokenizer(theChars, "\n");
String[] sts1 = new String[st1.countTokens()];
try{
for(int i1=0; st1.hasMoreTokens(); i1++){
sts1[i1] = st1.nextToken().trim();
StringTokenizer st2 = new StringTokenizer(sts1[i1], "|");
String[] sts2 = new String[st2.countTokens()];
for(int i2=0; st2.hasMoreTokens(); i2++){
sts2[i2] = st2.nextToken().trim();
}
if(sts2.length>=2){
str = str.replaceAll(sts2[0],sts2[1]);
}
}
}catch(Exception e){
logger.error(e.toString());
}
}else{
return str;
}
return str;
}
public NoAllowedCharModel findById(int id) {
return null;
}
@SuppressWarnings("unchecked")
public List findByParameter(BaseParameter param) {
return null;
}
public long countByParameter(BaseParameter param) {
return 0;
}
public NoAllowedCharModel findOnly() {
NoAllowedCharModel model = (NoAllowedCharModel) cache.get("NoAllowedCharModel");
if(Validator.isEmpty(model)){
NoAllowedChar item = getNoAllowedCharDAO().findOnly();
model = new NoAllowedCharModel();
BeanUtils.copyProperties(model,item);
cache.put("NoAllowedCharModel",model);
}
return model;
}
public int delete(NoAllowedCharModel model) {
return 0;
}
public int delete(String[] ids) {
return 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -