?? forbid.java
字號:
package com.laoer.bbscs.sys;
import java.io.*;
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.*;
/**
* <p>Title: TianYi BBS</p>
* <p>Description: TianYi BBS System</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: LAOER.COM/TIANYISOFT.NET</p>
* @author laoer
* @version 6.0
*/
public class Forbid {
private static final Log logger = LogFactory.getLog(Forbid.class);
public static Forbid instance;
private HashMap forbidipHm = new HashMap();
private HashMap forbidwordsHm = new HashMap();
public synchronized static Forbid getInstance() {
if (instance == null) {
instance = new Forbid();
}
return instance;
}
public Forbid() {
load();
}
public void load() {
SAXBuilder sb = new SAXBuilder();
try {
Document doc = sb.build(new FileInputStream(Constant.CONFIGPATH +
Constant.FORBIDXMLFILE));
logger.info("Load forbid xml file:" + Constant.CONFIGPATH +
Constant.FORBIDXMLFILE);
Element root = doc.getRootElement();
Element forbidip = root.getChild("forbidip");
List forbidiplist = forbidip.getChildren();
String address = "";
for (int i = 0; i < forbidiplist.size(); i++) {
Element ip = (Element) forbidiplist.get(i);
address = ip.getAttribute("address").getValue();
forbidipHm.put(address, address);
}
Element forbidwords = root.getChild("forbidwords");
List forbidwordslist = forbidwords.getChildren();
String content = "";
for (int i = 0; i < forbidwordslist.size(); i++) {
Element word = (Element) forbidwordslist.get(i);
content = word.getAttribute("content").getValue();
forbidwordsHm.put(content, content);
}
}
catch (Exception ex) {
logger.error(ex);
}
}
public synchronized void save() {
Element rootElement = new Element("forbid");
Document forbidDocument = new Document(rootElement);
Element forbidip = new Element("forbidip");
Iterator i = this.forbidipHm.values().iterator();
while (i.hasNext()) {
Element ip = new Element("ip");
ip.addAttribute("address", (String) i.next());
forbidip.addContent(ip);
}
rootElement.addContent(forbidip);
Element forbidwords = new Element("forbidwords");
i = this.forbidwordsHm.values().iterator();
while (i.hasNext()) {
Element word = new Element("word");
word.addAttribute("content", (String) i.next());
forbidwords.addContent(word);
}
rootElement.addContent(forbidwords);
try {
XMLOutputter xmlo = new XMLOutputter(" ", true, "UTF-8");
xmlo.output(forbidDocument, new FileOutputStream(Constant.CONFIGPATH +
Constant.FORBIDXMLFILE));
logger.info("Save forbid xml file:" + Constant.CONFIGPATH +
Constant.FORBIDXMLFILE);
}
catch (java.io.IOException e) {
logger.error(e);
}
}
public HashMap getForbidipHm() {
return forbidipHm;
}
public HashMap getForbidwordsHm() {
return forbidwordsHm;
}
public void setForbidwordsHm(HashMap forbidwordsHm) {
this.forbidwordsHm = forbidwordsHm;
}
public void setForbidipHm(HashMap forbidipHm) {
this.forbidipHm = forbidipHm;
}
public Result addIp(String ip) {
if (this.forbidipHm.get(ip) != null) {
return new Result(false, "error.adminforbid.ipexist");
}
this.forbidipHm.put(ip, ip);
this.save();
return new Result(true, "");
}
public Result removeIp(String ip) {
this.forbidipHm.remove(ip);
this.save();
return new Result(true, "");
}
public Result addWord(String word) {
if (this.forbidwordsHm.get(word) != null) {
return new Result(false, "error.adminforbid.wordexist");
}
this.forbidwordsHm.put(word, word);
this.save();
return new Result(true, "");
}
public Result removeWord(String word) {
this.forbidwordsHm.remove(word);
this.save();
return new Result(true, "");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -