⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlconfigfactory.java

📁 如果遇到MD5加密文件
💻 JAVA
字号:
package com.easyjf.web.config;
import org.apache.log4j.Logger;
import org.dom4j.*;
import org.dom4j.io.*;

import com.easyjf.web.FormConfig;
import com.easyjf.web.FormProperty;
import com.easyjf.web.Globals;
import com.easyjf.web.Module;
import com.easyjf.web.Page;


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;
/**
*
* <p>Title:XML格式配置文件信息处理</p>
* <p>Description:读取XML格式的EasyJWeb框架配置文件信息;</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: www.easyjf.com</p>
* @author 蔡世友
* @version 1.0
*/

public class XMLConfigFactory implements IConfigFactory {	
private Document doc;
private static final Logger logger = (Logger) Logger.getLogger(IConfigFactory.class.getName());
public XMLConfigFactory()
{	
	try{
		File file=new File(Globals.CONFIG_FILE_FULL_PATH);		
		System.out.println(Globals.CONFIG_FILE_FULL_PATH);
		if(file.exists()){
		FileInputStream in=new FileInputStream(file);
		SAXReader reader = new SAXReader();	
		doc=reader.read(in);
		}
		else
		{
			logger.warn("无法找到配置文件"+Globals.CONFIG_FILE_FULL_PATH+".EasyJWEB将自动使用默认的路径处理Action!");
		}
	}
	catch(Exception e)
	{
		logger.warn("配置文件错误!"+e);
	}	
}
public XMLConfigFactory(InputStream in)
{	
	try{		
		SAXReader reader = new SAXReader();	
		doc=reader.read(in);		
	}
	catch(Exception e)
	{
		logger.warn("配置文件错误!"+e);
	}	
	
}
public void initForm(Map forms)
	{
	if(doc==null)return;
	List nodes=doc.selectNodes("/easyjf-web/forms/form");	
	for(int i=0;i<nodes.size();i++)
	{
		Element e=(Element)nodes.get(i);
		FormConfig fc=new FormConfig();
		fc.setAlertType(e.attributeValue("alertType"));
		fc.setBean(e.attributeValue("bean"));
		fc.setClientValidate(e.attributeValue("clientValidate"));
		fc.setName(e.attributeValue("name"));
		fc.setServerValidate(e.attributeValue("serverValidate"));
		String events=e.attributeValue("event");
		if(events!=null && (!events.equals("")))
		{
			String[] s=events.split(",");				
		    if(s!=null)
		    {
		    	List event=new ArrayList();
		    	for(int t=0;t<s.length;t++)
		    	{
		    		if(!s[t].equals(""))event.add(s[t]);
		    	}
		    	fc.setEvent(event);	
		    }
		}		
		List lPage=e.selectNodes("property");
		Map pages=new HashMap();
		for(int j=0;j<lPage.size();j++)
		{
			
			Element p=(Element)lPage.get(j);		
			FormProperty prop=new FormProperty();
			prop.setInitial(p.attributeValue("initial"));
			prop.setName(p.attributeValue("name"));
			prop.setNotNull(p.attributeValue("notNull"));
			prop.setSize(p.attributeValue("size"));
			prop.setType(p.attributeValue("type"));
			events=p.attributeValue("event");
			if(events!=null && (!events.equals("")))
			{
				String[] s=events.split(",");				
			    if(s!=null)
			    {
			    	List event=new ArrayList();
			    	for(int t=0;t<s.length;t++)
			    	{
			    		if(!s[t].equals(""))event.add(s[t]);
			    	}
			    	prop.setEvent(event);	
			    }
			}
			pages.put(prop.getName(),prop);			
		}
		fc.setPropertys(pages);
		forms.put(fc.getName(),fc);			
	}

	}
public void initModule(Map modules)
	{
	if(doc==null)return;
	List nodes=doc.selectNodes("/easyjf-web/modules/module");
	for(int i=0;i<nodes.size();i++)
	{
		Element e=(Element)nodes.get(i);
		Module mc=new Module();
		mc.setAction(e.attributeValue("action"));
		mc.setDefaultPage(e.attributeValue("defaultPage"));
		mc.setForm(e.attributeValue("form"));		
		mc.setPath(e.attributeValue("path"));		
		List lPage=e.selectNodes("page");
		Map pages=new HashMap();
		for(int j=0;j<lPage.size();j++)
		{			
			Element p=(Element)lPage.get(j);			
			Page page=new Page();
			page.setName(p.attributeValue("name"));
			if(mc.getDefaultPage()==null || mc.getDefaultPage().equals(""))
			{
				mc.setDefaultPage(page.getName());
			}
			page.setType(p.attributeValue("type"));
			page.setUrl(p.attributeValue("url"));	
			pages.put(page.getName(),page);			
		}
	
		mc.setPages(pages);
		//System.out.println(mc.getPath());
		modules.put(mc.getPath(),mc);
			
	}	
	}
public void initPage(Map pages)
{
if(doc==null)return;
List nodes=doc.selectNodes("/easyjf-web/pages/page");
for(int i=0;i<nodes.size();i++)
{
	Element e=(Element)nodes.get(i);
	Page page=new Page();
	page.setName(e.attributeValue("name"));
	page.setType(e.attributeValue("type"));
	page.setUrl(e.attributeValue("url"));	
	pages.put(page.getName(),page);	
}	
}
public Map initOther()
{	
	if(doc==null)return null;
	Node node=doc.selectSingleNode("/easyjf-web/frame-setting/template-base");
	Map result=new HashMap();
	if(node!=null)result.put("TemplateBasePath",node.getText());
	List appList=doc.selectNodes("/easyjf-web/frame-setting/init-app/app-class");
	List list=new ArrayList();
	if(appList!=null)
	{
		for(int i=0;i<appList.size();i++)
		{
			list.add(((Node)appList.get(i)).getText());
		}
	}
	result.put("initApp",list);	
	list=doc.selectNodes("/easyjf-web/frame-setting/property");
	if(list!=null)
	{
		for(int i=0;i<list.size();i++)
		{
			Element el=(Element)list.get(i);			
			result.put(el.attributeValue("name"),el.getText());
		}
	}
	return result;
}
public Document parse(String  fileName) throws DocumentException {
	    SAXReader reader = new SAXReader();	    
	    File file=new File(fileName);
	    Document document = file.exists()?reader.read(fileName):null;
	    return document;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -