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

            LibraryApplication app = this;

            FilterHost host = new FilterHost();

            host.RecPath = strRecPath;
            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);
        }