Package org.marc4j.marc

Examples of org.marc4j.marc.Subfield


       
        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 testContructor() {
      Subfield sf = factory.newSubfield();
      assertNotNull("subfield is null", sf);
      sf = factory.newSubfield('a');
      assertEquals('a', sf.getCode());
      sf = factory.newSubfield('a', "Summerland");
      assertEquals('a', sf.getCode());
      assertEquals("Summerland", sf.getData());
  }
View Full Code Here

      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

    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

            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()));

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

                handler.startElement(Constants.MARCXML_NS_URI, SUBFIELD,
                        SUBFIELD, atts);
                temp = getDataElement(subfield.getData());
                handler.characters(temp, 0, temp.length);
                handler
                        .endElement(Constants.MARCXML_NS_URI, SUBFIELD,
                                SUBFIELD);
            }
View Full Code Here

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

  public void testContructor() {
      Subfield sf = factory.newSubfield();
      assertNotNull("subfield is null", sf);
      sf = factory.newSubfield('a');
      assertEquals('a', sf.getCode());
      sf = factory.newSubfield('a', "Summerland");
      assertEquals('a', sf.getCode());
      assertEquals("Summerland", sf.getData());
  }
View Full Code Here

                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("%%@%%"))
                    {
                        String parts[] = sf.getData().split("%%@%%", 3);
                        sf.setData(parts[partToUse]);
                    }
                }
            }
        }                     
    }
View Full Code Here

        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

    public List getSubfields(char code) {
        List retSubfields = new ArrayList();
        Iterator i = subfields.iterator();
        while (i.hasNext()) {
            Subfield sf = (Subfield) i.next();
            if (sf.getCode() == code)
                retSubfields.add(sf);
        }
        return retSubfields;
    }
View Full Code Here

    }

    public Subfield getSubfield(char code) {
        Iterator i = subfields.iterator();
        while (i.hasNext()) {
            Subfield sf = (Subfield) i.next();
            if (sf.getCode() == code)
                return sf;
        }
        return null;
    }
View Full Code Here

TOP

Related Classes of org.marc4j.marc.Subfield

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.