systemconfig.java~4~
来自「一个自己做的公司网站和办公职员管理系统。」· JAVA~4~ 代码 · 共 157 行
JAVA~4~
157 行
package ws.woa.core;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.xerces.parsers.SAXParser;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
/**
* 僔僗僥儉偺愝掕忣曬傪曐帩偡傞僋儔僗丅
*
* @author Wang
*/
public class SystemConfig {
private String requestEncode;
//private String mpMaxBytes;
private String smtpHost;
private String smtpPort;
private static SystemConfig _instance = null;
/**
* 僔儞僌儖僩儞僷僞乕儞揔梡偺偨傔偺僾儔僀儀乕僩僐儞僗僩儔僋僞丅
*/
private SystemConfig() throws IOException, SAXException, FileNotFoundException {
String file = ControllerServlet._context.getRealPath("/WEB-INF/system.xml");
SystemConfigSAXHandler handler = new SystemConfigSAXHandler();
XMLReader parser = new SAXParser();
parser.setContentHandler(handler);
parser.setErrorHandler(handler);
parser.parse(new InputSource(new FileInputStream(file)));
}
/**
* Returns the mpMaxBytes.
* @return String
*/
// public String getMpMaxBytes() {
// return mpMaxBytes;
// }
/**
* 儕僋僄僗僩僄儞僐乕僪傪庢摼偟傑偡丅
* @return String
*/
public String getRequestEncode() {
return requestEncode;
}
/**
* SMTP僒乕僶偺儂僗僩柤傪庢摼偟傑偡丅
* @return String
*/
public String getSmtpHost() {
return smtpHost;
}
/**
* SMTP僒乕僶偺億乕僩斣崋傪庢摼偟傑偡丅
* @return String
*/
public String getSmtpPort() {
return smtpPort;
}
/**
* Sets the mpMaxBytes.
* @param mpMaxBytes The mpMaxBytes to set
*/
// public void setMpMaxBytes(String mpMaxBytes) {
// this.mpMaxBytes = mpMaxBytes;
// }
/**
* 儕僋僄僗僩僄儞僐乕僪傪巜掕偟傑偡丅
* @param requestEncode The requestEncode to set
*/
public void setRequestEncode(String requestEncode) {
this.requestEncode = requestEncode;
}
/**
* SMTP僒乕僶偺儂僗僩柤傪巜掕偟傑偡丅
* @param smtpHost The smtpHost to set
*/
public void setSmtpHost(String smtpHost) {
this.smtpHost = smtpHost;
}
/**
* SMTP僒乕僶偺億乕僩斣崋傪巜掕偟傑偡丅
* @param smtpPort The smtpPort to set
*/
public void setSmtpPort(String smtpPort) {
this.smtpPort = smtpPort;
}
/**
* SystemConfig偺僀儞僗僞儞僗傪庢摼偟傑偡丅
*/
public static synchronized SystemConfig getInstance()
throws FileNotFoundException, IOException, SAXException {
if(_instance==null){
_instance = new SystemConfig();
}
return _instance;
}
//////////////////////////////////////////////////////////////////////
/**
* system.xml傪夝愅偟偰SystemConfig傪僙僢僩傾僢僾偡傞偨傔偺僴儞僪儔丅
*/
class SystemConfigSAXHandler extends DefaultHandler {
/**
* @see org.xml.sax.ContentHandler#startElement(String, String, String, Attributes)
*/
public void startElement(String uri,String local,String raw,Attributes attrs){
if(raw.equals("smtp")){
parseSMTP(attrs);
} else if(raw.equals("request")){
parseRequest(attrs);
}
}
/**
* smtp僞僌傪夝愅偟傑偡丅
*/
private void parseSMTP(Attributes attrs){
String host = attrs.getValue("host");
String port = attrs.getValue("port");
setSmtpHost(host);
setSmtpPort(port);
}
/**
* request僞僌傪夝愅偟傑偡丅
*/
private void parseRequest(Attributes attrs){
String encode = attrs.getValue("encode");
//String mpMaxBytes = attrs.getValue("mpart-max");
setRequestEncode(encode);
//setMpMaxBytes(mpMaxBytes);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?