📄 xmlparser.java
字号:
/**
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.jdon.controller.config;
import java.io.InputStream;
import java.util.LinkedHashMap;
import java.util.Map;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import com.jdon.util.Debug;
import com.jdon.util.FileLocator;
/**
* by Jdom parse the jdonframework.xml
* dom4j is faster than jdom, but this parser only be runned for
* one time ,so parsing speed is not important.
*
* <p>@author <a href="mailto:banqiao@jdon.com">banq</a></p>
* <p>@version JdonFramework 2005 v1.0</p>
*/
public abstract class XmlParser {
private final static String module = XmlParser.class.getName();
private FileLocator fileLocator = new FileLocator();
private Document doc;
public Map load(String configFileName) {
Map mps = new LinkedHashMap();
try {
if (configFileName == null)
return mps;
if (doc == null){
buildDocument(configFileName);
}
if (doc == null)
return mps;
Element root = doc.getRootElement();
//Iterator iter = root.getChildren().iterator();
//while(iter.hasNext()){
//Debug.logVerbose(" test: " + iter.next(), module);
//}
parse(root, mps);
Debug.logVerbose("<!-- config load finished -->", module);
} catch (Exception ex) {
Debug.logError("configure FileName: " + configFileName + " parsed error: " + ex, module);
}
return mps;
}
private void buildDocument(String configFileName) {
Debug.logVerbose(" locate configure file :" + configFileName, module);
try {
InputStream xmlStream = fileLocator.getConfPathXmlStream(configFileName);
if (xmlStream == null){
Debug.logVerbose("can't locate file:" + configFileName, module);
return;
}else{
Debug.logVerbose(" configure file found :" + xmlStream, module);
}
SAXBuilder builder = new SAXBuilder();
builder.setEntityResolver(new DTDEntityResolver());
this.doc = builder.build(xmlStream);
Debug.logVerbose(" got mapping file ", module);
} catch (JDOMException e) {
Debug.logError(" JDOMException error: " + e, module);
}
}
public abstract void parse(Element root, Map results) throws Exception;
public Document getDoc() {
return doc;
}
public void setDoc(Document doc) {
this.doc = doc;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -