Exemplo n.º 1
0
        // 将种记录数据从XML格式转换为HTML格式
        public int ConvertBiblioXmlToHtml(
            string strFilterFileName,
            string strBiblioXml,
            string strRecPath,
            out string strBiblio,
            out KeyValueCollection result_params,
            out string strError)
        {
            strBiblio     = "";
            strError      = "";
            result_params = null;

            OpacApplication app = this;

            FilterHost host = new FilterHost();

            host.RecPath      = strRecPath;
            host.App          = this;
            host.ResultParams = new KeyValueCollection();

            // 如果必要,转换为MARC格式,调用filter

            string strOutMarcSyntax = "";
            string strMarc          = "";
            // 将MARCXML格式的xml记录转换为marc机内格式字符串
            // parameters:
            //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
            //		strMarcSyntax	指示marc语法,如果=="",则自动识别
            //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
            int nRet = MarcUtil.Xml2Marc(strBiblioXml,
                                         true,
                                         "", // this.CurMarcSyntax,
                                         out strOutMarcSyntax,
                                         out strMarc,
                                         out strError);

            if (nRet == -1)
            {
                goto ERROR1;
            }

            LoanFilterDocument filter = null;

            nRet = app.PrepareMarcFilter(
                host,
                strFilterFileName,
                out filter,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            try
            {
                nRet = filter.DoRecord(null,
                                       strMarc,
                                       0,
                                       out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                strBiblio     = host.ResultString;
                result_params = host.ResultParams;
            }
            catch (Exception ex)
            {
                strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                // 归还对象
                filter.FilterHost = null;  // 2016/1/23
                app.Filters.SetFilter(strFilterFileName, filter);
            }

            return(0);

ERROR1:
            return(-1);
        }
Exemplo n.º 2
0
        void GetVolume(string strBiblioRecPath,
                       out string strVolume,
                       out string strPrice)
        {
            strVolume = "";
            strPrice  = "";

            string strXml = (string)this._biblioXmlTable[strBiblioRecPath];

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

            string strOutMarcSyntax = "";
            string strMARC          = "";
            string strError         = "";
            int    nRet             = MarcUtil.Xml2Marc(strXml,
                                                        false,
                                                        "",
                                                        out strOutMarcSyntax,
                                                        out strMARC,
                                                        out strError);

            if (nRet == -1)
            {
                return;
            }
            if (string.IsNullOrEmpty(strMARC) == true)
            {
                return;
            }
            MarcRecord record = new MarcRecord(strMARC);

            if (strOutMarcSyntax == "unimarc")
            {
                string h = record.select("field[@name='200']/subfield[@name='h']").FirstContent;
                string i = record.select("field[@name='200']/subfield[@name='i']").FirstContent;
                if (string.IsNullOrEmpty(h) == false && string.IsNullOrEmpty(i) == false)
                {
                    strVolume = h + " . " + i;
                }
                else
                {
                    if (h == null)
                    {
                        h = "";
                    }
                    strVolume = h + i;
                }

                strPrice = record.select("field[@name='010']/subfield[@name='d']").FirstContent;
            }
            else if (strOutMarcSyntax == "usmarc")
            {
                string n = record.select("field[@name='200']/subfield[@name='n']").FirstContent;
                string p = record.select("field[@name='200']/subfield[@name='p']").FirstContent;
                if (string.IsNullOrEmpty(n) == false && string.IsNullOrEmpty(p) == false)
                {
                    strVolume = n + " . " + p;
                }
                else
                {
                    if (n == null)
                    {
                        n = "";
                    }
                    strVolume = n + p;
                }

                strPrice = record.select("field[@name='020']/subfield[@name='c']").FirstContent;
            }
            else
            {
            }
        }
Exemplo n.º 3
0
        // 获得MARC记录
        // parameters:
        //      bAddField901    是否加入901字段?
        // return:
        //      -1  error
        //      0   not found
        //      1   found
        static int GetIso2709Record(
            DigitalPlatform.LibraryClient.localhost.Record dp2library_record,
            List <string> elementSetNames,
            bool bAddField901,
            string strRemoveFields,
            Encoding marcRecordEncoding,
            out byte[] baIso2709,
            out string strError)
        {
            baIso2709 = null;
            strError  = "";

            string strMarcSyntax = "";

            // 转换为机内格式
            int nRet = MarcUtil.Xml2Marc(dp2library_record.RecordBody.Xml,
                                         true,
                                         strMarcSyntax,
                                         out string strOutMarcSyntax,
                                         out string strMarc,
                                         out strError);

            if (nRet == -1)
            {
                strError = "XML转换到MARC记录时出错: " + strError;
                return(-1);
            }

            // 去掉记录中的 997/998
            MarcRecord record = new MarcRecord(strMarc);

            if (string.IsNullOrEmpty(strRemoveFields) == false)
            {
                List <string> field_names = StringUtil.SplitList(strRemoveFields);
                foreach (string field_name in field_names)
                {
                    if (field_name.Length != 3)
                    {
                        strError = "removeFields 定义里面出现了不是 3 字符的字段名('" + strRemoveFields + "')";
                        return(-1);
                    }
                    record.select("field[@name='" + field_name + "']").detach();
                }
            }

            if (bAddField901 == true)
            {
                // 901  $p记录路径$t时间戳
                string strContent = "$p" + dp2library_record.Path
                                    + "$t" + ByteArray.GetHexTimeStampString(dp2library_record.RecordBody.Timestamp);
                record.setFirstField("901", "  ", strContent.Replace("$", MarcQuery.SUBFLD), "  ");
            }
            strMarc = record.Text;

            // 转换为ISO2709
            nRet = MarcUtil.CvtJineiToISO2709(
                strMarc,
                strOutMarcSyntax,
                marcRecordEncoding,
                out baIso2709,
                out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            return(1);
        }
Exemplo n.º 4
0
        /*
         * https://en.wikipedia.org/wiki/International_Standard_Bibliographic_Description#Structure_of_an_ISBD_record
         * ISBD Structure
         * 0: Content form and media type area
         * 1: Title and statement of responsibility area, consisting of
         * 1.1 Title proper
         * 1.2 Parallel title
         * 1.3 Other title information
         * 1.4 Statement of responsibility
         * 2: Edition area
         * 3: Material or type of resource specific area (e.g., the scale of a map or the numbering of a periodical)
         * 4: Publication, production, distribution, etc., area
         * 5: Material description area (e.g., number of pages in a book or number of CDs issued as a unit)
         * 6: Series area
         * 7: Notes area
         * 8: Resource identifier and terms of availability area (e.g., ISBN, ISSN)
         *
         * 按照上述结构名称,大项的 type 命名为:
         * content_form_area
         * title_area
         * edition_area
         * material_specific_area
         * publication_area
         * material_description_area
         * series_area
         * notes_area
         * resource_identifier_area
         * */
        // 将书目 XML 转换为 table 格式
        // parameters:
        //      strBiblioXml    XML记录,或者 MARC 记录
        //      strSyntax   MARC格式 usmarc/unimarc。如果strBiblioXml 第一字符为 '<' 则本参数可以为空
        //      strStyle    创建风格。
        public int ConvertBiblioXmlToTable(
            string strBiblioXml,
            string strSyntax,
            string strRecPath,
            string strStyle,
            out string strBiblio,
            out string strError)
        {
            strBiblio = "";
            strError  = "";
            int nRet = 0;

            string strMarc = "";

            if (string.IsNullOrEmpty(strBiblioXml) == false &&
                strBiblioXml[0] == '<')
            {
                // 如果必要,转换为MARC格式,调用filter

                // string strOutMarcSyntax = "";
                // 将MARCXML格式的xml记录转换为marc机内格式字符串
                // parameters:
                //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                nRet = MarcUtil.Xml2Marc(strBiblioXml,
                                         true,
                                         "", // this.CurMarcSyntax,
                                         out strSyntax,
                                         out strMarc,
                                         out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
            }
            else
            {
                strMarc = strBiblioXml;
            }

            {
                string strFilterFileName = Path.Combine(this.DataDir, "cfgs/table_" + strSyntax + ".fltx");
                if (File.Exists(strFilterFileName) == true)
                {
                    nRet = this.ConvertBiblioXmlToHtml(
                        strFilterFileName,
                        strBiblioXml,
                        null,
                        strRecPath,
                        strStyle,
                        out strBiblio,
                        out strError);
                    if (nRet == -1)
                    {
                        return(-1);
                    }
                }
                else
                {
                    List <NameValueLine> results = null;
                    if (strSyntax == "usmarc")
                    {
                        nRet = MarcTable.ScriptMarc21(
                            strRecPath,
                            strMarc,
                            strStyle,
                            out results,
                            out strError);
                        if (nRet == -1)
                        {
                            return(-1);
                        }
                    }
                    else if (strSyntax == "unimarc")
                    {
                        nRet = MarcTable.ScriptUnimarc(
                            strRecPath,
                            strMarc,
                            strStyle,
                            out results,
                            out strError);
                        if (nRet == -1)
                        {
                            return(-1);
                        }
                    }
                    else
                    {
                        strError = "无法识别的 MARC 格式 '" + strSyntax + "'";
                        return(-1);
                    }

                    strBiblio = NameValueLine.BuildTableXml(results);
                    return(0);
                }
            }

            return(0);
        }
Exemplo n.º 5
0
        // 将种记录数据从XML格式转换为HTML格式
        // parameters:
        //      strBiblioXml    XML记录,或者 MARC 记录
        //      strSyntax   MARC格式 usmarc/unimarc。如果strBiblioXml 第一字符为 '<' 则本参数可以为空
        public int ConvertBiblioXmlToHtml(
            string strFilterFileName,
            string strBiblioXml,
            string strSyntax,
            string strRecPath,
            string strStyle,
            out string strBiblio,
            out string strError)
        {
            strBiblio = "";
            strError  = "";
            int nRet = 0;

            LibraryApplication app = this;

            FilterHost host = new FilterHost();

            host.RecPath = strRecPath;
            host.Style   = strStyle;
            host.App     = this;

            string strMarc = "";

            if (string.IsNullOrEmpty(strBiblioXml) == false &&
                strBiblioXml[0] == '<')
            {
                // 如果必要,转换为MARC格式,调用filter

                // string strOutMarcSyntax = "";
                // 将MARCXML格式的xml记录转换为marc机内格式字符串
                // parameters:
                //		bWarning	==true, 警告后继续转换,不严格对待错误; = false, 非常严格对待错误,遇到错误后不继续转换
                //		strMarcSyntax	指示marc语法,如果=="",则自动识别
                //		strOutMarcSyntax	out参数,返回marc,如果strMarcSyntax == "",返回找到marc语法,否则返回与输入参数strMarcSyntax相同的值
                nRet = MarcUtil.Xml2Marc(strBiblioXml,
                                         true,
                                         "", // this.CurMarcSyntax,
                                         out strSyntax,
                                         out strMarc,
                                         out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            else
            {
                strMarc = strBiblioXml;
            }

            LoanFilterDocument filter = null;

            nRet = app.PrepareMarcFilter(
                // host,
                strFilterFileName,
                out filter,
                out strError);
            if (nRet == -1)
            {
                goto ERROR1;
            }

            filter.FilterHost = host;

            try
            {
                nRet = filter.DoRecord(null,
                                       strMarc,
                                       strSyntax,
                                       0,
                                       out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }

                strBiblio = host.ResultString;
            }
            catch (Exception ex)
            {
                strError = "filter.DoRecord error: " + ExceptionUtil.GetDebugText(ex);
                return(-1);
            }
            finally
            {
                // 2012/3/28
                filter.FilterHost = null;   // 脱钩

                // 归还对象
                app.Filters.SetFilter(strFilterFileName, filter);
            }

            return(0);

ERROR1:
            return(-1);
        }
Exemplo n.º 6
0
        // 获得一条MARC/XML记录
        // return:
        //      -1  error 包括not found
        //      0   found
        //      1   为诊断记录
        public int GetOneRecord(
            string strStyle,
            int nTest,
            string strPathParam,
            string strParameters,   // bool bHilightBrowseLine,
            out string strSavePath,
            out string strRecord,
            out string strXmlFragment,
            out string strOutStyle,
            out byte[] baTimestamp,
            out long lVersion,
            out DigitalPlatform.Z3950.Record record,
            out Encoding currrentEncoding,
            out LoginInfo logininfo,
            out string strError)
        {
            strXmlFragment   = "";
            strRecord        = "";
            record           = null;
            strError         = "";
            currrentEncoding = this.CurrentEncoding;
            baTimestamp      = null;
            strSavePath      = "";
            strOutStyle      = "marc";
            logininfo        = new LoginInfo();
            lVersion         = 0;

            // 防止重入
            if (m_bInSearch == true)
            {
                strError = "当前窗口正在被一个未结束的长操作使用,无法获得记录。请稍后再试。";
                return(-1);
            }

            if (strStyle != "marc" && strStyle != "xml")
            {
                strError = "DupForm只支持获取MARC格式记录和xml格式记录,不支持 '" + strStyle + "' 格式的记录";
                return(-1);
            }
            int nRet = 0;

            int    index        = -1;
            string strPath      = "";
            string strDirection = "";

            nRet = Global.ParsePathParam(strPathParam,
                                         out index,
                                         out strPath,
                                         out strDirection,
                                         out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            if (index == -1)
            {
                strError = "暂时不支持没有 index 的用法";
                return(-1);
            }

            bool bHilightBrowseLine = StringUtil.IsInList("hilight_browse_line", strParameters);

            if (index >= this.listView_browse.Items.Count)
            {
                strError = "越过结果集尾部";
                return(-1);
            }
            ListViewItem curItem = this.listView_browse.Items[index];

            if (bHilightBrowseLine == true)
            {
                // 修改listview中事项的选定状态
                for (int i = 0; i < this.listView_browse.SelectedItems.Count; i++)
                {
                    this.listView_browse.SelectedItems[i].Selected = false;
                }

                curItem.Selected = true;
                curItem.EnsureVisible();
            }

            string strPurePath   = curItem.Text;
            string strServerName = this.LibraryServerName;

            strPath = strPurePath + "@" + this.LibraryServerName;

            strSavePath = this.CurrentProtocol + ":" + strPath;

            // 拉上一个dp2检索窗,好办事
            dp2SearchForm dp2_searchform = this.GetDp2SearchForm();

            if (dp2_searchform == null)
            {
                strError = "没有打开的dp2检索窗,无法GetOneRecordSyntax()";
                return(-1);
            }

            // 获得server url
            string strServerUrl = dp2_searchform.GetServerUrl(strServerName);

            if (strServerUrl == null)
            {
                strError = "没有找到服务器名 '" + strServerName + "' 对应的URL";
                return(-1);
            }

            this.Channel = this.Channels.GetChannel(strServerUrl);

            stop.OnStop += new StopEventHandler(this.DoStop);
            stop.Initial("正在初始化浏览器组件 ...");
            stop.BeginLoop();

            this.Update();
            this.MainForm.Update();

            try
            {
                stop.SetMessage("正在装入书目记录 " + strPath + " ...");

                string[] formats = null;
                formats    = new string[1];
                formats[0] = "xml";

                string[] results = null;

                long lRet = Channel.GetBiblioInfos(
                    stop,
                    strPurePath,
                    "",
                    formats,
                    out results,
                    out baTimestamp,
                    out strError);
                if (lRet == 0)
                {
                    strError = "路径为 '" + strPath + "' 的书目记录没有找到 ...";
                    goto ERROR1;   // not found
                }

                if (lRet == -1)
                {
                    goto ERROR1;
                }

                // this.BiblioTimestamp = baTimestamp;

                if (results == null)
                {
                    strError = "results == null";
                    goto ERROR1;
                }
                if (results.Length != formats.Length)
                {
                    strError = "result.Length != formats.Length";
                    goto ERROR1;
                }

                string strXml = results[0];

                if (strStyle == "marc")
                {
                    string strMarcSyntax    = "";
                    string strOutMarcSyntax = "";
                    // 从数据记录中获得MARC格式
                    nRet = MarcUtil.Xml2Marc(strXml,
                                             true,
                                             strMarcSyntax,
                                             out strOutMarcSyntax,
                                             out strRecord,
                                             out strError);
                    if (nRet == -1)
                    {
                        strError = "XML转换到MARC记录时出错: " + strError;
                        goto ERROR1;
                    }


                    // 获得书目以外的其它XML片断
                    nRet = dp2SearchForm.GetXmlFragment(strXml,
                                                        out strXmlFragment,
                                                        out strError);
                    if (nRet == -1)
                    {
                        goto ERROR1;
                    }
                }
                else
                {
                    strRecord   = strXml;
                    strOutStyle = strStyle;
                }
            }
            finally
            {
                stop.EndLoop();
                stop.OnStop -= new StopEventHandler(this.DoStop);
                stop.Initial("");
            }
            return(0);

ERROR1:
            return(-1);
        }
Exemplo n.º 7
0
        int GetXmlHtml(
            string strXml1,
            string strXml2,
            out string strHtml2,
            out string strError)
        {
            strError = "";
            strHtml2 = "";
            int nRet = 0;

            string strOldMARC        = "";
            string strOldFragmentXml = "";

            if (string.IsNullOrEmpty(strXml1) == false)
            {
                string strOutMarcSyntax = "";
                // 将XML格式转换为MARC格式
                // 自动从数据记录中获得MARC语法
                nRet = MarcUtil.Xml2Marc(strXml1,
                                         MarcUtil.Xml2MarcStyle.Warning | MarcUtil.Xml2MarcStyle.OutputFragmentXml,
                                         "",
                                         out strOutMarcSyntax,
                                         out strOldMARC,
                                         out strOldFragmentXml,
                                         out strError);
                if (nRet == -1)
                {
                    strError = "XML 转换到 MARC 记录时出错: " + strError;
                    return(-1);
                }
            }

            string strNewMARC        = "";
            string strNewFragmentXml = "";

            if (string.IsNullOrEmpty(strXml2) == false)
            {
                string strOutMarcSyntax = "";
                // 将XML格式转换为MARC格式
                // 自动从数据记录中获得MARC语法
                nRet = MarcUtil.Xml2Marc(strXml2,
                                         MarcUtil.Xml2MarcStyle.Warning | MarcUtil.Xml2MarcStyle.OutputFragmentXml,
                                         "",
                                         out strOutMarcSyntax,
                                         out strNewMARC,
                                         out strNewFragmentXml,
                                         out strError);
                if (nRet == -1)
                {
                    strError = "XML 转换到 MARC 记录时出错: " + strError;
                    return(-1);
                }
            }

            if (string.IsNullOrEmpty(strOldMARC) == false &&
                string.IsNullOrEmpty(strNewMARC) == false)
            {
                // 创建展示两个 MARC 记录差异的 HTML 字符串
                // return:
                //      -1  出错
                //      0   成功
                nRet = MarcDiff.DiffHtml(
                    _leftTitle,
                    strOldMARC,
                    strOldFragmentXml,
                    "",
                    _rightTitle,
                    strNewMARC,
                    strNewFragmentXml,
                    "",
                    out strHtml2,
                    out strError);
                if (nRet == -1)
                {
                    return(-1);
                }
            }
            else if (string.IsNullOrEmpty(strOldMARC) == false &&
                     string.IsNullOrEmpty(strNewMARC) == true)
            {
                strHtml2 = MarcUtil.GetHtmlOfMarc(strOldMARC,
                                                  strOldFragmentXml,
                                                  "",
                                                  false);
            }
            else if (string.IsNullOrEmpty(strOldMARC) == true &&
                     string.IsNullOrEmpty(strNewMARC) == false)
            {
                strHtml2 = MarcUtil.GetHtmlOfMarc(strNewMARC,
                                                  strNewFragmentXml,
                                                  "",
                                                  false);
            }

            return(0);
        }