// 获得一个普通数据库的定义(包括数据库名captions,froms name captions) // 格式为 /* * <database> * <caption lang="zh-cn">中文图书</caption> * <caption lang="en">Chinese book</caption> * <from style="title"> * <caption lang="zh-cn">题名</caption> * <caption lang="en">Title</caption> * </from> * ... * <from name="__id" /> * </database> * */ // return: // -1 error // 0 not found such database // 1 found and succeed public int GetDatabaseDef( string strDbName, out string strDef, out string strError) { strError = ""; strDef = ""; int nRet = 0; XmlDocument dom = new XmlDocument(); dom.LoadXml("<database />"); { ResInfoItem dbitem = KernelDbInfo.GetDbItem( this.root_dir_results, strDbName); if (dbitem == null) { strError = "根目录下没有找到名字为 '" + strDbName + "' 的数据库目录事项"; return(0); } // 在根下加入<caption>元素 for (int i = 0; i < dbitem.Names.Length; i++) { string strText = dbitem.Names[i]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = dom.CreateElement("caption"); dom.DocumentElement.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); } } // ResInfoItem[] fromitems = (ResInfoItem[])this.db_dir_results[strDbName]; if (fromitems == null) { strError = "db_dir_results中没有找到关于 '" + strDbName + "' 的下级目录事项"; return(0); } for (int i = 0; i < fromitems.Length; i++) { ResInfoItem item = fromitems[i]; if (item.Type != ResTree.RESTYPE_FROM) { continue; } // 插入<from>元素 XmlNode fromnode = dom.CreateElement("from"); dom.DocumentElement.AppendChild(fromnode); DomUtil.SetAttr(fromnode, "style", item.TypeString); // style if (item.Names == null) { continue; } // 插入caption for (int j = 0; j < item.Names.Length; j++) { string strText = item.Names[j]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = dom.CreateElement("caption"); fromnode.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); } } strDef = dom.OuterXml; return(1); }
// 初始化数据库和From的一些属性, 以便将来运行起来快速方便 // 在<database>元素下要插入若干<from>元素 // 这些信息属于软件初始化的范畴, 避免人工去配置 // return: // -2 有数据库没有找到 // -1 出错 // 0 对DOM没有修改 // 1 对DOM发生了修改 public int InitialAllProperty( ResInfoItem[] root_dir_results, Hashtable db_dir_results, out string strError) { strError = ""; int nRet = 0; if (nodeDatabase == null) { strError = "nodeDatabase尚未设置值"; return(-1); } if (this.IsVirtual != false) { strError = "该函数只适用于<database>元素的初始化"; return(-1); } bool bChanged = false; string strDbName = DomUtil.GetAttr(nodeDatabase, "name"); RemoveChildren(nodeDatabase); bChanged = true; ResInfoItem dbitem = KernelDbInfo.GetDbItem( root_dir_results, strDbName); if (dbitem == null) { strError = "数据库内核根目录下没有找到名字为 '" + strDbName + "' 的数据库事项。如果该数据库已经被删除,请修改dp2Library的library.xml文件中<virtualDatabases>元素下的有关内容"; // return -1; return(-2); // 2017/6/7 } // 在下级加入<caption>元素 for (int i = 0; i < dbitem.Names.Length; i++) { string strText = dbitem.Names[i]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = nodeDatabase.OwnerDocument.CreateElement("caption"); newnode = nodeDatabase.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); bChanged = true; } // ResInfoItem [] fromitems = (ResInfoItem[])db_dir_results[strDbName]; if (fromitems == null) { strError = "db_dir_results中没有找到关于 '" + strDbName + "' 的下级目录事项"; return(-1); } for (int i = 0; i < fromitems.Length; i++) { ResInfoItem item = fromitems[i]; if (item.Type != ResTree.RESTYPE_FROM) { continue; } // 插入<from>元素 XmlNode fromnode = nodeDatabase.OwnerDocument.CreateElement("from"); fromnode = nodeDatabase.AppendChild(fromnode); DomUtil.SetAttr(fromnode, "name", item.Name); // 当前工作语言下的名字 // 以前忘记了 DomUtil.SetAttr(fromnode, "style", item.TypeString); // 2011/1/21 bChanged = true; if (item.Names == null) { continue; } // 插入caption for (int j = 0; j < item.Names.Length; j++) { string strText = item.Names[j]; nRet = strText.IndexOf(":"); if (nRet == -1) { strError = "names字符串 '" + strText + "' 格式不正确。"; return(-1); } string strLang = strText.Substring(0, nRet); string strName = strText.Substring(nRet + 1); XmlNode newnode = fromnode.OwnerDocument.CreateElement("caption"); newnode = fromnode.AppendChild(newnode); DomUtil.SetAttr(newnode, "lang", strLang); DomUtil.SetNodeText(newnode, strName); bChanged = true; } } if (bChanged == true) { return(1); } return(0); }