Exemple #1
0
        public void TestAddSubfield()
        {
            var df = factory.NewDataField("245", '1', '0');
            var sf = factory.NewSubfield('a', "Summerland");

            df.AddSubfield(sf);
            Assert.AreEqual(1, df.GetSubfields().Count);
        }
Exemple #2
0
        public void TestContructor()
        {
            var sf = factory.NewSubfield();

            Assert.IsNotNull(sf, "subfield is null");
            sf = factory.NewSubfield('a');
            Assert.AreEqual('a', sf.Code);
            sf = factory.NewSubfield('a', "Summerland");
            Assert.AreEqual('a', sf.Code);
            Assert.AreEqual("Summerland", sf.Data);
        }
Exemple #3
0
        private IDataField ParseDataField(String tag, byte[] field)
        {
            using (var bais = new InputStream(field))
            {
                char ind1 = (char)bais.ReadByte();
                char ind2 = (char)bais.ReadByte();

                var dataField = factory.NewDataField();
                dataField.Tag        = tag;
                dataField.Indicator1 = ind1;
                dataField.Indicator2 = ind2;

                int       code;
                int       size;
                int       readByte;
                byte[]    data;
                ISubfield subfield;
                while (true)
                {
                    readByte = bais.ReadByte();
                    if (readByte < 0)
                    {
                        break;
                    }
                    switch (readByte)
                    {
                    case Constants.US:
                        code = bais.ReadByte();
                        if (code < 0)
                        {
                            throw new IOException("unexpected end of data field");
                        }
                        if (code == Constants.FT)
                        {
                            break;
                        }
                        size = GetSubfieldLength(bais);
                        data = new byte[size];
                        bais.Read(data);
                        subfield      = factory.NewSubfield();
                        subfield.Code = (char)code;
                        subfield.Data = GetDataAsString(data);
                        dataField.AddSubfield(subfield);
                        break;

                    case Constants.FT:
                        break;
                    }
                }
                return(dataField);
            }
        }
Exemple #4
0
        public void TestWriteOfRecordWithIndicatorlessSubfield()
        {
            var         record   = StaticTestRecords.GetSummerlandRecord();
            MarcFactory factory  = StaticTestRecords.getFactory();
            var         badField = factory.NewDataField();

            badField.Tag = "911";
            badField.AddSubfield(factory.NewSubfield('a', "HAZMARC - INDICATORLESS FIELD DETECTED - MOPP LEVEL 4"));
            record.AddVariableField(badField);

            using (var output = new MemoryStream())
            {
                using (MarcXmlWriter writer = new MarcXmlWriter(output, true))
                {
                    writer.Write(record);
                }
            }
        }
Exemple #5
0
        private void LoadRecord(XElement recordElement, ref IRecord rec)
        {
            foreach (var elem in recordElement.Elements())
            {
                switch (elem.Name.LocalName)
                {
                case LEADER:
                    rec.Leader = factory.NewLeader(elem.Value);
                    break;

                case CONTROLFIELD:
                    rec.AddVariableField(
                        factory.NewControlField(
                            elem.Attribute(TAG_ATTR).Value, elem.Value));
                    break;

                case DATAFIELD:
                    var ind1 = elem.Attribute(IND_1_ATTR) != null?elem.Attribute(IND_1_ATTR).Value : " ";

                    var ind2 = elem.Attribute(IND_2_ATTR) != null?elem.Attribute(IND_2_ATTR).Value : " ";

                    dataField = factory.NewDataField(
                        elem.Attribute(TAG_ATTR).Value,
                        string.IsNullOrEmpty(ind1) ? ' ' : ind1[0],
                        string.IsNullOrEmpty(ind2) ? ' ' : ind2[0]);

                    foreach (var subField in elem.Elements(XName.Get(SUBFIELD, Constants.MARCXML_NS_URI)).Select(a =>
                                                                                                                 factory.NewSubfield(
                                                                                                                     a.Attribute(CODE_ATTR).Value[0],
                                                                                                                     a.Value)))
                    {
                        dataField.AddSubfield(subField);
                    }
                    rec.AddVariableField(dataField);
                    break;

                default:
                    break;
                }
            }
        }