Search in sources :

Example 1 with Subfield

use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.

the class MarcDSL method getHoldings996.

public List<String> getHoldings996() {
    List<String> result = new ArrayList<>();
    Map<String, List<DataField>> allFields = record.getAllFields();
    List<DataField> list996 = allFields.get("996");
    if (list996 == null) {
        return result;
    }
    for (DataField dataField : list996) {
        StringBuilder currentSb = new StringBuilder();
        // 996 with '0' in subfield 'q'
        if (dataField.getSubfield('q') != null && dataField.getSubfield('q').getData().equals("0")) {
            continue;
        }
        for (Subfield subfield : dataField.getSubfields()) {
            currentSb.append('$');
            currentSb.append(subfield.getCode());
            currentSb.append(subfield.getData());
        }
        result.add(currentSb.toString());
    }
    return result;
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 2 with Subfield

use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.

the class MarcDSL method getTitleDisplay.

public String getTitleDisplay() {
    DataField df = getFirstDataField("245");
    if (df == null)
        return null;
    final char[] titleSubfields = new char[] { 'a', 'b', 'n', 'p' };
    final char[] sfhPunctuation = new char[] { '.', ',', ':' };
    char endCharH = ' ';
    StringBuilder sb = new StringBuilder();
    for (Subfield sf : df.getSubfields()) {
        // get last punctuation from 'h'
        if (sf.getCode() == 'h') {
            String data = sf.getData().trim();
            if (data.length() > 0) {
                if (Chars.contains(sfhPunctuation, data.charAt(data.length() - 1))) {
                    endCharH = data.charAt(data.length() - 1);
                }
            }
        } else if (Chars.contains(titleSubfields, sf.getCode())) {
            // print punctuation from h
            if (endCharH != ' ') {
                sb.append(endCharH);
                sb.append(" ");
                endCharH = ' ';
            }
            sb.append(sf.getData());
            sb.append(" ");
        } else
            endCharH = ' ';
    }
    return removeEndPunctuation(sb.toString());
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 3 with Subfield

use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.

the class MetadataMarcRecord method getLanguages.

@Override
public List<String> getLanguages() {
    Set<String> result = new HashSet<>();
    for (DataField df : underlayingMarc.getDataFields("041")) {
        for (Subfield subA : df.getSubfields('a')) {
            String lang = null;
            if (subA.getData().toLowerCase().equals("cze")) {
                lang = "cze";
            } else if (subA.getData().toLowerCase().equals("eng")) {
                lang = "eng";
            } else {
                lang = "oth";
            }
            result.add(lang);
        }
    }
    if (result.isEmpty()) {
        String cf = underlayingMarc.getControlField("008");
        if (cf != null && cf.length() > 39) {
            String substr = cf.substring(35, 38);
            String lang = null;
            if (substr.toLowerCase().equals("cze")) {
                lang = "cze";
            } else if (substr.toLowerCase().equals("eng")) {
                lang = "eng";
            }
            if (lang != null) {
                result.add(lang);
            }
        }
    }
    return new ArrayList<String>(result);
}
Also used : DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList) Subfield(org.marc4j.marc.Subfield) HashSet(java.util.HashSet)

Example 4 with Subfield

use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.

the class MarcISO2709StreamReader method parseDataField.

private DataField parseDataField(String tag, byte[] field) 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;
        }
    }
    return dataField;
}
Also used : DataField(org.marc4j.marc.DataField) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Subfield(org.marc4j.marc.Subfield)

Example 5 with Subfield

use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.

the class MarcRecordImpl method parseSubfields.

protected String parseSubfields(DataField df, String separator, char... subfields) {
    StringBuilder sb = new StringBuilder();
    String sep = EMPTY_STRING;
    for (char subfield : subfields) {
        List<Subfield> sfl = df.getSubfields(subfield);
        if (sfl != null && !sfl.isEmpty()) {
            for (Subfield sf : sfl) {
                sb.append(sep);
                sb.append(sf.getData());
                sep = separator;
            }
        }
    }
    return sb.toString();
}
Also used : Subfield(org.marc4j.marc.Subfield)

Aggregations

Subfield (org.marc4j.marc.Subfield)24 DataField (org.marc4j.marc.DataField)17 ArrayList (java.util.ArrayList)8 Matcher (java.util.regex.Matcher)6 ControlField (org.marc4j.marc.ControlField)4 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)3 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)3 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)3 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)3 List (java.util.List)3 TreeSet (java.util.TreeSet)3 MarcFactory (org.marc4j.marc.MarcFactory)3 Record (org.marc4j.marc.Record)3 IOException (java.io.IOException)2 Oclc (cz.mzk.recordmanager.server.model.Oclc)1 Sigla (cz.mzk.recordmanager.server.model.Sigla)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 HashSet (java.util.HashSet)1 StringJoiner (java.util.StringJoiner)1 Pair (org.apache.commons.lang3.tuple.Pair)1