Пример #1
0
        /// <summary>
        /// 图书推荐
        /// </summary>
        /// <returns></returns>
        private IResponseMessageBase DoNewBooks()
        {
            // 置空当前命令,该命令不需要保存状态
            this.CurrentMessageContext.CurrentCmdName = "";

            // 加载新书配置文件
            string fileName = this.Dp2WeiXinAppDir + "/newbooks.xml";

            if (File.Exists(fileName) == false)
            {
                return(this.CreateTextResponseMessage("暂无推荐图书。"));
            }

            // 拼成图文消息
            var         responseMessage = CreateResponseMessage <ResponseMessageNews>();
            XmlDocument dom             = new XmlDocument();

            dom.Load(fileName);
            XmlNodeList itemList = dom.DocumentElement.SelectNodes("item");

            foreach (XmlNode node in itemList)
            {
                responseMessage.Articles.Add(new Article()
                {
                    Title       = DomUtil.GetNodeText(node.SelectSingleNode("Title")),
                    Description = DomUtil.GetNodeText(node.SelectSingleNode("Description")),
                    PicUrl      = this.CmdService.dp2WeiXinUrl + DomUtil.GetNodeText(node.SelectSingleNode("PicUrl")),
                    Url         = DomUtil.GetNodeText(node.SelectSingleNode("Url"))
                });
            }
            return(responseMessage);
        }
Пример #2
0
        // 得到
        public static string GetAllCaption(XmlNode node)
        {
            string      strXpath = "property/logicname/caption";
            XmlNodeList list     = node.SelectNodes(strXpath);

            string strAllCaption = "";

            foreach (XmlNode oneNode in list)
            {
                string strCaption = DomUtil.GetNodeText(oneNode);
                if (strCaption == "")
                {
                    continue;
                }

                if (strAllCaption != "")
                {
                    strAllCaption += ",";
                }

                strAllCaption += strCaption;
            }

            return(strAllCaption);
        }
Пример #3
0
        // 从references.xml文件中得到refs字符串数组
        // return:
        //		-1	error
        //		0	正确
        public static int GetRefs(string strRef,
                                  out string [] saRef,
                                  out string strError)
        {
            saRef    = null;
            strError = "";
            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strRef);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return(-1);
            }

            // 所有ref节点
            XmlNodeList nodes = dom.DocumentElement.SelectNodes("//ref");

            saRef = new string [nodes.Count];
            for (int i = 0; i < nodes.Count; i++)
            {
                saRef[i] = DomUtil.GetNodeText(nodes[i]);
            }

            return(0);
        }
Пример #4
0
        /// <summary>
        /// 检查微信用户是否绑定读者账号
        /// </summary>
        /// <param name="strWeiXinId"></param>
        /// <param name="strXml"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        private int CheckIsBinding(out string strError)
        {
            strError = "";

            if (String.IsNullOrEmpty(this.ReaderBarcode) == true)
            {
                // 根据openid检索绑定的读者
                string strRecPath = "";
                string strXml     = "";
                long   lRet       = dp2CommandService.Instance.SearchReaderByWeiXinId(this.WeiXinId, out strRecPath,
                                                                                      out strXml,
                                                                                      out strError);
                if (lRet == -1)
                {
                    return(-1);
                }
                // 未绑定
                if (lRet == 0)
                {
                    return(0);
                }

                XmlDocument dom = new XmlDocument();
                dom.LoadXml(strXml);
                this.ReaderBarcode = DomUtil.GetNodeText(dom.DocumentElement.SelectSingleNode("barcode"));
            }
            return(1);
        }
Пример #5
0
        public string GetString(string strID,
                                string strLang,
                                bool bThrowException,
                                string strDefault)
        {
            XmlNode node = null;

            string xpath = "";

            if (strLang == null || strLang == "")
            {
                xpath = "//"
                        + ContainerElementName
                        + "/" + ItemElementName + "[@"
                        + IdAttributeName + "='" + strID + "']/"
                        + ValueElementName;

                node = dom.DocumentElement.SelectSingleNode(xpath);
            }
            else
            {
REDO:
                xpath = "//"
                        + ContainerElementName
                        + "/" + ItemElementName + "[@"
                        + IdAttributeName + "='" + strID + "']/"
                        + ValueElementName + "[@lang='" + strLang + "']";

                node = dom.DocumentElement.SelectSingleNode(xpath);

                // 任延华加
                if (node == null)
                {
                    int nIndex = strLang.IndexOf('-');
                    if (nIndex != -1)
                    {
                        strLang = strLang.Substring(nIndex + 1);
                        goto REDO;
                    }
                }
            }
            if (node == null)
            {
                if (bThrowException)
                {
                    throw(new StringNotFoundException("id为" + strID + "lang为" + strLang + "的字符串没有找到"));
                }

                if (strDefault == "@id")
                {
                    return(strID);
                }

                return(strDefault);
            }

            return(DomUtil.GetNodeText(node));
        }
Пример #6
0
        public int Initialize(List <XmlNode> valueListNodes,
                              string strLang,
                              out string strError)
        {
            strError = "";

            Debug.Assert(valueListNodes != null, "Initialize() 的 valueListNodes参数不能为null。");

            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

            nsmgr.AddNamespace("xml", Ns.xml);

            foreach (XmlNode valueListNode in valueListNodes)
            {
                XmlNodeList itemList = valueListNode.SelectNodes("Item");
                foreach (XmlNode itemNode in itemList)
                {
                    string strItemLable = "";

                    // 从一个元素的下级的多个<strElementName>元素中, 提取语言符合的XmlNode的InnerText
                    // parameters:
                    //      bReturnFirstNode    如果找不到相关语言的,是否返回第一个<strElementName>
                    strItemLable = DomUtil.GetXmlLangedNodeText(
                        strLang,
                        itemNode,
                        "Label",
                        true);
                    if (string.IsNullOrEmpty(strItemLable) == true)
                    {
                        strItemLable = "????????";
                    }

#if NO
                    XmlNode itemLabelNode = itemNode.SelectSingleNode("Label[@xml:lang='" + strLang + "']", nsmgr);
                    if (itemLabelNode == null)
                    {
                        strItemLable = "????????";
                    }
                    else
                    {
                        strItemLable = DomUtil.GetNodeText(itemLabelNode);
                    }
#endif

                    XmlNode itemValueNode = itemNode.SelectSingleNode("Value");
                    string  strItemValue  = DomUtil.GetNodeText(itemValueNode);

                    ListViewItem item = new ListViewItem(strItemValue);
                    item.SubItems.Add(strItemLable);
                    this.listView_valueList.Items.Add(item);
                }
            }

            return(0);
        }
Пример #7
0
        /*
         * <subject>
         *  <rdf:value>马克思著作</rdf:value>
         *  <c2s:subdivide c2s:refinement="">
         *      <rdf:value>文集</rdf:value>
         *  </c2s:subdivide>
         * </subject>
         */
        /*
         *      <item>
         *              <subject>类名对应汉语主题词(用黑体显示)</subject>
         *              <subject refinement="subdivide">学科复分主题词</subject>
         *              <subject refinement="geographic">地区复分主题词</subject>
         *              <subject refinement="chronological">年代复分主题词</subject>
         *              <subject refinement="ethnic" rdf:resource="ethnic" />
         *              <!--
         *              前面的带限定词的subject值都用“-”连字符串起来,即判断refinement属性值为:
         *              “subdivide、geographic、chronological、chronological、ethnic”
         *              都用“-”连在不具refinement属性的subject值之后。
         *              -->
         *              <subject refinement="modifier">主题词修饰词</subject>
         *              <!--
         *              前面的带限定词的subject值都用“,”字符串起来,即判断refinement属性值为:
         *              “modifier”时,用“,”连在不具refinement属性的subject值之后。
         *              -->
         *              <subject refinement="bond">组配主题词</subject>
         *              <!--
         *              前面的带限定词的subject值都用“:”字符串起来,即判断refinement属性值为:
         *              “bond”时,用“:”连在不具refinement属性的subject值之后。
         *              -->
         *      </item>
         */
        void GetSubjectText(XmlNode node,
                            XmlNamespaceManager mngr,
                            out string strPureText,
                            out string strHtml)
        {
            strHtml     = "";
            strPureText = "";
            XmlNodeList nodes = node.SelectNodes("./c2s:subject", mngr);

            string strImg = "<img src='" + Environment.CurrentDirectory + "/copyfirst.gif" + "' border='0'>";

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode cur = nodes[i];

                XmlNode parent = cur.ParentNode;

                string strRefinement = DomUtil.GetAttr(cur, "refinement");

                if (String.IsNullOrEmpty(strRefinement) == true)
                {
                    string strText = RefinementText(strRefinement,
                                                    DomUtil.GetNodeText(cur));

                    string strSelectUrl = this.ActionPrefix + "copyone/" + HttpUtility.UrlEncode(strText);



                    // 引导词
                    strHtml += strText;

                    if (nodes.Count > 1)
                    {
                        strHtml += "<a href='" + strSelectUrl + "' alt='选用主题词" + strText + "'>" + strImg + "</a>";
                    }
                    else
                    {
                    }


                    strPureText += strText;
                }
                else
                {
                    // 被引导词
                    strHtml += "-" + DomUtil.GetNodeText(cur);

                    strPureText += "-" + DomUtil.GetNodeText(cur);
                }
            }
        }
Пример #8
0
        // 获得一个节点(有关语言的)的注释值
        private string GetComment(XmlNode node, string strLang)
        {
            XmlNode nodeComment = node.SelectSingleNode("comment[@lang='" + strLang + "']");

            if (nodeComment == null)
            {
                nodeComment = node.SelectSingleNode("comment");
            }

            if (nodeComment == null)
            {
                return("");
            }

            return(DomUtil.GetNodeText(nodeComment));
        }
Пример #9
0
        /// <summary>
        /// 从marcdef配置文件中获得marc格式定义
        /// </summary>
        /// <param name="strDbFullPath"></param>
        /// <param name="strMarcSyntax"></param>
        /// <param name="strError"></param>
        /// <returns>-1	出错;0	没有找到;1	找到</returns>
        public int GetMarcSyntax(string strDbFullPath,
                                 out string strMarcSyntax,
                                 out string strError)
        {
            strError      = "";
            strMarcSyntax = "";

            ResPath respath = new ResPath(strDbFullPath);

            string strCfgFilePath = respath.Path + "/cfgs/marcdef";

            XmlDocument tempdom = null;
            // 获得配置文件
            // return:
            //		-1	error
            //		0	not found
            //		1	found
            int nRet = this.GetCfgFile(
                respath.Url,
                strCfgFilePath,
                out tempdom,
                out strError);

            if (nRet == -1)
            {
                return(-1);
            }
            if (nRet == 0)
            {
                strError = "配置文件 '" + strCfgFilePath + "' 没有找到...";
                return(0);
            }

            XmlNode node = tempdom.DocumentElement.SelectSingleNode("//MARCSyntax");

            if (node == null)
            {
                strError = "marcdef文件 " + strCfgFilePath + " 中没有<MARCSyntax>元素";
                return(0);
            }

            strMarcSyntax = DomUtil.GetNodeText(node);

            strMarcSyntax = strMarcSyntax.ToLower();

            return(1);
        }
Пример #10
0
        /// <summary>
        /// 获取指定天的背景图url
        /// </summary>
        /// <returns></returns>
        public string GetImgUrl(string strNo)
        {
            // 先从本地记录找,有则直接返回
            if (imgDict.Keys.Contains(strNo) == true)
            {
                return(imgDict[strNo]);
            }

            //通过网络取url
            //我们可以通过访问:http://cn.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1获得一个XML文件,里面包含了图片的地址。
            //上面访问参数的含义分别是:
            //1、format,非必要。返回结果的格式,不存在或者等于xml时,输出为xml格式,等于js时,输出json格式。
            //2、idx,非必要。不存在或者等于0时,输出当天的图片,-1为已经预备用于明天显示的信息,1则为昨天的图片,idx最多获取到前16天的图片信息。
            //3、n,必要参数。这是输出信息的数量。比如n=1,即为1条,以此类推,至多输出8条。
            //在返回的XML文件中我们通过访问images->image->url获得图片地址,然后通过http://s.cn.bing.net/获得的图片地址进行访问
            string    url    = "http://cn.bing.com/HPImageArchive.aspx?format=xml&idx=0&n=1";
            WebClient client = new WebClient();

            byte[] result    = client.DownloadData(url);
            string strResult = Encoding.UTF8.GetString(result);

            XmlDocument dom = new XmlDocument();

            dom.LoadXml(strResult);
            XmlNode node   = dom.SelectSingleNode("images/image/url");
            string  imgUrl = DomUtil.GetNodeText(node);

            imgUrl = "http://s.cn.bing.net/" + imgUrl;

            // 设到字典
            imgDict[strNo] = imgUrl;

            // 保存到dom
            XmlNode imgNode = imgDom.CreateElement("img");

            DomUtil.SetAttr(imgNode, "no", strNo);
            DomUtil.SetAttr(imgNode, "url", imgUrl);
            imgDom.DocumentElement.AppendChild(imgNode);
            imgDom.Save(this.imgFileName);
            return(imgUrl);
        }
Пример #11
0
        // 成对出现的字符串
        public string[] GetStrings(string strLang)
        {
            string xpath = "";

            xpath = "//"
                    + ContainerElementName
                    + "/" + ItemElementName + "/"
                    + ValueElementName + "[@lang='" + strLang + "']";

            XmlNodeList nodes = dom.DocumentElement.SelectNodes(xpath);

            string [] result = new string [nodes.Count * 2];

            for (int i = 0; i < nodes.Count; i++)
            {
                result[i * 2]     = DomUtil.GetAttr(nodes[i].ParentNode, "id");
                result[i * 2 + 1] = DomUtil.GetNodeText(nodes[i]);
            }

            return(result);
        }
Пример #12
0
        /// <summary>
        /// 近期通告
        /// </summary>
        /// <returns></returns>
        private IResponseMessageBase DoNotice()
        {
            // 置空当前命令,该命令不需要保存状态
            this.CurrentMessageContext.CurrentCmdName = "";

            // 加载公告配置文件
            string fileName = this.Dp2WeiXinAppDir + "/notice.xml";

            if (File.Exists(fileName) == false)
            {
                return(this.CreateTextResponseMessage("暂无公告"));

                var textResponseMessage = CreateResponseMessage <ResponseMessageText>();
                textResponseMessage.Content = "";
                return(textResponseMessage);
            }

            //拼成图文消息
            var         responseMessage = CreateResponseMessage <ResponseMessageNews>();
            XmlDocument dom             = new XmlDocument();

            dom.Load(fileName);
            XmlNodeList itemList = dom.DocumentElement.SelectNodes("item");

            foreach (XmlNode node in itemList)
            {
                Article article = new Article();
                article.Title       = DomUtil.GetNodeText(node.SelectSingleNode("Title"));
                article.Description = DomUtil.GetNodeText(node.SelectSingleNode("Description"));
                string picUrl = DomUtil.GetNodeText(node.SelectSingleNode("PicUrl"));
                if (String.IsNullOrEmpty(picUrl) == false)
                {
                    article.PicUrl = this.CmdService.dp2WeiXinUrl + picUrl;
                }
                article.Url = DomUtil.GetNodeText(node.SelectSingleNode("Url"));
                responseMessage.Articles.Add(article);
            }
            return(responseMessage);
        }
Пример #13
0
        public void CreateNSOfCfg(XmlDocument domData,
                                  XmlDocument domCfg)
        {
            XmlNodeList nsitemList = domCfg.DocumentElement.SelectNodes("/root/nstable/item");

            foreach (XmlNode nsitemNode in nsitemList)
            {
                XmlNode nsNode     = nsitemNode.SelectSingleNode("nameSpace");
                XmlNode prefixNode = nsitemNode.SelectSingleNode("prefix");

                PrefixURI prefixUri = new PrefixURI();
                if (prefixNode != null)
                {
                    prefixUri.strPrefix = DomUtil.GetNodeText(prefixNode);
                }
                if (nsNode != null)
                {
                    prefixUri.strURI = DomUtil.GetNodeText(nsNode);
                }

                if (prefixUri.strPrefix != "" &&
                    prefixUri.strURI != "")                         //在配置文件里不允许前缀为空
                {
                    this.Add(prefixUri);
                }
            }

            this.Sort();
            this.DumpRep();

            //if (this.Count > 0)
            //{
            this.nsmgr = new XmlNamespaceManager(domData.NameTable);
            Add2nsmgr();
            //}
        }
Пример #14
0
        /// <summary>
        /// 根据微信id检索读者
        /// </summary>
        /// <param name="strWeiXinId"></param>
        /// <param name="strRecPath"></param>
        /// <param name="strXml"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public override long SearchOnePatronByWeiXinId(string remoteUserName,
                                                       string libCode,
                                                       string strWeiXinId,
                                                       out string strBarcode,
                                                       out string strError)
        {
            strError   = "";
            strBarcode = "";

            long lRet = 0;

            LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);

            channel.Password = this.dp2Password;
            try
            {
                strWeiXinId = dp2CommandUtility.C_WeiXinIdPrefix + strWeiXinId;//weixinid:

                // 先从mongodb查
                if (this.IsUseMongoDb == true)
                {
                    return(0);
                }


                lRet = channel.SearchReader("",
                                            strWeiXinId,
                                            -1,
                                            "email",
                                            "exact",
                                            "zh",
                                            "weixin",
                                            "keyid",
                                            out strError);
                if (lRet == -1)
                {
                    strError = "检索微信用户对应的读者出错:" + strError;
                    return(-1);
                }
                else if (lRet > 1)
                {
                    strError = "检索微信用户对应的读者异常,得到" + lRet.ToString() + "条读者记录";
                    return(-1);
                }
                else if (lRet == 0)
                {
                    strError = "根据微信id未找到对应读者。";
                    return(0);
                }
                else if (lRet == 1)
                {
                    Record[] searchresults = null;
                    lRet = channel.GetSearchResult("weixin",
                                                   0,
                                                   -1,
                                                   "id,xml",
                                                   "zh",
                                                   out searchresults,
                                                   out strError);
                    if (searchresults.Length != 1)
                    {
                        throw new Exception("获得的记录数不是1");
                    }
                    if (lRet != 1)
                    {
                        strError = "获取结果集异常:" + strError;
                        return(-1);
                    }

                    string      strXml = searchresults[0].RecordBody.Xml;
                    XmlDocument dom    = new XmlDocument();
                    dom.LoadXml(strXml);
                    strBarcode = DomUtil.GetNodeText(dom.DocumentElement.SelectSingleNode("barcode"));
                    // 将关系存到mongodb库
                    if (this.IsUseMongoDb == true)
                    {
                        //name
                        string  name = "";
                        XmlNode node = dom.DocumentElement.SelectSingleNode("name");
                        if (node != null)
                        {
                            name = DomUtil.GetNodeText(node);
                        }

                        WxUserItem userItem = new WxUserItem();
                        userItem.weixinId      = strWeiXinId;
                        userItem.readerBarcode = strBarcode;
                        userItem.readerName    = name;
                        userItem.libCode       = "";
                        userItem.libUserName   = "";
                        userItem.xml           = strXml;
                        userItem.refID         = searchresults[0].Path;
                        userItem.createTime    = DateTimeUtil.DateTimeToString(DateTime.Now);
                        userItem.updateTime    = userItem.createTime;
                        WxUserDatabase.Current.Add(userItem);
                    }
                }
            }
            finally
            {
                this.ChannelPool.ReturnChannel(channel);
            }

            return(0);
        }
Пример #15
0
        public static List <SubLib> ParseSubLib(string xml, bool bAddRoot)
        {
            List <SubLib> subLibs = new List <SubLib>();

            /*
             * <item canborrow="no" itemBarcodeNullable="yes">保存本库</item>
             * <item canborrow="no" itemBarcodeNullable="yes">阅览室</item>
             * <item canborrow="yes" itemBarcodeNullable="yes">流通库</item>
             * <library code="方洲小学">
             * <item canborrow="yes" itemBarcodeNullable="yes">图书总库</item>
             * </library>
             * <library code="星洲小学">
             * <item canborrow="yes" itemBarcodeNullable="yes">阅览室</item>
             * </library>
             *
             * ==样例2==
             * <library code="方洲小学">
             * <item canborrow="yes" itemBarcodeNullable="yes">图书总库</item>
             * </library>
             * <library code="星洲小学">
             * <item canborrow="yes" itemBarcodeNullable="yes">阅览室</item>
             * </library>
             */

            // 将xml用<root>包起来
            if (bAddRoot == true)
            {
                xml = "<root>" + xml + "</root>";
            }
            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(xml);
            }
            catch
            {
                return(subLibs);
            }
            XmlNode root = dom.DocumentElement;

            // 第一层的item,没有分馆代码,一般表示总馆
            XmlNodeList level1ItemList = root.SelectNodes("item");

            if (level1ItemList.Count > 0)
            {
                SubLib subLib = new SubLib();
                subLib.libCode = "";
                foreach (XmlNode item in level1ItemList)
                {
                    // todo 不参与流通的库,是否需要过滤???
                    string   location = DomUtil.GetNodeText(item);
                    Location loc      = new Location(location, subLib.libCode);
                    subLib.Locations.Add(loc);
                }
                subLibs.Add(subLib);
            }

            // 分馆
            XmlNodeList libList = root.SelectNodes("library");

            foreach (XmlNode lib in libList)
            {
                SubLib subLib = new SubLib();
                subLib.libCode = DomUtil.GetAttr(lib, "code");

                XmlNodeList itemList = lib.SelectNodes("item");
                foreach (XmlNode item in itemList)
                {
                    // todo 不参与流通的库,是否需要过滤???
                    string   location = DomUtil.GetNodeText(item);
                    Location loc      = new Location(location, subLib.libCode);
                    subLib.Locations.Add(loc);
                }
                subLibs.Add(subLib);
            }



            return(subLibs);
        }
Пример #16
0
        // 解析资源路径中的xpath部分
        // parameters:
        //		strOrigin	资源路径中传来的xpath路径
        //		strLocateXpath	out参数,返回定位的节点路径
        //		strCreatePath	out参数,返回创建的节点路径
        //		strNewRecordTemplate	新数据模板
        //		strAction	行为
        //		strError	出错信息
        // return:
        //		-1	出错
        //		0	成功
        public static int PaseXPathParameter(string strOrigin,
                                             out string strLocateXPath,
                                             out string strCreatePath,
                                             out string strNewRecordTemplate,
                                             out string strAction,
                                             out string strError)
        {
            strLocateXPath       = "";
            strCreatePath        = "";
            strNewRecordTemplate = "";
            strAction            = "";
            strError             = "";

            if (strOrigin.Length == 0)
            {
                strError = "strOrigin不能为空字符串";
                return(-1);
            }

            // 开后门,xpath可以直接用简单的式子
            if (strOrigin[0] == '@')
            {
                strLocateXPath = strOrigin.Substring(1);
                return(0);
            }

            strOrigin = "<root>" + strOrigin + "</root>";
            XmlDocument tempDom = new XmlDocument();

            tempDom.PreserveWhitespace = true; //设PreserveWhitespace为true

            try
            {
                tempDom.LoadXml(strOrigin);
            }
            catch (Exception ex)
            {
                strError = "PaseXPathParameter() 解析strOrigin到dom出错,原因:" + ex.Message;
                return(-1);
            }

            // locate
            XmlNode node = tempDom.DocumentElement.SelectSingleNode("//locate");

            if (node != null)
            {
                strLocateXPath = DomUtil.GetNodeText(node);
            }

            // create
            node = tempDom.DocumentElement.SelectSingleNode("//create");
            if (node != null)
            {
                strCreatePath = DomUtil.GetNodeText(node);
            }

            // template
            node = tempDom.DocumentElement.SelectSingleNode("//template");
            if (node != null)
            {
                if (node.ChildNodes.Count != 1)
                {
                    strError = "template下级有且只能有一个儿子节点";
                    return(-1);
                }
                if (node.ChildNodes[0].NodeType != XmlNodeType.Element)
                {
                    strError = "template的下级必须是元素类型";
                    return(-1);
                }
                strNewRecordTemplate = node.InnerXml;
            }

            // action
            node = tempDom.DocumentElement.SelectSingleNode("//action");
            if (node != null)
            {
                strAction = DomUtil.GetNodeText(node);
            }

            return(0);
        }
Пример #17
0
        /// <summary>
        /// 根据微信id检索读者
        /// </summary>
        /// <param name="strWeiXinId"></param>
        /// <param name="strRecPath"></param>
        /// <param name="strXml"></param>
        /// <param name="strError"></param>
        /// <returns></returns>
        public long SearchReaderByWeiXinId(string strWeiXinId,
                                           out string strRecPath,
                                           out string strXml,
                                           out string strError)
        {
            strError   = "";
            strRecPath = "";
            strXml     = "";

            long lRet = 0;

            LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);

            channel.Password = this.dp2Password;
            try
            {
                strWeiXinId = dp2CommandUtility.C_WeiXinIdPrefix + strWeiXinId;//weixinid:

                // 先从mongodb查
                if (this.IsUseMongoDb == true)
                {
                    return(0);
                }


                lRet = this.SearchReaderByWeiXinId(channel, strWeiXinId, out strError);
                if (lRet == -1)
                {
                    strError = "检索微信用户对应的读者出错:" + strError;
                    return(-1);
                }
                else if (lRet > 1)
                {
                    strError = "检索微信用户对应的读者异常,得到" + lRet.ToString() + "条读者记录";
                    return(-1);
                }
                else if (lRet == 0)
                {
                    strError = "根据微信id未找到对应读者。";
                    return(0);
                }
                else if (lRet == 1)
                {
                    lRet = this.GetSearchResultForWeiXinUser(channel,
                                                             out strRecPath,
                                                             out strXml,
                                                             out strError);
                    if (lRet != 1)
                    {
                        strError = "获取结果集异常:" + strError;
                        return(-1);
                    }

                    XmlDocument dom = new XmlDocument();
                    dom.LoadXml(strXml);
                    string strBarcode = DomUtil.GetNodeText(dom.DocumentElement.SelectSingleNode("barcode"));
                    // 将关系存到mongodb库
                    if (this.IsUseMongoDb == true)
                    {
                        //name
                        string  name = "";
                        XmlNode node = dom.DocumentElement.SelectSingleNode("name");
                        if (node != null)
                        {
                            name = DomUtil.GetNodeText(node);
                        }

                        WxUserItem userItem = new WxUserItem();
                        userItem.weixinId      = strWeiXinId;
                        userItem.readerBarcode = strBarcode;
                        userItem.readerName    = name;
                        userItem.libCode       = "";
                        userItem.createTime    = DateTimeUtil.DateTimeToString(DateTime.Now);
                        WxUserDatabase.Current.Add(userItem);
                    }
                }
            }
            finally
            {
                this.ChannelPool.ReturnChannel(channel);
            }

            return(1);
        }
Пример #18
0
        // 装载一个 XML 文件
        int LoadOneXml(string strFileName,
                       out string strError)
        {
            strError = "";

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.Load(strFileName);
            }
            catch (Exception ex)
            {
                strError = ExceptionUtil.GetAutoText(ex);
                return(-1);
            }

            XmlNodeList propertyList = dom.SelectNodes("root/property");

            // int j;
            foreach (XmlElement node in propertyList)
            {
                // 找到事项名字
                string strName = DomUtil.GetAttr(node, "name");

                if (string.IsNullOrEmpty(strName))
                {
                    continue;
                }

                // 按照语言找到comment字符串
                XmlNode nodeComment = null;

                if (Lang == "")
                {
                    nodeComment = node.SelectSingleNode("comment");
                }
                else
                {
                    nodeComment = node.SelectSingleNode("comment[@lang='" + Lang + "']");
                    if (nodeComment == null)    // 按照指定的语言找,但是没有找到
                    {
                        nodeComment = node.SelectSingleNode("comment");
                    }
                }

                string strComment = "";

                if (nodeComment != null)
                {
                    strComment = DomUtil.GetNodeText(nodeComment);
                }


                ListViewItem item = new ListViewItem(strName, 0);
                item.SubItems.Add(strComment);

                // 2017/4/20
                string strAlias = node.GetAttribute("alias");
                if (string.IsNullOrEmpty(strAlias) == false)
                {
                    ItemInfo info = new ItemInfo();
                    info.AliasList = StringUtil.SplitList(strAlias);
                    item.Tag       = info;
                }

                listView_property.Items.Add(item);
            }

            // 创建语言数组
            XmlNodeList commentList = dom.SelectNodes("root/property/comment");

            _langNameList = new List <string>(); // = new ArrayList();

            foreach (XmlNode node in commentList)
            {
                // 找到事项名字
                string strLang = DomUtil.GetAttr(node, "lang");

                if (strLang == "")
                {
                    continue;
                }

#if NO
                bool bFound = false;
                for (j = 0; j < _langNameList.Count; j++)
                {
                    if (strLang == _langNameList[j])
                    {
                        bFound = true;
                        break;
                    }
                }

                if (bFound == false)
                {
                    _langNameList.Add(strLang);
                }
#endif
                if (_langNameList.IndexOf(strLang) == -1)
                {
                    _langNameList.Add(strLang);
                }
            }

            return(0);
        }
Пример #19
0
        // 根据nodeItem得到检索的相关信息
        // parameter:
        //		nodeItem	配置节点
        //		strTarget	out参数,返回检索目标,会是多库的多途径
        //		strWord	    out参数,返回检索词
        //		strMatch	out参数,返回匹配方式
        //		strRelation	out参数,返回关系符
        //		strDataType	out参数,返回检索的数据类型
        //		strIdOrder	out参数,返回id的排序规则
        //		strKeyOrder	out参数,返回key的排序规则
        //		strOrderBy	out参数,返回由order与originOrder组合的排序规则,例如" keystring ASC,idstring DESC "
        //		nMax	    out参数,返回最大条数
        //		strError	out参数,返回出错信息
        // return:
        //		-1	出错
        //		0	成功
        public static int GetSearchInfo(XmlNode nodeItem,
                                        out string strTarget,
                                        out string strWord,
                                        out string strMatch,
                                        out string strRelation,
                                        out string strDataType,
                                        out string strIdOrder,
                                        out string strKeyOrder,
                                        out string strOrderBy,
                                        out int nMaxCount,
                                        out string strError)
        {
            strTarget   = "";
            strWord     = "";
            strMatch    = "";
            strRelation = "";
            strDataType = "";
            strIdOrder  = "";
            strKeyOrder = "";
            strOrderBy  = "";
            nMaxCount   = 0;
            strError    = "";

            //--------------------------------------
            //调GetTarget函数,得到检索目标target节点
            XmlNode nodeTarget = QueryUtil.GetTarget(nodeItem);

            if (nodeTarget == null)
            {
                strError = "检索式的target元素未定义";
                return(-1);
            }
            strTarget = DomUtil.GetAttrDiff(nodeTarget, "list");
            if (strTarget == null)
            {
                strError = "target元素的list属性未定义";
            }
            strTarget = strTarget.Trim();
            if (strTarget == "")
            {
                strError = "target元素的list属性值不能为空字符串";
                return(-1);
            }


            //-------------------------------------------
            //检索文本 可以为空字符串
            XmlNode nodeWord = nodeItem.SelectSingleNode("word");

            if (nodeWord == null)
            {
                strError = "检索式的word元素未定义";
                return(-1);
            }
            strWord = DomUtil.GetNodeText(nodeWord);
            strWord = strWord.Trim();


            //------------------------------------
            //匹配方式
            XmlNode nodeMatch = nodeItem.SelectSingleNode("match");

            if (nodeMatch == null)
            {
                strError = "检索式的match元素未定义";
                return(-1);
            }
            strMatch = DomUtil.GetNodeText(nodeMatch);
            strMatch = strMatch.Trim();
            if (strMatch == "")
            {
                strError = "检索式的match元素内容不能为空字符串";
                return(-1);
            }
            if (QueryUtil.CheckMatch(strMatch) == false)
            {
                strError = "检索式的match元素内容'" + strMatch + "'不合法,必须为left,middle,right,exact";
                return(-1);
            }

            //--------------------------------------------
            //关系操作符
            XmlNode nodeRelation = nodeItem.SelectSingleNode("relation");

            if (nodeRelation == null)
            {
                strError = "检索式的relation元素未定义";
                return(-1);
            }
            strRelation = DomUtil.GetNodeText(nodeRelation);
            strRelation = strRelation.Trim();
            if (strRelation == "")
            {
                strError = "检索式的relation元素内容不能为空字符串";
                return(-1);
            }
            strRelation = QueryUtil.ConvertLetterToOperator(strRelation);
            if (QueryUtil.CheckRelation(strRelation) == false)
            {
                strError = "检索式的relation元素内容'" + strRelation + "'不合法.";
                return(-1);
            }

            //-------------------------------------------
            //数据类型
            XmlNode nodeDataType = nodeItem.SelectSingleNode("dataType");

            if (nodeDataType == null)
            {
                strError = "检索式的dataType元素未定义";
                return(-1);
            }
            strDataType = DomUtil.GetNodeText(nodeDataType);
            strDataType = strDataType.Trim();
            if (strDataType == "")
            {
                strError = "检索式的dataType元素内容不能为空字符串";
                return(-1);
            }
            if (QueryUtil.CheckDataType(strDataType) == false)
            {
                strError = "检索式的dataType元素内容'" + strDataType + "'不合法,必须为string,number";
                return(-1);
            }


            // ----------order可以不存在----------
            int    nOrderIndex       = -1;
            string strOrder          = null;
            int    nOriginOrderIndex = -1;
            string strOriginOrder    = null;

            //id的序  //ASC:升序  //DESC:降序
            XmlNode nodeOrder = nodeItem.SelectSingleNode("order");

            // 当定义了order元素时,才会id进行排序
            if (nodeOrder != null)
            {
                string strOrderText = DomUtil.GetNodeText(nodeOrder);
                strOrderText = strOrderText.Trim();
                if (strOrderText != "")
                {
                    strOrder    = "idstring " + strOrderText;
                    nOrderIndex = DomUtil.GetIndex(nodeOrder);
                    strIdOrder  = strOrderText;
                }
            }

            //key的序  //ASC:升序  //DESC:降序
            XmlNode nodeOriginOrder = nodeItem.SelectSingleNode("originOrder");

            // 当定义了order元素时,才会id进行排序
            if (nodeOriginOrder != null)
            {
                string strOriginOrderText = DomUtil.GetNodeText(nodeOriginOrder);
                strOriginOrderText = strOriginOrderText.Trim();
                if (strOriginOrderText != "")
                {
                    strOriginOrder    = "keystring " + strOriginOrderText;
                    nOriginOrderIndex = DomUtil.GetIndex(nodeOriginOrder);
                    strKeyOrder       = strOriginOrderText;
                }
            }

            if (strOrder != null &&
                strOriginOrder != null)
            {
                if (nOrderIndex == -1 ||
                    nOriginOrderIndex == -1)
                {
                    strError = "此时nOrderIndex和nOriginOrderIndex都不可能为-1";
                    return(-1);
                }
                if (nOrderIndex == nOriginOrderIndex)
                {
                    strError = "nOrderIndex 与 nOriginOrderIndex不可能相等";
                    return(-1);
                }
                if (nOrderIndex > nOriginOrderIndex)
                {
                    strOrderBy = strOrder + "," + strOriginOrder;
                }
                else
                {
                    strOrderBy = strOriginOrder + "," + strOrder;
                }
            }
            else
            {
                if (strOrder != null)
                {
                    strOrderBy = strOrder;
                }
                if (strOriginOrder != null)
                {
                    strOrderBy = strOriginOrder;
                }
            }


            //-------------------------------------------
            //最大个数
            XmlNode nodeMaxCount = nodeItem.SelectSingleNode("maxCount");

            /*
             *          if (nodeMaxCount == null)
             *          {
             *              strError = "检索式的maxCount元素未定义";
             *              return -1;
             *          }
             */
            string strMaxCount = "";

            if (nodeMaxCount != null)
            {
                strMaxCount = DomUtil.GetNodeText(nodeMaxCount).Trim();
            }
            if (strMaxCount == "")
            {
                strMaxCount = "-1";
            }

            /*
             *          if (strMaxCount == "")
             *          {
             *              strError = "检索式的maxCount元素的值为空字符串";
             *              return -1;
             *          }
             */
            try
            {
                nMaxCount = Convert.ToInt32(strMaxCount);
                if (nMaxCount < -1)
                {
                    strError = "xml检索式的maxCount的值'" + strMaxCount + "'不合法,必须是数值型";
                    return(-1);
                }
            }
            catch
            {
                strError = "xml检索式的maxCount的值'" + strMaxCount + "'不合法,必须是数值型";
                return(-1);
            }

            return(0);
        }
Пример #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strBarcode"></param>
        /// <param name="strPassword"></param>
        /// <param name="weiXinId"></param>
        /// <returns>
        /// -1 出错
        /// 0 读者证条码号或密码不正确
        /// 1 成功
        /// </returns>
        public int Binding(string strBarcode,
                           string strPassword,
                           string strWeiXinId,
                           out string strReaderBarcode,
                           out string strError)
        {
            strError         = "";
            strReaderBarcode = "";

            LibraryChannel channel = this.ChannelPool.GetChannel(this.dp2Url, this.dp2UserName);

            channel.Password = this.dp2Password;
            try
            {
                // 检验用户名与密码
                long lRet = channel.VerifyReaderPassword(strBarcode,
                                                         strPassword,
                                                         out strError);
                if (lRet == -1)
                {
                    strError = "读者证条码号或密码不正确。\n请重新输入'读者证条码号'(注:您也可以同时输入'读者证条码号'和'密码',中间以/分隔,例如:R0000001/123)";
                    return(0);
                }

                if (lRet == 0)
                {
                    strError = "读者证条码号或密码不正确。\n请重新输入'读者证条码号'(注:您也可以同时输入'读者证条码号'和'密码',中间以/分隔,例如:R0000001/123)";
                    return(0);
                }

                if (lRet == 1)
                {
                    // 进行绑定
                    // 先根据barcode检索出来,得到原记录与时间戳
                    GetReaderInfoResponse response = channel.GetReaderInfo(strBarcode,
                                                                           "xml");
                    if (response.GetReaderInfoResult.Value != 1)
                    {
                        strError = "根据读者证条码号得到读者记录异常:" + response.GetReaderInfoResult.ErrorInfo;
                        return(-1);
                    }
                    string strRecPath   = response.strRecPath;
                    string strTimestamp = StringUtil.GetHexTimeStampString(response.baTimestamp);
                    string strXml       = response.results[0];

                    // 改读者的email字段
                    XmlDocument readerDom = new XmlDocument();
                    readerDom.LoadXml(strXml);
                    XmlNode emailNode = readerDom.SelectSingleNode("//email");
                    if (emailNode == null)
                    {
                        emailNode = readerDom.CreateElement("email");
                        readerDom.DocumentElement.AppendChild(emailNode);
                    }
                    emailNode.InnerText = JoinEmail(emailNode.InnerText, strWeiXinId);
                    string strNewXml = ConvertXmlToString(readerDom);

                    // 更新到读者库
                    lRet = channel.SetReaderInfoForWeiXin(strRecPath,
                                                          strNewXml,
                                                          strTimestamp,
                                                          out strError);
                    if (lRet == -1)
                    {
                        strError = "绑定出错:" + strError;
                        return(-1);
                    }

                    // 绑定成功,把读者证条码记下来,用于续借 2015/11/7,不要用strbarcode变量,因为可能做的大小写转换
                    strReaderBarcode = DomUtil.GetNodeText(readerDom.DocumentElement.SelectSingleNode("barcode"));

                    // 将关系存到mongodb库
                    if (this.IsUseMongoDb == true)
                    {
                        //name
                        string  name = "";
                        XmlNode node = readerDom.DocumentElement.SelectSingleNode("name");
                        if (node != null)
                        {
                            name = DomUtil.GetNodeText(node);
                        }

                        WxUserItem userItem = WxUserDatabase.Current.GetOneByWeixinId(strWeiXinId);
                        if (userItem == null)
                        {
                            // 大微信号管理多个图书馆不可能出现不存在的情况,必然先选择了图书馆
                            userItem               = new WxUserItem();
                            userItem.weixinId      = strWeiXinId;
                            userItem.libCode       = "";
                            userItem.readerBarcode = "";
                            userItem.readerName    = "";
                            userItem.createTime    = DateTimeUtil.DateTimeToString(DateTime.Now);
                            WxUserDatabase.Current.Add(userItem);
                        }
                        else
                        {
                            userItem.readerBarcode = strBarcode;
                            userItem.readerName    = name;
                            userItem.createTime    = DateTimeUtil.DateTimeToString(DateTime.Now);
                            lRet = WxUserDatabase.Current.Update(userItem);
                        }
                    }

                    return(1);
                }

                strError = "校验读者账号返回未知情况,返回值:" + lRet.ToString() + "-" + strError;
                return(-1);
            }
            finally
            {
                this.ChannelPool.ReturnChannel(channel);
            }
        }
Пример #21
0
/*
 *              <Char name='0/5'>
 *                      <Property>
 *                              <Label xml:lang='en'>?</Label>
 *                              <Label xml:lang='cn'>记录长度</Label>
 *                              <Help xml:lang='cn'></Help>
 *                              <ValueList name='header_0/5'>
 *                                      <Item>
 *                                              <Value>?????</Value>
 *                                              <Label xml:lang='cn'>由软件自动填写</Label>
 *                                      </Item>
 *                              </ValueList>
 *                      </Property>
 *              </Char>
 */
        // 通过一个Char节点,初始化本行的值
        // parameter:
        //		node	char节点
        //		strLang	语言版本
        //		strError	出错信息
        // return:
        //		-1	失败
        //		0	成功
        public int Initial(XmlNode node,
                           string strLang,
                           out string strError)
        {
            strError = "";

            if (node == null)
            {
                strError = "调用错误,node参数不能为null";
                Debug.Assert(false, strError);
                return(-1);
            }

            this.m_strName = Trim(DomUtil.GetAttr(node, "name"));
            if (this.m_strName == "")
            {
                strError = "<Char>元素的name属性可能不存在或者值为空,配置文件不合法。";
                Debug.Assert(false, strError);
                return(-1);
            }

            XmlNode propertyNode = node.SelectSingleNode("Property");

            if (propertyNode == null)
            {
                strError = "<Char>元素下级未定义<Property>元素,配置文件不合法";
                Debug.Assert(false, strError);
                return(-1);
            }

            // <Property>/<sensitive>
            if (propertyNode.SelectSingleNode("sensitive") != null)
            {
                this.IsSensitive  = true;
                this.m_lineState |= LineState.Sensitive;
            }
            else
            {
                this.IsSensitive = false;
            }

            // <Property>/<DefaultValue>
            if (propertyNode.SelectSingleNode("DefaultValue") != null)
            {
                this.m_lineState |= LineState.Macro;
            }

            // <Property>/<DefaultValue>
            XmlNode nodeDefaultValue = propertyNode.SelectSingleNode("DefaultValue");

            if (nodeDefaultValue != null)
            {
                this.DefaultValue = nodeDefaultValue.InnerText;
            }

            // 从一个元素的下级的多个<strElementName>元素中, 提取语言符合的XmlNode的InnerText
            // parameters:
            //      bReturnFirstNode    如果找不到相关语言的,是否返回第一个<strElementName>
            this.m_strLabel = DomUtil.GetXmlLangedNodeText(
                strLang,
                propertyNode,
                "Label",
                true);
            if (string.IsNullOrEmpty(this.m_strLabel) == true)
            {
                this.m_strLabel = "<尚未定义>";
            }
            else
            {
                this.m_strLabel = StringUtil.Trim(this.m_strLabel);
            }
#if NO
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
            nsmgr.AddNamespace("xml", Ns.xml);
            XmlNode labelNode = propertyNode.SelectSingleNode("Label[@xml:lang='" + strLang + "']", nsmgr);
            if (labelNode == null ||
                string.IsNullOrEmpty(labelNode.InnerText.Trim()) == true)
            {
                // 如果找不到,则找到第一个有值的
                XmlNodeList nodes = propertyNode.SelectNodes("Label", nsmgr);
                foreach (XmlNode temp_node in nodes)
                {
                    if (string.IsNullOrEmpty(temp_node.InnerText.Trim()) == false)
                    {
                        labelNode = temp_node;
                        break;
                    }
                }

                //Debug.Assert(false,"名称为'" + this.m_strName + "'的<char>元素未定义Label的'" + strLang + "'语言版本的值");
            }
            if (labelNode == null)
            {
                this.m_strLabel = "<尚未定义>";
            }
            else
            {
                this.m_strLabel = Trim(DomUtil.GetNodeText(labelNode));
            }
#endif

            // 给value赋初值
            int nIndex = this.m_strName.IndexOf("/");
            if (nIndex >= 0)
            {
                string strLetterCount = this.m_strName.Substring(nIndex + 1);
                this.m_nValueLength = Convert.ToInt32(strLetterCount);
                this.m_nStart       = Convert.ToInt32(this.m_strName.Substring(0, nIndex));
            }
            if (this.m_strValue == null)
            {
                this.m_strValue = new string('*', this.m_nValueLength);
            }


            XmlNodeList valuelist_nodes = propertyNode.SelectNodes("ValueList");
            this.ValueListNodes = new List <XmlNode>();
            foreach (XmlNode valuelist_node in valuelist_nodes)
            {
                this.ValueListNodes.Add(valuelist_node);
            }

            return(0);
        }
Пример #22
0
        /*
         * public int UseCount
         * {
         *  get
         *  {
         *      return this.m_nUseCount;
         *  }
         * }
         */

        // 初始化用户对象
        // 线程不安全。因为被调用时尚未进入集合,也没有必要线程安全
        // parameters:
        //      dom         用户记录dom
        //      strResPath  记录路径 全路径 库名/记录号
        //      db          所从属的数据库
        //      strError    out参数,返回出错信息
        // return:
        //      -1  出错
        //      0   成功
        internal int Initial(string strRecPath,
                             XmlDocument dom,
                             Database db,
                             DatabaseCollection dbs,
                             out string strError)
        {
            strError = "";
            int nRet = 0;

            this.RecPath = strRecPath;
            this.m_dom   = dom;
            // this.m_db = db;

            XmlNode root     = this.m_dom.DocumentElement;
            XmlNode nodeName = root.SelectSingleNode("name");

            if (nodeName != null)
            {
                this.Name = DomUtil.GetNodeText(nodeName).Trim();
            }

            // 用户所拥有的数据库
            this.aOwnerDbName = null;

            if (String.IsNullOrEmpty(this.Name) == false)
            {
                List <string> aOwnerDbName = null;

                nRet = dbs.GetOwnerDbNames(this.Name,
                                           out aOwnerDbName,
                                           out strError);
                if (nRet == -1)
                {
                    return(-1);
                }

                this.aOwnerDbName = aOwnerDbName;
            }



            XmlNode nodePassword = root.SelectSingleNode("password");

            if (nodePassword != null)
            {
                SHA1Password = DomUtil.GetNodeText(nodePassword).Trim();
            }

            XmlNode nodeRightsItem = root.SelectSingleNode("rightsItem");

            if (nodeRightsItem != null)
            {
                strError = "帐户记录为旧版本,根元素下已经不支持<rightsItem>元素。";
                return(-1);
            }

            // 没有<server>元素是否按出错处理
            this.m_nodeServer = root.SelectSingleNode("server");
            if (this.m_nodeServer == null)
            {
                strError = "帐户记录未定义<server>元素。";
                return(-1);
            }

            this.cfgRights = new CfgRights();
            // return:
            //      -1  出错
            //      0   成功
            nRet = this.cfgRights.Initial(this.m_nodeServer,
                                          out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            return(0);
        }
Пример #23
0
        void LoadXml()
        {
            listView_property.Items.Clear();

            string strErrorInfo = "";

            if (CfgFileName == "")
            {
                return;
            }

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.Load(CfgFileName);
            }
            catch (Exception ex)
            {
                strErrorInfo = ex.Message;
                goto ERROR1;
            }

            XmlNodeList propertyList = dom.SelectNodes("root/property");

            int i, j;

            for (i = 0; i < propertyList.Count; i++)
            {
                // 找到事项名字
                string strName = DomUtil.GetAttr(propertyList[i], "name");

                if (strName == "")
                {
                    continue;
                }

                // 按照语言找到comment字符串
                XmlNode nodeComment = null;

                if (Lang == "")
                {
                    nodeComment = propertyList[i].SelectSingleNode("comment");
                }
                else
                {
                    nodeComment = propertyList[i].SelectSingleNode("comment[@lang='" + Lang + "']");
                    if (nodeComment == null)                            // 按照指定的语言找,但是没有找到
                    {
                        nodeComment = propertyList[i].SelectSingleNode("comment");
                    }
                }

                string strComment = "";

                if (nodeComment != null)
                {
                    strComment = DomUtil.GetNodeText(nodeComment);
                }

                ListViewItem item =
                    new ListViewItem(strName,
                                     0);

                item.SubItems.Add(strComment);

                listView_property.Items.Add(item);
            }

            // 创建字符串数组,便于随时查重
            aPropertyName = new string[listView_property.Items.Count];
            for (j = 0; j < listView_property.Items.Count; j++)
            {
                aPropertyName[j] = listView_property.Items[j].Text;
            }


            // 创建语言数组
            XmlNodeList commentList = dom.SelectNodes("//property/comment");

            aLangName = new ArrayList();

            for (i = 0; i < propertyList.Count; i++)
            {
                // 找到事项名字
                string strLang = DomUtil.GetAttr(commentList[i], "lang");

                if (strLang == "")
                {
                    continue;
                }

                bool bFound = false;
                for (j = 0; j < aLangName.Count; j++)
                {
                    if (strLang == (string)aLangName[j])
                    {
                        bFound = true;
                        break;
                    }
                }

                if (bFound == false)
                {
                    aLangName.Add(strLang);
                }
            }


            return;

ERROR1:
            MessageBox.Show(strErrorInfo);
            return;
        }
Пример #24
0
        void LoadXml()
        {
            _langNameList = new List <string>();
            // _propertyNameList = new List<string>(); // = new string[listView_property.Items.Count];
            _propertyNameTable = new Hashtable();

            listView_property.Items.Clear();
            this.toolStripDropDownButton_quickSet.DropDownItems.Clear();

            string strError = "";

            if (string.IsNullOrEmpty(this.CfgFileName) == true)
            {
                return;
            }

            string[] filenames = this.CfgFileName.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            this.listView_property.BeginUpdate();
            foreach (string filename in filenames)
            {
                // 装载一个 XML 文件
                int nRet = LoadOneXml(filename,
                                      out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
                nRet = FillQuickSetMenu(filename,
                                        out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            this.listView_property.EndUpdate();

#if NO
            XmlDocument dom = new XmlDocument();

            try
            {
                dom.Load(CfgFileName);
            }
            catch (Exception ex)
            {
                strErrorInfo = ex.Message;
                goto ERROR1;
            }

            XmlNodeList propertyList = dom.SelectNodes("root/property");

            int i, j;
            for (i = 0; i < propertyList.Count; i++)
            {
                // 找到事项名字
                string strName = DomUtil.GetAttr(propertyList[i], "name");

                if (strName == "")
                {
                    continue;
                }

                // 按照语言找到comment字符串
                XmlNode nodeComment = null;

                if (Lang == "")
                {
                    nodeComment = propertyList[i].SelectSingleNode("comment");
                }
                else
                {
                    nodeComment = propertyList[i].SelectSingleNode("comment[@lang='" + Lang + "']");
                    if (nodeComment == null)                            // 按照指定的语言找,但是没有找到
                    {
                        nodeComment = propertyList[i].SelectSingleNode("comment");
                    }
                }

                string strComment = "";

                if (nodeComment != null)
                {
                    strComment = DomUtil.GetNodeText(nodeComment);
                }

                ListViewItem item =
                    new ListViewItem(strName,
                                     0);

                item.SubItems.Add(strComment);

                listView_property.Items.Add(item);
            }
#endif

            // 创建字符串数组,便于随时查重
            foreach (ListViewItem item in listView_property.Items)
            {
                // _propertyNameList[j] = listView_property.Items[j].Text;

                // _propertyNameList.Add(item.Text);

                _propertyNameTable[item.Text.ToLower()] = item;

                // 2017/4/20
                // 别名也要加入 hashtable
                ItemInfo info = (ItemInfo)item.Tag;
                if (info != null && info.AliasList != null)
                {
                    foreach (string alias in info.AliasList)
                    {
                        if (string.IsNullOrEmpty(alias) == false)
                        {
                            _propertyNameTable[alias.ToLower()] = item;
                        }
                    }
                }
            }

#if NO
            // 创建语言数组
            XmlNodeList commentList = dom.SelectNodes("//property/comment");

            aLangName = new ArrayList();

            for (i = 0; i < propertyList.Count; i++)
            {
                // 找到事项名字
                string strLang = DomUtil.GetAttr(commentList[i], "lang");

                if (strLang == "")
                {
                    continue;
                }

                bool bFound = false;
                for (j = 0; j < aLangName.Count; j++)
                {
                    if (strLang == (string)aLangName[j])
                    {
                        bFound = true;
                        break;
                    }
                }

                if (bFound == false)
                {
                    aLangName.Add(strLang);
                }
            }
#endif

            if (this.toolStripDropDownButton_quickSet.DropDownItems.Count == 0)
            {
                this.toolStripDropDownButton_quickSet.Visible = false;
            }
            else
            {
                this.toolStripDropDownButton_quickSet.Visible = true;
            }
            return;

ERROR1:
            MessageBox.Show(strError);
        }
Пример #25
0
        int MakeHtmlPage(XmlDocument dom,
                         out string strHtml,
                         out string strError)
        {
            strError = "";


            strHtml  = "";
            strHtml += "<html>";
            strHtml += "<head>";
            // strHtml += "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
            if (CssUrl != "")
            {
                strHtml += "<LINK href='" + this.CssUrl + "' type='text/css' rel='stylesheet'>";
            }

            strHtml += "</head>";

            strHtml += "<body>";

            strHtml += "<form method='post' action='" + this.ActionPrefix + "copymulti' >";

            XmlNamespaceManager mngr = new XmlNamespaceManager(dom.NameTable);

            mngr.AddNamespace("dprms", "http://dp2003.com/dprms");
            mngr.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
            mngr.AddNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#");
            // mngr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/");
            mngr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            mngr.AddNamespace("c2s", "http://dp2003.com/c2s");


            // 上级类号
            //    <rdf:Description rdf:about="broaderTerm">
            //        <subject>
            //            <rdf:value>A</rdf:value>
            //        </subject>
            //    </rdf:Description>

            /*
             * <rdf:Description rdf:about="broaderTerm">
             *  <item>
             *          <subject>上位分类号</subject>
             *          <rdfs:label>上位分类号标签,简体中文</rdfs:label>
             *          <rdfs:label xml:lang="en">上位分类号标签,英文</rdfs:label>
             *  </item>
             * </rdf:Description>
             */

            XmlNode node = null;

            node = dom.DocumentElement.SelectSingleNode(
                "rdf:Description[@rdf:about='broaderTerm']/c2s:item",
                mngr);
            if (node != null)
            {
                XmlNode child = node.SelectSingleNode("rdfs:label", mngr);

                string strTitle = DomUtil.GetNodeText(child);

                child = node.SelectSingleNode("c2s:subject", mngr);

                string strName = DomUtil.GetNodeText(child);

                strHtml += "<p class='parentlink'>";
                string strUrl = this.ActionPrefix + "navi/" + strName;
                strHtml += "上级类: <a class='parentlink' href='" + strUrl + "' >" + strName + "</a>" + " <span class='parentclassname'>" + strTitle + "</span></div>";

                // strHtml += "<div class='childrenclassline'><a class='childrenclasslink' href='" + strUrl + "' >" + strName + "</a>" + " <span class='childrenclassname'>" + strTitle + "</span></div>";


                strHtml += "</p>";

                strHtml += "<table width='100%' cellspacing='1' cellpadding='8' border='0'>";
            }

            /*
             *          string strParent = DomUtil.GetElementText(dom.DocumentElement,
             *  "rdf:Description[@rdf:about='broaderTerm']/c2s:item/c2s:subject",
             *                  mngr);
             */



            // 类号
            //    <rdf:Description rdf:about="entry">
            //        <subject>
            //            <rdf:value>A1</rdf:value>
            //            <rdfs:label>马克思、恩格斯著作</rdfs:label>
            //        </subject>
            //        <description>全集入此。</description>
            //    </rdf:Description>

            /*
             * <rdf:Description rdf:about="entry">
             *  <item>
             *          <subject>中图法分类号</subject>
             *          <rdfs:label>中图法分类标签,简体中文</rdfs:label>
             *          <rdfs:label xml:lang="en">中图法分类标签,英文</rdfs:label>
             *  </item>
             *  <description>中图法分类附注说明</description>
             * </rdf:Description>
             */
            node = dom.DocumentElement.SelectSingleNode(
                "rdf:Description[@rdf:about='entry']/c2s:item/c2s:subject",
                mngr);
            strHtml += "<tr class='classnumber'>";
            strHtml += "<td class='classnumbertitle' valign='bottom' nowrap align='right' width='20%'>类号</td>";

            strHtml += "<td class='classnumbertext' width='80%'>";

            if (node != null)
            {
                string strRefinement = DomUtil.GetAttr(node, "refinement");
                string strText       = RefinementText(strRefinement, DomUtil.GetNodeText(node));
                strHtml += strText;
            }

            strHtml += "</td>";
            strHtml += "</tr>";

            // 类名
            node = dom.DocumentElement.SelectSingleNode(
                "rdf:Description[@rdf:about='entry']/c2s:subject/rdfs:label", mngr);
            strHtml += "<tr class='classname'>";
            strHtml += "<td class='classnametitle'  nowrap align='right' width='20%'>类名</td>";

            strHtml += "<td class='classnametext' width='80%'>";

            if (node != null)
            {
                strHtml += DomUtil.GetNodeText(node);
            }

            strHtml += "</td>";
            strHtml += "</tr>";


            // --
            strHtml += "<tr class='seperator'>";
            strHtml += "<td class='seperator' colspan='2'></td>";
            strHtml += "</tr>";

            int i = 0;

            // 主题词若干
            //    <rdf:Description rdf:about="CTofLabel">
            //        <subject>
            //            <rdf:value>马恩著作</rdf:value>
            //        </subject>
            //	  </rdf:Description>

            /*
             * <rdf:Description rdf:about="entryDescriptor">
             *  <item>
             *          <subject>类名对应汉语主题词(用黑体显示)</subject>
             *          <subject refinement="subdivide">学科复分主题词</subject>
             *          <subject refinement="geographic">地区复分主题词</subject>
             *          <subject refinement="chronological">年代复分主题词</subject>
             *          <subject refinement="ethnic" rdf:resource="ethnic" />
             *          <!--
             *          前面的带限定词的subject值都用“-”连字符串起来,即判断refinement属性值为:
             *          “subdivide、geographic、chronological、chronological、ethnic”
             *          都用“-”连在不具refinement属性的subject值之后。
             *          -->
             *          <subject refinement="modifier">主题词修饰词</subject>
             *          <!--
             *          前面的带限定词的subject值都用“,”字符串起来,即判断refinement属性值为:
             *          “modifier”时,用“,”连在不具refinement属性的subject值之后。
             *          -->
             *          <subject refinement="bond">组配主题词</subject>
             *          <!--
             *          前面的带限定词的subject值都用“:”字符串起来,即判断refinement属性值为:
             *          “bond”时,用“:”连在不具refinement属性的subject值之后。
             *          -->
             *  </item>
             * </rdf:Description>
             */
            XmlNodeList nodes = dom.DocumentElement.SelectNodes(
                "rdf:Description[@rdf:about='entryDescriptor']/c2s:item",
                mngr);

            strHtml += "<tr class='subject'>";
            strHtml += "<td class='subjecttitle'  nowrap align='right'>主题词</td>";

            strHtml += "<td class='subjecttext'>";
            for (i = 0; i < nodes.Count; i++)
            {
                node = nodes[i];


                string strText     = "";
                string strTempHtml = "";
                // string strText = DomUtil.GetNodeText(node);
                GetSubjectText(node,
                               mngr,
                               out strText,
                               out strTempHtml);

                string strSelectUrl = this.ActionPrefix + "copyone/" + HttpUtility.UrlEncode(strText);

                string strImg = "<img src='" + Environment.CurrentDirectory + "/copy.gif" + "' border='0'>";

                // strHtml += "<div class='relatesubjectline'><input class='checkbox' name='subject' type='checkbox' value='" + DomUtil.GetNodeText(node) + "'/>" + " <a href='" + strSelectUrl + "' alt='选用主题词" + strText + "'>" + strImg + "</a>" + strTempHtml + "</div>";

                strHtml += "<div class='relatesubjectline'><input class='checkbox' name='subject' type='checkbox' value='" + node.InnerText + "'/>" + " <a href='" + strSelectUrl + "' alt='选用主题词" + strText + "'>" + strImg + "</a>" + strTempHtml + "</div>";
            }
            strHtml += "</td>";
            strHtml += "</tr>";

            // 相关主题词若干

            nodes = dom.DocumentElement.SelectNodes(
                "rdf:Description[@rdf:about='noteDescriptor']/c2s:item",
                mngr);
            strHtml += "<tr class='relatesubject'>";
            strHtml += "<td class='relatesubjecttitle'  nowrap align='right'>其他主题词</td>";

            strHtml += "<td class='relatesubjecttext'>";
            for (i = 0; i < nodes.Count; i++)
            {
                node = nodes[i];

                string strText     = "";
                string strTempHtml = "";
                // string strText = DomUtil.GetNodeText(node);
                GetSubjectText(node,
                               mngr,
                               out strText,
                               out strTempHtml);

                string strSelectUrl = this.ActionPrefix + "copyone/" + HttpUtility.UrlEncode(strText);

                string strImg = "<img src='" + Environment.CurrentDirectory + "/copy.gif" + "' border='0'>";


                // strHtml += "<div class='relatesubjectline'><input class='checkbox' name='subject' type='checkbox' value='" + DomUtil.GetNodeText(node) + "'/>" + " <a href='" + strSelectUrl + "' alt='选用主题词" + strText + "'>" + strImg + "</a>" + strTempHtml + "</div>";

                strHtml += "<div class='relatesubjectline'><input class='checkbox' name='subject' type='checkbox' value='" + node.InnerText + "'/>" + " <a href='" + strSelectUrl + "' alt='选用主题词" + strText + "'>" + strImg + "</a>" + strTempHtml + "</div>";   // ?
            }
            strHtml += "</td>";
            strHtml += "</tr>";

            // 命令按钮
            strHtml += "<tr class='command'>";
            strHtml += "<td class='command' colspan='2'>";
            strHtml += "<input type='submit' value='选用打勾的主题词' />";
            strHtml += "</td></tr>";


            // --
            strHtml += "<tr class='seperator'>";
            strHtml += "<td class='seperator' colspan='2'></td>";
            strHtml += "</tr>";


            // 下级类

            /*
             *  <rdf:Description rdf:about="narrowerTerm">
             *      <subject>
             *          <rdf:value>A11</rdf:value>
             *          <rdfs:label>选集、文集</rdfs:label>
             *      </subject>
             *      ...
             */
            /*
             * <rdf:Description rdf:about="narrowerTerm">
             *  <item>
             *          <subject>下位分类号</subject>
             *          <rdfs:label>下位分类号标签</rdfs:label>
             *          <rdfs:label xml:lang="en">下位分类号标签,英文</rdfs:label>
             *  </item>
             *  <item>
             *          <subject refinement="disable">下位分类号(停用)</subject>
             *          <rdfs:label>下位分类号标签</rdfs:label>
             *          <rdfs:label xml:lang="en">下位分类号标签,英文</rdfs:label>
             *  </item>
             * </rdf:Description>
             */

            nodes = dom.DocumentElement.SelectNodes(
                "rdf:Description[@rdf:about='narrowerTerm']/c2s:item",
                mngr);
            strHtml += "<tr class='childrenclass'>";
            strHtml += "<td class='childrenclasstitle'  nowrap align='right'>下级类</td>";

            strHtml += "<td class='childrenclasstext'>";
            for (i = 0; i < nodes.Count; i++)
            {
                node = nodes[i];

                XmlNode child = node.SelectSingleNode("rdfs:label", mngr);

                string strTitle = DomUtil.GetNodeText(child);

                child = node.SelectSingleNode("c2s:subject", mngr);

                string strName = DomUtil.GetNodeText(child);


                string strUrl = this.ActionPrefix + "navi/" + strName;

                strHtml += "<div class='childrenclassline'><a class='childrenclasslink' href='" + strUrl + "' >" + strName + "</a>" + " <span class='childrenclassname'>" + strTitle + "</span></div>";
            }
            strHtml += "</td>";
            strHtml += "</tr>";

            strHtml += "</table>";

            strHtml += "</form>";
            strHtml += "</body></html>";


            return(0);
        }
Пример #26
0
/*
 *      <Field name='###' length='24' mandatory='yes' repeatable='no'>
 *              <Property>
 *                      <Label xml:lang='en'>RECORD IDENTIFIER</Label>
 *                      <Label xml:lang='cn'>头标区</Label>
 *                      <Help xml:lang='cn'>帮助信息</Help>
 *              </Property>
 *              <Char name='0/5'>
 *              </Char>
 *              ....
 *      </Field>
 */
        // 初始化TemplateRoot对象
        // parameters:
        //		fieldNode	Field节点
        //		strLang	语言版本
        //		strError	出错信息
        // return:
        //		-1	失败
        //		0	不是定长字段
        //		1	成功
        public int Initial(XmlNode node,
                           string strLang,
                           out string strError)
        {
            strError = "";

            Debug.Assert(node != null, "调用错误,node不能为null");

            this.m_fieldNode = node;
            this.m_strLang   = strLang;


            this.m_strName = DomUtil.GetAttr(node, "name");
            if (this.m_strName == "")
            {
                strError = "<" + node.Name + ">元素的name属性可能不存在或者值为空,配置文件不合法。";
                Debug.Assert(false, strError);
                return(-1);
            }

            XmlNode propertyNode = node.SelectSingleNode("Property");

            if (propertyNode == null)
            {
                // TODO: 需要显示更详细的信息
                XmlNode temp = node.Clone();
                while (temp.ChildNodes.Count > 0)
                {
                    temp.RemoveChild(temp.ChildNodes[0]);
                }
                strError = "在 " + temp.OuterXml + " 元素下级未定义<Property>元素,配置文件不合法.";
                // strError = "在<" + node.Name + ">元素下级未定义<Property>元素,配置文件不合法.";
                // Debug.Assert(false,strError);
                return(-1);
            }

            XmlNodeList charList = node.SelectNodes("Char");

            // 没有<Char>元素,不是字长字段或子字段
            if (charList.Count == 0)
            {
                return(0);
            }
#if NO
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
            nsmgr.AddNamespace("xml", Ns.xml);
            XmlNode labelNode = propertyNode.SelectSingleNode("Label[@xml:lang='" + strLang + "']", nsmgr);
            if (labelNode == null)
            {
                this.m_strLabel = "????????";
                Debug.Assert(false, "名称为'" + this.m_strName + "'的<" + node.Name + ">元素未定义Label的'" + strLang + "'语言版本的值");
            }
            this.m_strLabel = DomUtil.GetNodeText(labelNode);
#endif
            // 从一个元素的下级的多个<strElementName>元素中, 提取语言符合的XmlNode的InnerText
            // parameters:
            //      bReturnFirstNode    如果找不到相关语言的,是否返回第一个<strElementName>
            this.m_strLabel = DomUtil.GetXmlLangedNodeText(
                strLang,
                propertyNode,
                "Label",
                true);

            if (this.Lines == null)
            {
                this.Lines = new ArrayList();
            }
            else
            {
                this.Lines.Clear();
            }
            foreach (XmlNode charNode in charList)
            {
                TemplateLine line = new TemplateLine(this,
                                                     charNode,
                                                     strLang);
                this.Lines.Add(line);
            }

            return(1);
        }
Пример #27
0
        int LoadFieldNames(out string strError)
        {
            strError = "";

            this.listView_fieldNameList.Items.Clear();

            if (this.MarcDefDom == null)
            {
                return(0);
            }

            XmlNodeList nodes = this.MarcDefDom.DocumentElement.SelectNodes("Field");

            for (int i = 0; i < nodes.Count; i++)
            {
                XmlNode node = nodes[i];

                string strName = DomUtil.GetAttr(node, "name");

                if (strName == "###")
                {
                    continue;   // 跳过头标区
                }
                string strLabel = "";

                XmlNode nodeProperty = node.SelectSingleNode("Property");
                if (nodeProperty != null)
                {
                    // 从一个元素的下级的多个<strElementName>元素中, 提取语言符合的XmlNode的InnerText
                    // parameters:
                    //      bReturnFirstNode    如果找不到相关语言的,是否返回第一个<strElementName>
                    strLabel = DomUtil.GetXmlLangedNodeText(
                        this.Lang,
                        nodeProperty,
                        "Label",
                        true);
                }

#if NO
                XmlNode nodeLabel = null;
                try
                {
                    if (this.Lang == "")
                    {
                        nodeLabel = node.SelectSingleNode("Property/Label");
                    }
                    else
                    {
                        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
                        nsmgr.AddNamespace("xml", Ns.xml);
                        nodeLabel = node.SelectSingleNode("Property/Label[@xml:lang='" + this.Lang + "']", nsmgr);
                    }
                }
                catch // 防止字段名中不合法字符用于xpath抛出异常
                {
                    nodeLabel = null;
                }

                string strLabel = "";
                if (nodeLabel != null)
                {
                    strLabel = DomUtil.GetNodeText(nodeLabel);
                }
#endif

                ListViewItem item = new ListViewItem(strName);
                item.SubItems.Add(strLabel);

                this.listView_fieldNameList.Items.Add(item);
            }

            return(0);
        }
Пример #28
0
        // 将MARCXML格式的xml记录转换为marc机内格式字符串
        // 注意,如果strXml内容为空,本函数会报错。最好在进入函数前进行判断。
        // parameters:
        //		bWarning	        ==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
        //		strMarcSyntax	    指示marc语法,如果=="",则自动识别
        //		strOutMarcSyntax	[out] 返回记录的 MARC 格式。如果 strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
        //      strFragmentXml      [out] 返回删除 <leader> <controlfield> <datafield> 以后的 XML 代码。注意,包含 <record> 元素
        public static int Xml2Marc(string strXml,
                                   Xml2MarcStyle style,
                                   string strMarcSyntax,
                                   out string strOutMarcSyntax,
                                   out string strMARC,
                                   out string strFragmentXml,
                                   out string strError)
        {
            strMARC          = "";
            strError         = "";
            strOutMarcSyntax = "";
            strFragmentXml   = "";

            // 2013/9/25
            if (string.IsNullOrEmpty(strXml) == true)
            {
                return(0);
            }

            Debug.Assert(string.IsNullOrEmpty(strXml) == false, "");

            bool bWarning           = (style & Xml2MarcStyle.Warning) != 0;
            bool bOutputFragmentXml = (style & Xml2MarcStyle.OutputFragmentXml) != 0;

            XmlDocument dom = new XmlDocument();

            dom.PreserveWhitespace = true;  // 在意空白符号
            try
            {
                dom.LoadXml(strXml);
            }
            catch (Exception ex)
            {
                strError = "Xml2Marc() strXml 加载 XML 到 DOM 时出错: " + ex.Message;
                return(-1);
            }

            // 取MARC根
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

            nsmgr.AddNamespace("unimarc", Ns.unimarcxml);
            nsmgr.AddNamespace("usmarc", Ns.usmarcxml);

            XmlNode root = null;

            if (string.IsNullOrEmpty(strMarcSyntax) == true)
            {
                // '//'保证了无论MARC的根在何处,都可以正常取出。
                root = dom.DocumentElement.SelectSingleNode("//unimarc:record", nsmgr);
                if (root == null)
                {
                    root = dom.DocumentElement.SelectSingleNode("//usmarc:record", nsmgr);

                    if (root == null)
                    {
                        // TODO: 是否要去除所有 MARC 相关元素
                        if (bOutputFragmentXml)
                        {
                            strFragmentXml = dom.DocumentElement.OuterXml;
                        }
                        return(0);
                    }

                    strMarcSyntax = "usmarc";
                }
                else
                {
                    strMarcSyntax = "unimarc";
                }
            }
            else
            {
                // 2012/1/8
                if (strMarcSyntax != null)
                {
                    strMarcSyntax = strMarcSyntax.ToLower();
                }

                if (strMarcSyntax != "unimarc" &&
                    strMarcSyntax != "usmarc")
                {
                    strError = "无法识别 MARC格式 '" + strMarcSyntax + "' 。目前仅支持 unimarc 和 usmarc 两种格式";
                    return(-1);
                }

                root = dom.DocumentElement.SelectSingleNode("//" + strMarcSyntax + ":record", nsmgr);
                if (root == null)
                {
                    // TODO: 是否要去除所有 MARC 相关元素
                    if (bOutputFragmentXml)
                    {
                        strFragmentXml = dom.DocumentElement.OuterXml;
                    }
                    return(0);
                }
            }

            StringBuilder strMarc = new StringBuilder(4096);

            strOutMarcSyntax = strMarcSyntax;

            XmlNode leader = root.SelectSingleNode(strMarcSyntax + ":leader", nsmgr);

            if (leader == null)
            {
                strError += "缺<" + strMarcSyntax + ":leader>元素\r\n";
                if (bWarning == false)
                {
                    return(-1);
                }
                else
                {
                    strMarc.Append("012345678901234567890123");
                }
            }
            else // 正常情况
            {
                // string strLeader = DomUtil.GetNodeText(leader);
                // GetNodeText()会自动Trim(),会导致头标区内容末尾丢失字符
                string strLeader = leader.InnerText;
                if (strLeader.Length != 24)
                {
                    strError += "<" + strMarcSyntax + ":leader>元素内容应为24字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strLeader.Length < 24)
                        {
                            strLeader = strLeader.PadRight(24, ' ');
                        }
                        else
                        {
                            strLeader = strLeader.Substring(0, 24);
                        }
                    }
                }

                strMarc.Append(strLeader);

                // 从 DOM 中删除 leader 元素
                if (bOutputFragmentXml)
                {
                    leader.ParentNode.RemoveChild(leader);
                }
            }

            int i = 0;

            // 固定长字段
            XmlNodeList controlfields = root.SelectNodes(strMarcSyntax + ":controlfield", nsmgr);

            for (i = 0; i < controlfields.Count; i++)
            {
                XmlNode field  = controlfields[i];
                string  strTag = DomUtil.GetAttr(field, "tag");
                if (strTag.Length != 3)
                {
                    strError += "<" + strMarcSyntax + ":controlfield>元素的tag属性值'" + strTag + "'应当为3字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strTag.Length < 3)
                        {
                            strTag = strTag.PadRight(3, '*');
                        }
                        else
                        {
                            strTag = strTag.Substring(0, 3);
                        }
                    }
                }

                string strContent = DomUtil.GetNodeText(field);

                strMarc.Append(strTag + strContent + new string(MarcUtil.FLDEND, 1));

                // 从 DOM 中删除
                if (bOutputFragmentXml)
                {
                    field.ParentNode.RemoveChild(field);
                }
            }

            // 可变长字段
            XmlNodeList datafields = root.SelectNodes(strMarcSyntax + ":datafield", nsmgr);

            for (i = 0; i < datafields.Count; i++)
            {
                XmlNode field  = datafields[i];
                string  strTag = DomUtil.GetAttr(field, "tag");
                if (strTag.Length != 3)
                {
                    strError += "<" + strMarcSyntax + ":datafield>元素的tag属性值'" + strTag + "'应当为3字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strTag.Length < 3)
                        {
                            strTag = strTag.PadRight(3, '*');
                        }
                        else
                        {
                            strTag = strTag.Substring(0, 3);
                        }
                    }
                }

                string strInd1 = DomUtil.GetAttr(field, "ind1");
                if (strInd1.Length != 1)
                {
                    strError += "<" + strMarcSyntax + ":datalfield>元素的ind1属性值'" + strInd1 + "'应当为1字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strInd1.Length < 1)
                        {
                            strInd1 = '*'.ToString();
                        }
                        else
                        {
                            strInd1 = strInd1[0].ToString();
                        }
                    }
                }

                string strInd2 = DomUtil.GetAttr(field, "ind2");
                if (strInd2.Length != 1)
                {
                    strError += "<" + strMarcSyntax + ":datalfield>元素的indi2属性值'" + strInd2 + "'应当为1字符\r\n";
                    if (bWarning == false)
                    {
                        return(-1);
                    }
                    else
                    {
                        if (strInd2.Length < 1)
                        {
                            strInd2 = '*'.ToString();
                        }
                        else
                        {
                            strInd2 = strInd2[0].ToString();
                        }
                    }
                }

                // string strContent = DomUtil.GetNodeText(field);
                XmlNodeList   subfields  = field.SelectNodes(strMarcSyntax + ":subfield", nsmgr);
                StringBuilder strContent = new StringBuilder(4096);
                for (int j = 0; j < subfields.Count; j++)
                {
                    XmlNode subfield = subfields[j];

                    XmlAttribute attr = subfield.Attributes["code"];
#if NO
                    string strCode = DomUtil.GetAttr(subfield, "code");
                    if (strCode.Length != 1)
                    {
                        strError += "<" + strMarcSyntax + ":subfield>元素的code属性值'" + strCode + "'应当为1字符\r\n";
                        if (bWarning == false)
                        {
                            return(-1);
                        }
                        else
                        {
                            if (strCode.Length < 1)
                            {
                                strCode = '*'.ToString();
                            }
                            else
                            {
                                strCode = strCode[0].ToString();
                            }
                        }
                    }

                    string strSubfieldContent = DomUtil.GetNodeText(subfield);

                    strContent += new string(MarcUtil.SUBFLD, 1) + strCode + strSubfieldContent;
#endif
                    if (attr == null)
                    {
                        // 前导纯文本
                        strContent.Append(DomUtil.GetNodeText(subfield));
                        continue;   //  goto CONTINUE; BUG!!!
                    }

                    string strCode = attr.Value;
                    if (strCode.Length != 1)
                    {
                        strError += "<" + strMarcSyntax + ":subfield>元素的 code 属性值 '" + strCode + "' 应当为1字符\r\n";
                        if (bWarning == false)
                        {
                            return(-1);
                        }
                        else
                        {
                            if (strCode.Length < 1)
                            {
                                strCode = "";   // '*'.ToString();
                            }
                            else
                            {
                                strCode = strCode[0].ToString();
                            }
                        }
                    }

                    string strSubfieldContent = DomUtil.GetNodeText(subfield);
                    strContent.Append(new string(MarcUtil.SUBFLD, 1) + strCode + strSubfieldContent);
                }

                strMarc.Append(strTag + strInd1 + strInd2 + strContent + new string(MarcUtil.FLDEND, 1));

CONTINUE:
                // 从 DOM 中删除
                if (bOutputFragmentXml)
                {
                    field.ParentNode.RemoveChild(field);
                }
            }

            strMARC = strMarc.ToString();
            if (bOutputFragmentXml)
            {
                strFragmentXml = dom.DocumentElement.OuterXml;
            }
            return(0);
        }
Пример #29
0
        // 功能: 检查检索单元match,relation,dataType三项的关系
        // 如果存在矛盾:
        // 如果处理警告的级别为0,会给检索单元node加warning信息,不自动更正,返回-1,
        // 如果级别为非0(应该固定为1),则系统自动更加,并在更正的地方加comment信息,返回0
        // 不存在矛盾:返回0
        // parameter:
        //		nodeItem    检索单元节点
        // return:
        //		0   正常(如果有矛盾,但由于处理警告级别为非0,自动更正,也返回0)
        //		-1  存在矛盾,且警告级别为0
        public int ProcessRelation(XmlNode nodeItem)
        {
            //匹配方式
            XmlNode nodeMatch = nodeItem.SelectSingleNode("match");
            string  strMatch  = "";

            if (nodeMatch != null)
            {
                strMatch = DomUtil.GetNodeText(nodeMatch).Trim();
            }


            if (strMatch == "")
            {
                DomUtil.SetNodeText(nodeMatch, "left");
                DomUtil.SetAttr(nodeMatch, "comment",
                                "原为" + strMatch + ",修改为缺省的left");
            }

            //关系操作符
            XmlNode nodeRelation = nodeItem.SelectSingleNode("relation");
            string  strRelation  = "";

            if (nodeRelation != null)
            {
                strRelation = DomUtil.GetNodeText(nodeRelation).Trim();
            }
            strRelation = QueryUtil.ConvertLetterToOperator(strRelation);

            //数据类型
            XmlNode nodeDataType = nodeItem.SelectSingleNode("dataType");
            string  strDataType  = "";

            if (nodeDataType != null)
            {
                strDataType = DomUtil.GetNodeText(nodeDataType).Trim();
            }

            if (strDataType == "number")
            {
                if (strMatch == "left" || strMatch == "right")
                {
                    //当dataType值为number时,match值为left或right或
                    //修改可以自动有两种:
                    //1.将left换成exact;
                    //2.将dataType设为string,
                    //我们先按dataType优先,将match改为exact

                    if (m_nWarningLevel == 0)
                    {
                        DomUtil.SetAttr(nodeItem,
                                        "warningInfo",
                                        "匹配方式为值‘" + strMatch + "'与数据类型的值'" + strDataType + "'矛盾,且处理警告级别为0,自动不进行自动更正");

                        return(-1);
                    }
                    else
                    {
                        DomUtil.SetNodeText(nodeMatch, "exact");
                        DomUtil.SetAttr(nodeMatch,
                                        "comment",
                                        "原为" + strMatch + ",由于与数据类型'" + strDataType + "'矛盾,修改为exact");
                    }
                }
            }

            if (strDataType == "string")
            {
                //如果dataType值为string,
                //match值为left或right,且relation值不等于"="

                //出现矛盾,(我们认为match的left或rgith值,只与relation的"="值匹配)
                //有两种裁决办法:
                //1.将relation值改为"="号;
                //2.将match值由left或right改为exact
                //目前按1进行修改

                if ((strMatch == "left" || strMatch == "right") && strRelation != "=")
                {
                    //根据处理警告级别做不同的处理
                    if (m_nWarningLevel == 0)
                    {
                        DomUtil.SetAttr(nodeItem,
                                        "warningInfo",
                                        "关系操作符'" + strRelation + "'与数据类型" + strDataType + "和匹配方式'" + strMatch + "'不匹配");
                        return(-1);
                    }
                    else
                    {
                        DomUtil.SetNodeText(nodeRelation, "=");
                        DomUtil.SetAttr(nodeRelation,
                                        "comment",
                                        "原为" + strRelation + ",由于与数据类型'" + strDataType + "和匹配方式'" + strMatch + "'不匹配,修改为'='");
                    }
                }
            }
            return(0);
        }