ConfigerAction.java
上传用户:zhc3n3
上传日期:2022-07-30
资源大小:2750k
文件大小:2k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.t11.web.XML;
- import java.io.File;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.dom4j.Document;
- import org.dom4j.Element;
- import org.dom4j.io.SAXReader;
- import com.t11.web.ActionForward;
- import com.t11.web.ActionMapping;
- public class ConfigerAction {
- Map<String, ActionMapping> actionMappings = new HashMap<String, ActionMapping>();
- public ConfigerAction(String fileName) {
- SAXReader reader = new SAXReader();
- try {
- Document doc = reader.read(new File(fileName));
- // 调用
- parseConfig(doc);
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public void parseConfig(Document doc) {
- ActionMapping actionMapping = null;
- List<Element> els = doc.selectNodes("//action-mappings/action");
- for (Element element : els) {
- String path = element.attributeValue("path");
- String type = element.attributeValue("type");
- String redirect = element.attributeValue("redirect");
- actionMapping = new ActionMapping();
- actionMapping.setPath(path);
- actionMapping.setType(type);
- actionMapping.setRedirect(Boolean.parseBoolean(redirect));
- List<Element> es = element.elements("forward");
- Map<String, ActionForward> forward = new HashMap<String, ActionForward>();
- for (Element element2 : es) {
- String fname = element2.attributeValue("name");
- String fpathe = element2.attributeValue("path");
- forward.put(fname, new ActionForward(fname,fpathe));
- }
- actionMapping.setForward(forward);
- actionMappings.put(actionMapping.getPath(), actionMapping);
- }
- }
- public ActionMapping findActionMapping(String path){
- System.out.println(actionMappings.size()+" "+path);
- return actionMappings.get(path);
- }
- }