123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- package com.sysmodel.xformmodel;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.Map;
- import javax.xml.parsers.DocumentBuilder;
- import javax.xml.parsers.DocumentBuilderFactory;
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import org.w3c.dom.NodeList;
- import com.sysmodel.XFormModelImpl;
- import com.sysmodel.xformmodel.impl.DojoInputTypeImpl;
- import com.sysmodel.xformmodel.impl.JsFunctionImpl;
- import com.sysmodel.xformmodel.impl.RegExpImpl;
- public class ResouceXMLLoader{
- private Log log = LogFactory.getLog(ResouceXMLLoader.class);
- Map<String, String> pageCssMap = new HashMap<String, String>();
- public boolean readResource(String filePath) {
- File xmlfile = new File(filePath);
- if (!xmlfile.exists()) {
- log.error("Resoucefile: " + filePath + " not exist");
- return false;
- }
- DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance();
- try {
- DocumentBuilder builder = domfactory.newDocumentBuilder();
- Document document = builder.parse(xmlfile);
- // pageCss
- NodeList pageCss = document.getElementsByTagName("pageCss");
- readPageCsses(pageCss);
- // regExp
- NodeList regExp = document.getElementsByTagName("regExp");
- readRegExp(regExp);
- // jsFunction
- NodeList jsFunction = document.getElementsByTagName("jsFunction");
- readJsFunction(jsFunction);
- // jsFunction
- NodeList dojoInuptTypes = document.getElementsByTagName("dojoType");
- readDojoInuptTypes(dojoInuptTypes);
- } catch (Exception e) {
- log.error("load PageResouce error: ", e);
- }
- return true;
- }
- private void readPageCsses(NodeList pageCss) {
- for (int i = 0; i < pageCss.getLength(); i++) {
- Element element = (Element) pageCss.item(i);
- pageCssMap.put(element.getAttribute("code"), element.getAttribute("value"));
- }
- XFormModelImpl.getInstance().setPageCssMap(pageCssMap);
- }
- private void readRegExp(NodeList regExp) {
- ArrayList<RegExpImpl> arr = new ArrayList<RegExpImpl>();
- for (int i = 0; i < regExp.getLength(); i++) {
- RegExpImpl RegExpImpl = new RegExpImpl();
- Element element = (Element) regExp.item(i);
- RegExpImpl.setCode(element.getAttribute("code"));
- RegExpImpl.setDescription(element.getAttribute("description"));
- RegExpImpl.setName(element.getAttribute("name"));
- RegExpImpl.setValue(element.getAttribute("value"));
- arr.add(RegExpImpl);
- }
- XFormModelImpl.getInstance().setRegExps(arr);
- }
- private void readJsFunction(NodeList jsFunction) {
- ArrayList<JsFunctionImpl> arr = new ArrayList<JsFunctionImpl>();
- for (int i = 0; i < jsFunction.getLength(); i++) {
- JsFunctionImpl JsFunctionImpl = new JsFunctionImpl();
- Element element = (Element) jsFunction.item(i);
- JsFunctionImpl.setCode(element.getAttribute("code"));
- JsFunctionImpl.setDescription(element.getAttribute("description"));
- JsFunctionImpl.setName(element.getAttribute("name"));
- JsFunctionImpl.setValue(element.getAttribute("value"));
- arr.add(JsFunctionImpl);
- }
- XFormModelImpl.getInstance().setJsFunctions(arr);
- }
- private void readDojoInuptTypes(NodeList dojoInuptTypes) {
- ArrayList<DojoInputTypeImpl> arr = new ArrayList<DojoInputTypeImpl>();
- for (int i = 0; i < dojoInuptTypes.getLength(); i++) {
- DojoInputTypeImpl DojoInputType = new DojoInputTypeImpl();
- Element element = (Element) dojoInuptTypes.item(i);
- DojoInputType.setCode(element.getAttribute("code"));
- DojoInputType.setName(element.getAttribute("name"));
- DojoInputType.setValue(element.getAttribute("value"));
- DojoInputType.setType(element.getAttribute("type"));
- arr.add(DojoInputType);
- }
- XFormModelImpl.getInstance().setDojoInuptTypes(arr);
- }
- }
|