Package org.marc4j.marc

Examples of org.marc4j.marc.DataField


        assertEquals(1, result.size());

        result = record.find("040", "DLC");
        assertTrue(result.size() > 0);

        DataField df = (DataField) result.get(0);
        String agency = df.getSubfield('a').getData();
        assertTrue(agency.matches("DLC"));

    }
View Full Code Here


        Record record = factory.newRecord("00000cam a2200000 a 4500");
        assertEquals("00000cam a2200000 a 4500", record.getLeader().marshal());

        record.addVariableField(factory.newControlField("001", "12883376"));

        DataField df = factory.newDataField("245", '1', '0');
        df.addSubfield(factory.newSubfield('a', "Summerland /"));
        df.addSubfield(factory.newSubfield('c', "Michael Chabon."));
        record.addVariableField(df);
    }
View Full Code Here

        Record record = factory.newRecord("00000nz  a2200000o  4500");

        ControlField cf = factory.newControlField("001", tokens[0]);
        record.addVariableField(cf);

        DataField df = factory.newDataField("100", '1', ' ');
        df.addSubfield(factory.newSubfield('a', tokens[1]));
        df.addSubfield(factory.newSubfield('d', tokens[2]));
        record.addVariableField(df);

        return record;
    }
View Full Code Here

            throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(field);
        char ind1 = (char) bais.read();
        char ind2 = (char) bais.read();

        DataField dataField = factory.newDataField();
        dataField.setTag(tag);
        dataField.setIndicator1(ind1);
        dataField.setIndicator2(ind2);

        int code;
        int size;
        int readByte;
        byte[] data;
        Subfield subfield;
        while (true) {
            readByte = bais.read();
            if (readByte < 0)
                break;
            switch (readByte) {
            case Constants.US:
                code = bais.read();
                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.setCode((char) code);
                subfield.setData(getDataAsString(data));
                dataField.addSubfield(subfield);
                break;
            case Constants.FT:
                break;
            }
        }
View Full Code Here

        MarcReader reader = new MarcStreamReader(input);
        while (reader.hasNext()) {
            Record record = reader.next();

            DataField field = factory.newDataField("856", '4', '2');
            field.addSubfield(factory.newSubfield('3',
                "Contributor biographical information"));
            field.addSubfield(factory.newSubfield('u',
                "http://en.wikipedia.org/wiki/Michael_Chabon"));
            record.addVariableField(field);

            System.out.println(record.toString());
        }
View Full Code Here

    public void setUp() {
        factory = MarcFactory.newInstance();
    }

    public void testConstructor() {
        DataField df = factory.newDataField("245", '1', '0');
        assertEquals("245", df.getTag());
        assertEquals('1', df.getIndicator1());
        assertEquals('0', df.getIndicator2());
    }
View Full Code Here

        assertEquals('1', df.getIndicator1());
        assertEquals('0', df.getIndicator2());
    }

    public void testAddSubfield() {
        DataField df = factory.newDataField("245", '1', '0');
        Subfield sf = factory.newSubfield('a', "Summerland");
        df.addSubfield(sf);
        assertEquals(1, df.getSubfields().size());
    }
View Full Code Here

        df.addSubfield(sf);
        assertEquals(1, df.getSubfields().size());
    }

    public void testSetSubfield() {
        DataField df = factory.newDataField("245", '1', '0');
        Subfield sf1 = factory.newSubfield('a', "Summerland");
        Subfield sf2 = factory.newSubfield('c', "Michael Chabon");
        df.addSubfield(sf2);
        df.addSubfield(0, sf1);
        Subfield s = (Subfield) df.getSubfields().get(0);
        assertEquals(2, df.getSubfields().size());
        assertEquals('a', s.getCode());
    }
View Full Code Here

        assertEquals(2, df.getSubfields().size());
        assertEquals('a', s.getCode());
    }

    public void testComparable() throws Exception {
        DataField df1 = factory.newDataField("600", '0', '0');
        DataField df2 = factory.newDataField("600", '0', '0');
        assertEquals(0, df1.compareTo(df2));
        df2.setTag("245");
        assertEquals(4, df1.compareTo(df2));
        df2.setTag("700");
        assertEquals(-1, df1.compareTo(df2));
    }
View Full Code Here

            if (result.size() > 0)
                System.out.println("Agency for this record is DLC");

            // there is no specific find for a specific subfield
            // so to check if it is the orignal cataloging agency
            DataField field = (DataField) result.get(0);
            String agency = field.getSubfield('a').getData();
            if (agency.matches("DLC"))
                System.out.println("DLC is the original agency");
        }
    }
View Full Code Here

TOP

Related Classes of org.marc4j.marc.DataField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.