读取xml文件类二

public static void getXMLInfo(String filelocation){
		String filename=BeifengMVCXMLFactory.class.getResource("/"+filelocation).getFile();
		File file=new File(filename);
		SAXReader reader=new SAXReader();
		Document doc=null;
		Package pack=null;
		BeifengMvc mvc=new BeifengMvc();
		List<IncludeFile> includefilelist=null;
		List<InterceptorInfo> allinterceptor=null;
		Map<String, InterceptorStack> stackmap=null;
		Map<String, Action> actionmap=null;
		try {
			doc=reader.read(file);
			Element root=doc.getRootElement();
			Element packagee=root.element("package");
			pack=new Package();
			pack.setPackagename(packagee.attributeValue("name"));
			pack.setNamespace(packagee.attributeValue("namespace"));
			pack.setExtendsfile(packagee.attributeValue("extends"));
			List<Element> list=packagee.elements();
			for(Element e:list){
				if(e.getName().equals("include")){
					if(null==includefilelist){
						includefilelist=new ArrayList<IncludeFile>();
					}
					IncludeFile include=new IncludeFile();
					include.setFile(e.attributeValue("file"));
					includefilelist.add(include);
				}else if(e.getName().equals("interceptor")){
					if(null==allinterceptor){
						allinterceptor=new ArrayList<InterceptorInfo>();
					}
					InterceptorInfo info=new InterceptorInfo();
					info.setInterceptorname(e.attributeValue("name"));
					info.setInterceptorclass(e.attributeValue("class"));
					//获得拦截器内的标签,从而配置Result属性
					List<Element> resultlist=e.elements();
					if(resultlist!=null){
						Map<String, Result> resultmap=null;
						List<String> notinterfunctionlist=null;
						Map<String,String> parammap=null;
						for(Element resulte:resultlist){
							if(resulte.getName().equals("result")){
								if(null==resultmap){
									resultmap=new HashMap<String, Result>();
								}
								Result r=new Result();
								r.setResultname(resulte.attributeValue("name"));
								Attribute type=resulte.attribute("type");
								if(type!=null){
									r.setResulttype(type.getValue());
								}
								r.setResultjsp(resulte.getText());
								resultmap.put(r.getResultname(), r);
							}else if(resulte.getName().equals("notinterfunction")){
								if(null==notinterfunctionlist){
									notinterfunctionlist=new ArrayList<String>();
								}
								notinterfunctionlist.add(resulte.attributeValue("name"));
							}else if(resulte.getName().equals("param")){
								if(null==parammap){
									parammap=new HashMap<String, String>();
								}
								parammap.put(resulte.attributeValue("name"), resulte.getText());
							}
						}
						info.setResultmap(resultmap);
						info.setNotinterfunctionlist(notinterfunctionlist);
						info.setParammap(parammap);
					}
					allinterceptor.add(info);
				}

 

你可能感兴趣的:(读取xml)