Beispiel #1
0
        // TODO: 实现简略格式和详细格式提供。简略格式可以理解为略去一些分类号主题词字段,最好用一段用户定制的脚本来进行过滤
        // 获得MARC记录
        // parameters:
        //      elementSetNames 元素集列表。每个元素集为 'B' 或 'F',表示简略和详细格式
        //      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 string strMarcSyntaxOID,
            out byte[] baIso2709,
            out string strError)
        {
            baIso2709        = null;
            strError         = "";
            strMarcSyntaxOID = "";

            // 转换为机内格式
            int nRet = MarcUtil.Xml2Marc(dp2library_record.RecordBody.Xml,
                                         true,
                                         "",
                                         out string strMarcSyntax,
                                         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,
                strMarcSyntax,
                marcRecordEncoding,
                out baIso2709,
                out strError);
            if (nRet == -1)
            {
                return(-1);
            }

            if (strMarcSyntax == "unimarc")
            {
                strMarcSyntaxOID = "1.2.840.10003.5.1";
            }
            if (strMarcSyntax == "usmarc")
            {
                strMarcSyntaxOID = "1.2.840.10003.5.10";
            }

            return(1);
        }