示例#1
0
        private static IRecord MakeSummerlandRecord()
        {
            var sumland = factory.NewRecord("00714cam a2200205 a 4500");

            sumland.AddVariableField(factory.NewControlField("001", "12883376"));
            sumland.AddVariableField(factory.NewControlField("005", "20030616111422.0"));
            sumland.AddVariableField(factory.NewControlField("008", "020805s2002    nyu    j      000 1 eng  "));
            sumland.AddVariableField(factory.NewDataField("020", ' ', ' ', "a", "0786808772"));
            sumland.AddVariableField(factory.NewDataField("020", ' ', ' ', "a", "0786816155 (pbk.)"));
            sumland.AddVariableField(factory.NewDataField("040", ' ', ' ', "a", "DLC", "c", "DLC", "d", "DLC"));
            sumland.AddVariableField(factory.NewDataField("100", '1', ' ', "a", "Chabon, Michael."));
            sumland.AddVariableField(factory.NewDataField("245", '1', '0', "a", "Summerland /", "c", "Michael Chabon."));
            sumland.AddVariableField(factory.NewDataField("250", ' ', ' ', "a", "1st ed."));
            sumland.AddVariableField(factory.NewDataField("260", ' ', ' ', "a", "New York :", "b", "Miramax Books/Hyperion Books for Children,", "c", "c2002."));
            sumland.AddVariableField(factory.NewDataField("300", ' ', ' ', "a", "500 p. ;", "c", "22 cm."));
            sumland.AddVariableField(factory.NewDataField("520", ' ', ' ', "a", "Ethan Feld, the worst baseball player in the history of the game, finds himself recruited by a 100-year-old scout to help a band of fairies triumph over an ancient enemy."));
            sumland.AddVariableField(factory.NewDataField("650", ' ', '1', "a", "Fantasy."));
            sumland.AddVariableField(factory.NewDataField("650", ' ', '1', "a", "Baseball", "v", "Fiction."));
            sumland.AddVariableField(factory.NewDataField("650", ' ', '1', "a", "Magic", "v", "Fiction."));
            return(sumland);
        }
示例#2
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;
                }
            }
        }
示例#3
0
        static StaticTestRecords()
        {
            factory   = MarcFactory.Instance;
            chabon[0] = factory.NewRecord("00759cam a2200229 a 4500");
            chabon[0].AddVariableField(factory.NewControlField("001", "11939876"));
            chabon[0].AddVariableField(factory.NewControlField("005", "20041229190604.0"));
            chabon[0].AddVariableField(factory.NewControlField("008", "000313s2000    nyu           000 1 eng  "));
            chabon[0].AddVariableField(factory.NewDataField("020", ' ', ' ', "a", "0679450041 (acid-free paper)"));
            chabon[0].AddVariableField(factory.NewDataField("040", ' ', ' ', "a", "DLC", "c", "DLC", "d", "DLC"));
            chabon[0].AddVariableField(factory.NewDataField("100", '1', ' ', "a", "Chabon, Michael."));
            chabon[0].AddVariableField(factory.NewDataField("245", '1', '4', "a", "The amazing adventures of Kavalier and Clay :", "b", "a novel /", "c", "Michael Chabon."));
            chabon[0].AddVariableField(factory.NewDataField("260", ' ', ' ', "a", "New York :", "b", "Random House,", "c", "c2000."));
            chabon[0].AddVariableField(factory.NewDataField("300", ' ', ' ', "a", "639 p. ;", "c", "25 cm."));
            chabon[0].AddVariableField(factory.NewDataField("650", ' ', '0', "a", "Comic books, strips, etc.", "x", "Authorship", "v", "Fiction."));
            chabon[0].AddVariableField(factory.NewDataField("650", ' ', '0', "a", "Heroes in mass media", "v", "Fiction."));
            chabon[0].AddVariableField(factory.NewDataField("650", ' ', '0', "a", "Czech Americans", "v", "Fiction."));
            chabon[0].AddVariableField(factory.NewDataField("651", ' ', '0', "a", "New York (N.Y.)", "v", "Fiction."));
            chabon[0].AddVariableField(factory.NewDataField("650", ' ', '0', "a", "Young men", "v", "Fiction."));
            chabon[0].AddVariableField(factory.NewDataField("650", ' ', '0', "a", "Cartoonists", "v", "Fiction."));
            chabon[0].AddVariableField(factory.NewDataField("655", ' ', '7', "a", "Humorous stories.", "2", "gsafd"));
            chabon[0].AddVariableField(factory.NewDataField("655", ' ', '7', "a", "Bildungsromane.", "2", "gsafd"));

            chabon[1] = factory.NewRecord("00714cam a2200205 a 4500");
            chabon[1].AddVariableField(factory.NewControlField("001", "12883376"));
            chabon[1].AddVariableField(factory.NewControlField("005", "20030616111422.0"));
            chabon[1].AddVariableField(factory.NewControlField("008", "020805s2002    nyu    j      000 1 eng  "));
            chabon[1].AddVariableField(factory.NewDataField("020", ' ', ' ', "a", "0786808772"));
            chabon[1].AddVariableField(factory.NewDataField("020", ' ', ' ', "a", "0786816155 (pbk.)"));
            chabon[1].AddVariableField(factory.NewDataField("040", ' ', ' ', "a", "DLC", "c", "DLC", "d", "DLC"));
            chabon[1].AddVariableField(factory.NewDataField("100", '1', ' ', "a", "Chabon, Michael."));
            chabon[1].AddVariableField(factory.NewDataField("245", '1', '0', "a", "Summerland /", "c", "Michael Chabon."));
            chabon[1].AddVariableField(factory.NewDataField("250", ' ', ' ', "a", "1st ed."));
            chabon[1].AddVariableField(factory.NewDataField("260", ' ', ' ', "a", "New York :", "b", "Miramax Books/Hyperion Books for Children,", "c", "c2002."));
            chabon[1].AddVariableField(factory.NewDataField("300", ' ', ' ', "a", "500 p. ;", "c", "22 cm."));
            chabon[1].AddVariableField(factory.NewDataField("520", ' ', ' ', "a", "Ethan Feld, the worst baseball player in the history of the game, finds himself recruited by a 100-year-old scout to help a band of fairies triumph over an ancient enemy."));
            chabon[1].AddVariableField(factory.NewDataField("650", ' ', '1', "a", "Fantasy."));
            chabon[1].AddVariableField(factory.NewDataField("650", ' ', '1', "a", "Baseball", "v", "Fiction."));
            chabon[1].AddVariableField(factory.NewDataField("650", ' ', '1', "a", "Magic", "v", "Fiction."));

            summerland[0] = MakeSummerlandRecord();
        }
示例#4
0
        private void ParseRecord(IRecord record, byte[] byteArray, byte[] recordBuf, int recordLength)
        {
            ILeader ldr;

            ldr = factory.NewLeader();
            ldr.RecordLength = recordLength;
            int directoryLength = 0;

            try
            {
                ParseLeader(ldr, byteArray);
                directoryLength = ldr.BaseAddressOfData - (24 + 1);
            }
            catch (IOException e)
            {
                throw new MarcException("error parsing leader with data: "
                                        + byteArray.ConvertToString(), e);
            }
            catch (MarcException e)
            {
                throw new MarcException("error parsing leader with data: "
                                        + byteArray.ConvertToString(), e);
            }

            // if MARC 21 then check encoding
            switch (ldr.CharCodingScheme)
            {
            case ' ':
                if (!isOverride)
                {
                    encoding = "ISO-8859-1";
                }
                break;

            case 'a':
                if (!isOverride)
                {
                    encoding = "UTF-8";
                }
                break;
            }
            record.Leader = ldr;

            if ((directoryLength % 12) != 0)
            {
                throw new MarcException("invalid directory");
            }
            using (var inputrec = new InputStream(recordBuf))
            {
                int size = directoryLength / 12;

                String[] tags    = new String[size];
                int[]    lengths = new int[size];

                byte[] tag    = new byte[3];
                byte[] length = new byte[4];
                byte[] start  = new byte[5];

                String tmp;

                try
                {
                    for (int i = 0; i < size; i++)
                    {
                        inputrec.Read(tag);
                        tmp     = tag.ConvertToString();
                        tags[i] = tmp;

                        inputrec.Read(length);
                        tmp        = length.ConvertToString();
                        lengths[i] = int.Parse(tmp);

                        inputrec.Read(start);
                    }

                    if (inputrec.ReadByte() != Constants.FT)
                    {
                        throw new MarcException("expected field terminator at end of directory");
                    }

                    for (int i = 0; i < size; i++)
                    {
                        GetFieldLength(inputrec);
                        if (Verifier.IsControlField(tags[i]))
                        {
                            byteArray = new byte[lengths[i] - 1];
                            inputrec.Read(byteArray);

                            if (inputrec.ReadByte() != Constants.FT)
                            {
                                throw new MarcException("expected field terminator at end of field");
                            }

                            var field = factory.NewControlField();
                            field.Tag  = tags[i];
                            field.Data = GetDataAsString(byteArray);
                            record.AddVariableField(field);
                        }
                        else
                        {
                            byteArray = new byte[lengths[i]];
                            inputrec.Read(byteArray);

                            try
                            {
                                record.AddVariableField(ParseDataField(tags[i], byteArray));
                            }
                            catch (Exception e)
                            {
                                throw new MarcException(
                                          "error parsing data field for tag: " + tags[i]
                                          + " with data: "
                                          + byteArray.ConvertToString(), e);
                            }
                        }
                    }

                    if (inputrec.ReadByte() != Constants.RT)
                    {
                        throw new MarcException("expected record terminator");
                    }
                }
                catch (IOException e)
                {
                    throw new MarcException("an error occured reading input", e);
                }
            }
        }