Package org.marc4j.marc

Examples of org.marc4j.marc.DataField


    }

    List fields = marcRecord.getDataFields();
    if (fields != null) {
      for (Iterator i = fields.iterator(); i.hasNext();) {
        DataField datafield = (DataField) i.next();
        List subfields = datafield.getSubfields();

        //if tag==016 we need to concatenate informations from subfield $a
        //and subfield $2
       
        if(datafield.getTag().compareTo("016")==0){
          String contentCodeA=null;
          String contentCodeTwo=null;
          for (Iterator j = subfields.iterator(); j.hasNext();) {
            Subfield subfield = (Subfield) j.next();

            if(subfield.getCode()=='2' && subfield.getData()!=null ){
              contentCodeTwo=subfield.getData();
            }
            if(subfield.getCode()=='a' && subfield.getData()!=null ){
              contentCodeA=subfield.getData();
            }
 
          }
          addProperty(ret, mappings.get(datafield.getTag())+"("+contentCodeTwo+")", contentCodeA);

        }

        //if tag==100 we need to check informations from subfield $4 and $0
        //and subfield $2
       
        if(datafield.getTag().compareTo("100")==0){
          String contentCodeFour=null;
          String contentCodeZero=null;
          for (Iterator j = subfields.iterator(); j.hasNext();) {
            Subfield subfield = (Subfield) j.next();

            if(subfield.getCode()=='4' && subfield.getData()!=null ){
              contentCodeFour=subfield.getData();
            }
            if(subfield.getCode()=='0' && subfield.getData()!=null && contentCodeFour.compareTo("aut")==0){
              contentCodeZero=subfield.getData();
            }
 
          }
          addProperty(ret, mappings.get(datafield.getTag()), contentCodeZero);

        }
       
       
        //one to one mappings
        else{
          for (Iterator j = subfields.iterator(); j.hasNext();) {
            Subfield subfield = (Subfield) j.next();
            String tagAndSubfield = datafield.getTag() + " $"
            + subfield.getCode();
            String mappingTagName = mappings.get(tagAndSubfield);
            if (mappingTagName != null) {
              addProperty(ret, mappingTagName, subfield.getData());
            }
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

        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

                    CONTROL_FIELD);
        }

        i = record.getDataFields().iterator();
        while (i.hasNext()) {
            DataField field = (DataField) i.next();
            atts = new AttributesImpl();
            atts.addAttribute("", "tag", "tag", "CDATA", field.getTag());
            atts.addAttribute("", "ind1", "ind1", "CDATA", String.valueOf(field
                    .getIndicator1()));
            atts.addAttribute("", "ind2", "ind2", "CDATA", String.valueOf(field
                    .getIndicator2()));

            if (indent)
                handler.ignorableWhitespace("\n    ".toCharArray(), 0, 5);

            handler.startElement(Constants.MARCXML_NS_URI, DATA_FIELD,
                    DATA_FIELD, atts);
            Iterator j = field.getSubfields().iterator();
            while (j.hasNext()) {
                Subfield subfield = (Subfield) j.next();
                atts = new AttributesImpl();
                atts.addAttribute("", "code", "code", "CDATA", String
                        .valueOf(subfield.getCode()));
View Full Code Here

        while (iter.hasNext())
        {
            VariableField field = iter.next();
            if (field instanceof DataField)
            {
                DataField df = (DataField)field;
                List<Subfield> subf = df.getSubfields();
                Iterator<Subfield> sfiter = subf.iterator();
                while (sfiter.hasNext())
                {
                    Subfield sf = sfiter.next();
                    if (sf.getData().contains("%%@%%"))
View Full Code Here

        }
        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);
                if (size == 0)
                {
                    if (permissive)
                    {
                        errors.addError(ErrorHandler.MINOR_ERROR, "Subfield of zero length encountered, ignoring it.");
                        continue;
                    }
                    throw new IOException("Subfield of zero length encountered");
                }
                data = new byte[size];
                bais.read(data);
                subfield = factory.newSubfield();
                if (permissive) errors.setCurrentSubfield("" + (char)code);
                String dataAsString = getDataAsString(data);
                if (permissive && code == Constants.US)
                {
                    code = data[0];
                    dataAsString = dataAsString.substring(1);
                    errors.addError(ErrorHandler.MAJOR_ERROR,
                                    "Subfield tag is a subfield separator, using first character of field as subfield tag.");
                }
                subfield.setCode((char) code);
                subfield.setData(dataAsString);
                dataField.addSubfield(subfield);
                break;
            case Constants.FT:
                break;
            }
        }
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.