7187f34d0bea23c841369ea9a8ad8ca3fd21b12f.svn-base 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. package com.sysmodel.listmodel.xmlmanager;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import javax.xml.parsers.DocumentBuilder;
  5. import javax.xml.parsers.DocumentBuilderFactory;
  6. import org.apache.commons.logging.Log;
  7. import org.apache.commons.logging.LogFactory;
  8. import org.w3c.dom.CDATASection;
  9. import org.w3c.dom.Document;
  10. import org.w3c.dom.Element;
  11. import com.sysmodel.XFormModelImpl;
  12. import com.sysmodel.listmodel.xmlmodel.able.ActionButton;
  13. import com.sysmodel.listmodel.xmlmodel.able.ListHead;
  14. import com.sysmodel.listmodel.xmlmodel.able.QueryList;
  15. import com.sysmodel.listmodel.xmlmodel.impl.ActionButtonImpl;
  16. import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
  17. import com.sysmodel.listmodel.xmlmodel.impl.ListFieldImpl;
  18. import com.sysmodel.listmodel.xmlmodel.impl.PramFieldImpl;
  19. import com.sysmodel.listmodel.xmlmodel.impl.QueryFieldImpl;
  20. import com.sysmodel.xformmodel.able.Validate;
  21. import com.sysmodel.xformmodel.importcontrol.DateControl;
  22. import com.sysmodel.xformmodel.importcontrol.SelectControl;
  23. import com.sysmodel.xformmodel.importcontrol.TextControl;
  24. import com.sysmodel.xformmodel.importcontrol.TreeControl;
  25. import com.toolkit.file.FileOperate;
  26. public class ListXMLSave{
  27. private Log log = LogFactory.getLog(ListXMLSave.class);
  28. /**
  29. * 根据文件路径,创建 pagelist xml文件
  30. *
  31. * @param filePath
  32. * 文件路径
  33. * @return
  34. */
  35. public boolean saveToXMLFile(String filePath) {
  36. boolean bsuccess = true;
  37. log.info("PageList.xml filePath = " + filePath);
  38. try {
  39. DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance();
  40. DocumentBuilder builder = domfactory.newDocumentBuilder();
  41. Document doc = builder.newDocument();
  42. createXMLDoc(doc);
  43. FileOperate FileOperate = new FileOperate();
  44. bsuccess = FileOperate.saveDocumentFromDomToXMLFile(doc, filePath);
  45. } catch (Exception e) {
  46. bsuccess = false;
  47. log.error(e);
  48. }
  49. return bsuccess;
  50. }
  51. /*
  52. * public boolean saveToXMLFile(String filePath){ boolean bsuccess = true;
  53. * log.info("filePath = " + filePath); try{ File savefile = new
  54. * File(filePath); DocumentBuilderFactory domfactory =
  55. * DocumentBuilderFactory.newInstance(); DocumentBuilder builder =
  56. * domfactory.newDocumentBuilder(); Document doc = builder.newDocument();
  57. * createXMLDoc(doc); DOMSource source = new
  58. * DOMSource(doc.getDocumentElement()); StreamResult result=new
  59. * StreamResult(new FileOutputStream(savefile, false)); TransformerFactory
  60. * transformerfactory = TransformerFactory.newInstance(); Transformer
  61. * transformer = transformerfactory.newTransformer();
  62. * transformer.transform(source,result); }catch(Exception e){ bsuccess =
  63. * false; log.error(e); } return bsuccess; }
  64. */
  65. /**
  66. * 创建Document对象
  67. */
  68. private void createXMLDoc(Document doc) {
  69. Element root = doc.createElement("pageList");
  70. createFormList(root, doc);
  71. doc.appendChild(root);
  72. }
  73. /**
  74. * 创建FormList节点
  75. *
  76. * @param root
  77. * @param doc
  78. */
  79. private void createFormList(Element root, Document doc) {
  80. // Element root = doc.getDocumentElement();
  81. List<FormListImpl> listFormList = XFormModelImpl.getInstance().getFormLists();
  82. for (int i = 0; i < listFormList.size(); i++) {
  83. FormListImpl formlist = listFormList.get(i);
  84. Element formListEle = doc.createElement("FormList");
  85. formListEle.setAttribute("listid", formlist.getListid());
  86. formListEle.setAttribute("listWidth", formlist.getListWidth());
  87. formListEle.setAttribute("refreshTime", formlist.getRefreshTime());
  88. formListEle.setAttribute("description", formlist.getDescription() == null ? ""
  89. : formlist.getDescription());
  90. formListEle.setAttribute("type", formlist.getType() == null ? "" : formlist.getType());
  91. /**
  92. * 创建include CDATA
  93. */
  94. if (formlist.getInclude().length() > 0) {
  95. CDATASection includeDATA = doc.createCDATASection(formlist.getInclude());
  96. Element include = doc.createElement("include");
  97. include.appendChild(includeDATA);
  98. formListEle.appendChild(include);
  99. }
  100. /**
  101. * 创建excurl CDATA
  102. */
  103. if (formlist.getExcurl().length() > 0) {
  104. CDATASection ExcurlDATA = doc.createCDATASection(formlist.getExcurl());
  105. Element Excurl = doc.createElement("excurl");
  106. Excurl.appendChild(ExcurlDATA);
  107. formListEle.appendChild(Excurl);
  108. }
  109. /**
  110. * 创建script CDATA
  111. */
  112. if (formlist.getScript().length() > 0) {
  113. CDATASection scriptDATA = doc.createCDATASection(formlist.getScript());
  114. Element script = doc.createElement("script");
  115. script.appendChild(scriptDATA);
  116. formListEle.appendChild(script);
  117. }
  118. // 创建listAction节点
  119. createlistAction(formListEle, formlist.getListAction(), doc);
  120. // 创建listHead节点
  121. createListHead(formListEle, formlist.getListHead(), doc);
  122. // 创建queryFields节点
  123. createQueryFields(formListEle, formlist.getQueryFields(), doc);
  124. // 创建qrueyTables节点
  125. createQrueyTables(formListEle, formlist.getQueryTables(), doc);
  126. // 创建qrueyConditions节点
  127. createQrueyConditions(formListEle, formlist.getQueryConditions(), doc);
  128. // 创建pramField节点
  129. createpramField(formListEle, formlist.getlistPramField(), doc);
  130. // 创建queryList节点
  131. creatQqueryList(formListEle, formlist.getQueryList(), doc);
  132. root.appendChild(formListEle);
  133. }
  134. }
  135. private void createlistAction(Element Element, ArrayList<ActionButtonImpl> actlist, Document doc) {
  136. Element listaction = doc.createElement("listAction");
  137. for (int i = 0; i < actlist.size(); i++) {
  138. ActionButton actionButton = actlist.get(i);
  139. Element buttonElement = doc.createElement("actionButton");
  140. buttonElement.setAttribute("buttonName", actionButton.getButtonName());
  141. buttonElement.setAttribute("buttonType", actionButton.getButtonType());
  142. buttonElement.setAttribute("value", actionButton.getValue());
  143. buttonElement.setAttribute("url", actionButton.getUrl());
  144. buttonElement.setAttribute("target", actionButton.getTarget());
  145. buttonElement.setAttribute("formWith", actionButton.getFormWith());
  146. buttonElement.setAttribute("formHeight", actionButton.getFormHeight());
  147. listaction.appendChild(buttonElement);
  148. }
  149. Element.appendChild(listaction);
  150. }
  151. private void createListHead(Element formListEle, ListHead listhead, Document doc) {
  152. Element listHead = doc.createElement("listHead");
  153. listHead.setAttribute("title", listhead.getTitle());
  154. listHead.setAttribute("titleWidth", listhead.getTitleWidth());
  155. formListEle.appendChild(listHead);
  156. }
  157. private void createQueryFields(Element formListEle, ArrayList<QueryFieldImpl> actlist,
  158. Document doc) {
  159. Element queryFields = doc.createElement("queryFields");
  160. for (int i = 0; i < actlist.size(); i++) {
  161. QueryFieldImpl queryfield = (QueryFieldImpl) actlist.get(i);
  162. Element queryFieldElement = doc.createElement("queryField");
  163. queryFieldElement.setAttribute("classid", queryfield.getClassid() + "");
  164. queryFieldElement.setAttribute("dataName", queryfield.getDataName());
  165. queryFieldElement.setAttribute("label", queryfield.getLabel());
  166. queryFieldElement.setAttribute("operator", queryfield.getOperator());
  167. queryFieldElement.setAttribute("controlType", queryfield.getControlType());
  168. controlTypeField(queryFieldElement, queryfield, doc);
  169. creatvalidates(queryFieldElement, doc, queryfield);
  170. queryFields.appendChild(queryFieldElement);
  171. }
  172. formListEle.appendChild(queryFields);
  173. }
  174. private void creatvalidates(Element pagereportField, Document doc, QueryFieldImpl queryfield) {
  175. Element validatesField = doc.createElement("validates");
  176. Validate Validate = queryfield.getValidate();
  177. if (Validate.isNeed()) {
  178. Element validateNode = doc.createElement("validate");
  179. validateNode.setAttribute("type", "need");
  180. validatesField.appendChild(validateNode);
  181. }
  182. if (Validate.isTrim()) {
  183. Element validateNode = doc.createElement("validate");
  184. validateNode.setAttribute("type", "trim");
  185. validatesField.appendChild(validateNode);
  186. }
  187. if (!Validate.getMaxLength().equals("")) {
  188. Element validateNode = doc.createElement("validate");
  189. validateNode.setAttribute("type", "length");
  190. validateNode.setAttribute("maxLength", Validate.getMaxLength());
  191. validatesField.appendChild(validateNode);
  192. }
  193. if (!Validate.getRegxValue().equals("")) {
  194. Element validateNode = doc.createElement("validate");
  195. validateNode.setAttribute("type", "regx");
  196. validateNode.setAttribute("regxValue", Validate.getRegxValue());
  197. validatesField.appendChild(validateNode);
  198. }
  199. if (!Validate.getDojoType().equals("")) {
  200. Element validateNode = doc.createElement("validate");
  201. validateNode.setAttribute("type", "dojoType");
  202. validateNode.setAttribute("typeValue", Validate.getDojoType());
  203. validatesField.appendChild(validateNode);
  204. }
  205. if (!Validate.getMaxValue().equals("") || !Validate.getMinValue().equals("")) {
  206. Element validateNode = doc.createElement("validate");
  207. validateNode.setAttribute("type", "range");
  208. validateNode.setAttribute("maxValue", Validate.getMaxValue());
  209. validateNode.setAttribute("minValue", Validate.getMinValue());
  210. validatesField.appendChild(validateNode);
  211. }
  212. if (!Validate.getInvalidMessage().equals("") || !Validate.getPromptMessage().equals("")) {
  213. Element validateNode = doc.createElement("validate");
  214. validateNode.setAttribute("type", "message");
  215. validateNode.setAttribute("promptMessage", Validate.getPromptMessage());
  216. validateNode.setAttribute("invalidMessage", Validate.getInvalidMessage());
  217. validatesField.appendChild(validateNode);
  218. }
  219. pagereportField.appendChild(validatesField);
  220. }
  221. private void creatQqueryList(Element formListEle, QueryList queryList, Document doc) {
  222. Element queryListEle = doc.createElement("queryList");
  223. queryListEle.setAttribute("haveOrder", new Boolean(queryList.isHaveOrder()).toString());
  224. queryListEle.setAttribute("pageSize", queryList.getPageSize() + "");
  225. queryListEle.setAttribute("tableList", queryList.getTableList());
  226. queryListEle.setAttribute("condition", queryList.getCondition());
  227. queryListEle.setAttribute("orderby", queryList.getOrderBy());
  228. queryListEle.setAttribute("isCheckbox", new Boolean(queryList.isCheckbox()).toString());
  229. creatListField(queryListEle, queryList.getlistFields(), doc);
  230. formListEle.appendChild(queryListEle);
  231. }
  232. private void creatListField(Element queryListEle, ArrayList<ListFieldImpl> arrayList,
  233. Document doc) {
  234. for (int i = 0; i < arrayList.size(); i++) {
  235. ListFieldImpl listField = arrayList.get(i);
  236. Element listFieldElement = doc.createElement("listField");
  237. listFieldElement.setAttribute("classid", listField.getClassid() + "");
  238. listFieldElement.setAttribute("showType", listField.getShowType());
  239. listFieldElement.setAttribute("width", listField.getWidth());
  240. listFieldElement.setAttribute("dataName", listField.getDataName());
  241. listFieldElement.setAttribute("label", listField.getLabel());
  242. listFieldElement.setAttribute("url", listField.getUrl());
  243. listFieldElement.setAttribute("target", listField.getTarget());
  244. listFieldElement.setAttribute("image", listField.getImage());
  245. listFieldElement.setAttribute("showTxt", listField.getShowTxt());
  246. listFieldElement.setAttribute("formWith", listField.getFormWith());
  247. listFieldElement.setAttribute("formHeight", listField.getFormHeight());
  248. listFieldElement.setAttribute("remark", listField.getRemark());
  249. queryListEle.appendChild(listFieldElement);
  250. }
  251. }
  252. private void createpramField(Element Element, ArrayList<PramFieldImpl> actlist, Document doc) {
  253. Element pramField = doc.createElement("pramField");
  254. for (int i = 0; i < actlist.size(); i++) {
  255. PramFieldImpl pram = actlist.get(i);
  256. Element pramElement = doc.createElement("pram");
  257. pramElement.setAttribute("classid", pram.getClassid() + "");
  258. pramElement.setAttribute("name", pram.getName());
  259. pramElement.setAttribute("valuefrom", pram.getValuefrom());
  260. pramElement.setAttribute("isInput", new Boolean(pram.isInput()).toString());
  261. pramField.appendChild(pramElement);
  262. }
  263. Element.appendChild(pramField);
  264. }
  265. private void createQrueyConditions(Element Element, ArrayList<String> actlist, Document doc) {
  266. Element qrueyConditions = doc.createElement("qrueyConditions");
  267. for (int i = 0; i < actlist.size(); i++) {
  268. String value = actlist.get(i);
  269. Element conditionElement = doc.createElement("condition");
  270. conditionElement.setAttribute("value", value);
  271. qrueyConditions.appendChild(conditionElement);
  272. }
  273. Element.appendChild(qrueyConditions);
  274. }
  275. private void createQrueyTables(Element Element, ArrayList<String> actlist, Document doc) {
  276. Element qrueyTables = doc.createElement("qrueyTables");
  277. for (int i = 0; i < actlist.size(); i++) {
  278. String classid = actlist.get(i);
  279. Element tableElement = doc.createElement("table");
  280. tableElement.setAttribute("classid", classid);
  281. qrueyTables.appendChild(tableElement);
  282. }
  283. Element.appendChild(qrueyTables);
  284. }
  285. private void controlTypeField(Element queryFieldElement, QueryFieldImpl queryfield, Document doc) {
  286. String controlType = queryfield.getControlType() == null ? "" : queryfield.getControlType();
  287. if (!controlType.equals("")) {
  288. Element controlField = doc.createElement(controlType);
  289. if (controlType.equals("text")) {
  290. TextControl TextControl = (TextControl) queryfield.getControl();
  291. controlField.setAttribute("size",
  292. TextControl.getSize() == null ? "" : TextControl.getSize());
  293. controlField.setAttribute("readonly",
  294. new Boolean(TextControl.isReadOnly()).toString());
  295. queryFieldElement.appendChild(controlField);
  296. } else if (controlType.equals("select")) {
  297. SelectControl SelectControl = (SelectControl) queryfield.getControl();
  298. controlField.setAttribute("constantName", SelectControl.getConstantName());
  299. queryFieldElement.appendChild(controlField);
  300. } else if (controlType.equals("tree")) {
  301. TreeControl TreeControl = (TreeControl) queryfield.getControl();
  302. controlField.setAttribute("size", TreeControl.getSize());
  303. controlField.setAttribute("type", TreeControl.getType());
  304. controlField.setAttribute("referenceTable", TreeControl.getReferenceTable());
  305. controlField.setAttribute("storeCode", TreeControl.getStoreCode());
  306. controlField.setAttribute("displayName", TreeControl.getDisplayName());
  307. controlField.setAttribute("parentCode", TreeControl.getParentCode());
  308. controlField.setAttribute("customDefine", TreeControl.getCustomDefine());
  309. controlField.setAttribute("condition", TreeControl.getCondition());
  310. controlField.setAttribute("order", TreeControl.getOrder());
  311. queryFieldElement.appendChild(controlField);
  312. }
  313. if (controlType.equals("date")) {
  314. DateControl DateControl = (DateControl) queryfield.getControl();
  315. controlField.setAttribute("size", DateControl.getSize());
  316. controlField.setAttribute("format", DateControl.getFormat());
  317. queryFieldElement.appendChild(controlField);
  318. }
  319. }
  320. }
  321. }