123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- package com.sysmodel.listmodel.xmlmanager;
- import java.util.ArrayList;
- import java.util.List;
- 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.CDATASection;
- import org.w3c.dom.Document;
- import org.w3c.dom.Element;
- import com.sysmodel.XFormModelImpl;
- import com.sysmodel.listmodel.xmlmodel.able.ActionButton;
- import com.sysmodel.listmodel.xmlmodel.able.ListHead;
- import com.sysmodel.listmodel.xmlmodel.able.QueryList;
- import com.sysmodel.listmodel.xmlmodel.impl.ActionButtonImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.FormListImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.ListFieldImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.PramFieldImpl;
- import com.sysmodel.listmodel.xmlmodel.impl.QueryFieldImpl;
- import com.sysmodel.xformmodel.able.Validate;
- import com.sysmodel.xformmodel.importcontrol.DateControl;
- import com.sysmodel.xformmodel.importcontrol.SelectControl;
- import com.sysmodel.xformmodel.importcontrol.TextControl;
- import com.sysmodel.xformmodel.importcontrol.TreeControl;
- import com.toolkit.file.FileOperate;
- public class ListXMLSave{
- private Log log = LogFactory.getLog(ListXMLSave.class);
- /**
- * 根据文件路径,创建 pagelist xml文件
- *
- * @param filePath
- * 文件路径
- * @return
- */
- public boolean saveToXMLFile(String filePath) {
- boolean bsuccess = true;
- log.info("PageList.xml filePath = " + filePath);
- try {
- DocumentBuilderFactory domfactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = domfactory.newDocumentBuilder();
- Document doc = builder.newDocument();
- createXMLDoc(doc);
- FileOperate FileOperate = new FileOperate();
- bsuccess = FileOperate.saveDocumentFromDomToXMLFile(doc, filePath);
- } catch (Exception e) {
- bsuccess = false;
- log.error(e);
- }
- return bsuccess;
- }
- /*
- * public boolean saveToXMLFile(String filePath){ boolean bsuccess = true;
- * log.info("filePath = " + filePath); try{ File savefile = new
- * File(filePath); DocumentBuilderFactory domfactory =
- * DocumentBuilderFactory.newInstance(); DocumentBuilder builder =
- * domfactory.newDocumentBuilder(); Document doc = builder.newDocument();
- * createXMLDoc(doc); DOMSource source = new
- * DOMSource(doc.getDocumentElement()); StreamResult result=new
- * StreamResult(new FileOutputStream(savefile, false)); TransformerFactory
- * transformerfactory = TransformerFactory.newInstance(); Transformer
- * transformer = transformerfactory.newTransformer();
- * transformer.transform(source,result); }catch(Exception e){ bsuccess =
- * false; log.error(e); } return bsuccess; }
- */
- /**
- * 创建Document对象
- */
- private void createXMLDoc(Document doc) {
- Element root = doc.createElement("pageList");
- createFormList(root, doc);
- doc.appendChild(root);
- }
- /**
- * 创建FormList节点
- *
- * @param root
- * @param doc
- */
- private void createFormList(Element root, Document doc) {
- // Element root = doc.getDocumentElement();
- List<FormListImpl> listFormList = XFormModelImpl.getInstance().getFormLists();
- for (int i = 0; i < listFormList.size(); i++) {
- FormListImpl formlist = listFormList.get(i);
- Element formListEle = doc.createElement("FormList");
- formListEle.setAttribute("listid", formlist.getListid());
- formListEle.setAttribute("listWidth", formlist.getListWidth());
- formListEle.setAttribute("refreshTime", formlist.getRefreshTime());
- formListEle.setAttribute("description", formlist.getDescription() == null ? ""
- : formlist.getDescription());
- formListEle.setAttribute("type", formlist.getType() == null ? "" : formlist.getType());
- /**
- * 创建include CDATA
- */
- if (formlist.getInclude().length() > 0) {
- CDATASection includeDATA = doc.createCDATASection(formlist.getInclude());
- Element include = doc.createElement("include");
- include.appendChild(includeDATA);
- formListEle.appendChild(include);
- }
- /**
- * 创建excurl CDATA
- */
- if (formlist.getExcurl().length() > 0) {
- CDATASection ExcurlDATA = doc.createCDATASection(formlist.getExcurl());
- Element Excurl = doc.createElement("excurl");
- Excurl.appendChild(ExcurlDATA);
- formListEle.appendChild(Excurl);
- }
- /**
- * 创建script CDATA
- */
- if (formlist.getScript().length() > 0) {
- CDATASection scriptDATA = doc.createCDATASection(formlist.getScript());
- Element script = doc.createElement("script");
- script.appendChild(scriptDATA);
- formListEle.appendChild(script);
- }
- // 创建listAction节点
- createlistAction(formListEle, formlist.getListAction(), doc);
- // 创建listHead节点
- createListHead(formListEle, formlist.getListHead(), doc);
- // 创建queryFields节点
- createQueryFields(formListEle, formlist.getQueryFields(), doc);
- // 创建qrueyTables节点
- createQrueyTables(formListEle, formlist.getQueryTables(), doc);
- // 创建qrueyConditions节点
- createQrueyConditions(formListEle, formlist.getQueryConditions(), doc);
- // 创建pramField节点
- createpramField(formListEle, formlist.getlistPramField(), doc);
- // 创建queryList节点
- creatQqueryList(formListEle, formlist.getQueryList(), doc);
- root.appendChild(formListEle);
- }
- }
- private void createlistAction(Element Element, ArrayList<ActionButtonImpl> actlist, Document doc) {
- Element listaction = doc.createElement("listAction");
- for (int i = 0; i < actlist.size(); i++) {
- ActionButton actionButton = actlist.get(i);
- Element buttonElement = doc.createElement("actionButton");
- buttonElement.setAttribute("buttonName", actionButton.getButtonName());
- buttonElement.setAttribute("buttonType", actionButton.getButtonType());
- buttonElement.setAttribute("value", actionButton.getValue());
- buttonElement.setAttribute("url", actionButton.getUrl());
- buttonElement.setAttribute("target", actionButton.getTarget());
- buttonElement.setAttribute("formWith", actionButton.getFormWith());
- buttonElement.setAttribute("formHeight", actionButton.getFormHeight());
- listaction.appendChild(buttonElement);
- }
- Element.appendChild(listaction);
- }
- private void createListHead(Element formListEle, ListHead listhead, Document doc) {
- Element listHead = doc.createElement("listHead");
- listHead.setAttribute("title", listhead.getTitle());
- listHead.setAttribute("titleWidth", listhead.getTitleWidth());
- formListEle.appendChild(listHead);
- }
- private void createQueryFields(Element formListEle, ArrayList<QueryFieldImpl> actlist,
- Document doc) {
- Element queryFields = doc.createElement("queryFields");
- for (int i = 0; i < actlist.size(); i++) {
- QueryFieldImpl queryfield = (QueryFieldImpl) actlist.get(i);
- Element queryFieldElement = doc.createElement("queryField");
- queryFieldElement.setAttribute("classid", queryfield.getClassid() + "");
- queryFieldElement.setAttribute("dataName", queryfield.getDataName());
- queryFieldElement.setAttribute("label", queryfield.getLabel());
- queryFieldElement.setAttribute("operator", queryfield.getOperator());
- queryFieldElement.setAttribute("controlType", queryfield.getControlType());
- controlTypeField(queryFieldElement, queryfield, doc);
- creatvalidates(queryFieldElement, doc, queryfield);
- queryFields.appendChild(queryFieldElement);
- }
- formListEle.appendChild(queryFields);
- }
- private void creatvalidates(Element pagereportField, Document doc, QueryFieldImpl queryfield) {
- Element validatesField = doc.createElement("validates");
- Validate Validate = queryfield.getValidate();
- if (Validate.isNeed()) {
- Element validateNode = doc.createElement("validate");
- validateNode.setAttribute("type", "need");
- validatesField.appendChild(validateNode);
- }
- if (Validate.isTrim()) {
- Element validateNode = doc.createElement("validate");
- validateNode.setAttribute("type", "trim");
- validatesField.appendChild(validateNode);
- }
- if (!Validate.getMaxLength().equals("")) {
- Element validateNode = doc.createElement("validate");
- validateNode.setAttribute("type", "length");
- validateNode.setAttribute("maxLength", Validate.getMaxLength());
- validatesField.appendChild(validateNode);
- }
- if (!Validate.getRegxValue().equals("")) {
- Element validateNode = doc.createElement("validate");
- validateNode.setAttribute("type", "regx");
- validateNode.setAttribute("regxValue", Validate.getRegxValue());
- validatesField.appendChild(validateNode);
- }
- if (!Validate.getDojoType().equals("")) {
- Element validateNode = doc.createElement("validate");
- validateNode.setAttribute("type", "dojoType");
- validateNode.setAttribute("typeValue", Validate.getDojoType());
- validatesField.appendChild(validateNode);
- }
- if (!Validate.getMaxValue().equals("") || !Validate.getMinValue().equals("")) {
- Element validateNode = doc.createElement("validate");
- validateNode.setAttribute("type", "range");
- validateNode.setAttribute("maxValue", Validate.getMaxValue());
- validateNode.setAttribute("minValue", Validate.getMinValue());
- validatesField.appendChild(validateNode);
- }
- if (!Validate.getInvalidMessage().equals("") || !Validate.getPromptMessage().equals("")) {
- Element validateNode = doc.createElement("validate");
- validateNode.setAttribute("type", "message");
- validateNode.setAttribute("promptMessage", Validate.getPromptMessage());
- validateNode.setAttribute("invalidMessage", Validate.getInvalidMessage());
- validatesField.appendChild(validateNode);
- }
- pagereportField.appendChild(validatesField);
- }
- private void creatQqueryList(Element formListEle, QueryList queryList, Document doc) {
- Element queryListEle = doc.createElement("queryList");
- queryListEle.setAttribute("haveOrder", new Boolean(queryList.isHaveOrder()).toString());
- queryListEle.setAttribute("pageSize", queryList.getPageSize() + "");
- queryListEle.setAttribute("tableList", queryList.getTableList());
- queryListEle.setAttribute("condition", queryList.getCondition());
- queryListEle.setAttribute("orderby", queryList.getOrderBy());
- queryListEle.setAttribute("isCheckbox", new Boolean(queryList.isCheckbox()).toString());
- creatListField(queryListEle, queryList.getlistFields(), doc);
- formListEle.appendChild(queryListEle);
- }
- private void creatListField(Element queryListEle, ArrayList<ListFieldImpl> arrayList,
- Document doc) {
- for (int i = 0; i < arrayList.size(); i++) {
- ListFieldImpl listField = arrayList.get(i);
- Element listFieldElement = doc.createElement("listField");
- listFieldElement.setAttribute("classid", listField.getClassid() + "");
- listFieldElement.setAttribute("showType", listField.getShowType());
- listFieldElement.setAttribute("width", listField.getWidth());
- listFieldElement.setAttribute("dataName", listField.getDataName());
- listFieldElement.setAttribute("label", listField.getLabel());
- listFieldElement.setAttribute("url", listField.getUrl());
- listFieldElement.setAttribute("target", listField.getTarget());
- listFieldElement.setAttribute("image", listField.getImage());
- listFieldElement.setAttribute("showTxt", listField.getShowTxt());
- listFieldElement.setAttribute("formWith", listField.getFormWith());
- listFieldElement.setAttribute("formHeight", listField.getFormHeight());
- listFieldElement.setAttribute("remark", listField.getRemark());
- queryListEle.appendChild(listFieldElement);
- }
- }
- private void createpramField(Element Element, ArrayList<PramFieldImpl> actlist, Document doc) {
- Element pramField = doc.createElement("pramField");
- for (int i = 0; i < actlist.size(); i++) {
- PramFieldImpl pram = actlist.get(i);
- Element pramElement = doc.createElement("pram");
- pramElement.setAttribute("classid", pram.getClassid() + "");
- pramElement.setAttribute("name", pram.getName());
- pramElement.setAttribute("valuefrom", pram.getValuefrom());
- pramElement.setAttribute("isInput", new Boolean(pram.isInput()).toString());
- pramField.appendChild(pramElement);
- }
- Element.appendChild(pramField);
- }
- private void createQrueyConditions(Element Element, ArrayList<String> actlist, Document doc) {
- Element qrueyConditions = doc.createElement("qrueyConditions");
- for (int i = 0; i < actlist.size(); i++) {
- String value = actlist.get(i);
- Element conditionElement = doc.createElement("condition");
- conditionElement.setAttribute("value", value);
- qrueyConditions.appendChild(conditionElement);
- }
- Element.appendChild(qrueyConditions);
- }
- private void createQrueyTables(Element Element, ArrayList<String> actlist, Document doc) {
- Element qrueyTables = doc.createElement("qrueyTables");
- for (int i = 0; i < actlist.size(); i++) {
- String classid = actlist.get(i);
- Element tableElement = doc.createElement("table");
- tableElement.setAttribute("classid", classid);
- qrueyTables.appendChild(tableElement);
- }
- Element.appendChild(qrueyTables);
- }
- private void controlTypeField(Element queryFieldElement, QueryFieldImpl queryfield, Document doc) {
- String controlType = queryfield.getControlType() == null ? "" : queryfield.getControlType();
- if (!controlType.equals("")) {
- Element controlField = doc.createElement(controlType);
- if (controlType.equals("text")) {
- TextControl TextControl = (TextControl) queryfield.getControl();
- controlField.setAttribute("size",
- TextControl.getSize() == null ? "" : TextControl.getSize());
- controlField.setAttribute("readonly",
- new Boolean(TextControl.isReadOnly()).toString());
- queryFieldElement.appendChild(controlField);
- } else if (controlType.equals("select")) {
- SelectControl SelectControl = (SelectControl) queryfield.getControl();
- controlField.setAttribute("constantName", SelectControl.getConstantName());
- queryFieldElement.appendChild(controlField);
- } else if (controlType.equals("tree")) {
- TreeControl TreeControl = (TreeControl) queryfield.getControl();
- controlField.setAttribute("size", TreeControl.getSize());
- controlField.setAttribute("type", TreeControl.getType());
- controlField.setAttribute("referenceTable", TreeControl.getReferenceTable());
- controlField.setAttribute("storeCode", TreeControl.getStoreCode());
- controlField.setAttribute("displayName", TreeControl.getDisplayName());
- controlField.setAttribute("parentCode", TreeControl.getParentCode());
- controlField.setAttribute("customDefine", TreeControl.getCustomDefine());
- controlField.setAttribute("condition", TreeControl.getCondition());
- controlField.setAttribute("order", TreeControl.getOrder());
- queryFieldElement.appendChild(controlField);
- }
- if (controlType.equals("date")) {
- DateControl DateControl = (DateControl) queryfield.getControl();
- controlField.setAttribute("size", DateControl.getSize());
- controlField.setAttribute("format", DateControl.getFormat());
- queryFieldElement.appendChild(controlField);
- }
- }
- }
- }
|