Search in sources :

Example 66 with DataField

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

the class MetadataMarcRecord method getEANs.

@Override
public List<Ean> getEANs() {
    List<Ean> results = new ArrayList<>();
    Long eanCounter = 0L;
    Ean ean;
    for (DataField df : underlayingMarc.getDataFields("024")) {
        try {
            ean = EANUtils.createEan(df);
        } catch (NoDataException nde) {
            continue;
        } catch (NumberFormatException nfe) {
            logger.info(String.format("Invalid EAN: %s", nfe.getMessage()));
            continue;
        }
        ean.setOrderInRecord(++eanCounter);
        results.add(ean);
    }
    return results;
}
Also used : Ean(cz.mzk.recordmanager.server.model.Ean) DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList) NoDataException(cz.mzk.recordmanager.server.util.identifier.NoDataException)

Example 67 with DataField

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

the class MarcRecordImpl method getSubfield.

/**
 * get first code subfield from first field having given tag
 * @param tag
 * @param code
 * @return {@link Subfield} or null
 */
protected Subfield getSubfield(String tag, char code) {
    DataField field = getDataField(tag);
    if (field == null) {
        return null;
    }
    List<Subfield> subfields = getSubfields(field, new char[] { code });
    return subfields.isEmpty() ? null : subfields.get(0);
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 68 with DataField

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

the class MarcRecordImpl method exportToAlephMarc.

protected String exportToAlephMarc() {
    StringBuilder out = new StringBuilder();
    out.append(record.getControlNumber());
    out.append(" LDR   L ");
    out.append(record.getLeader().toString());
    out.append('\n');
    for (ControlField field : record.getControlFields()) {
        out.append(record.getControlNumber());
        out.append(" ");
        out.append(field.getTag());
        out.append("   L ");
        out.append(field.getData());
        out.append("\n");
    }
    for (DataField field : record.getDataFields()) {
        out.append(record.getControlNumber());
        out.append(" ");
        out.append(field.getTag());
        out.append(field.getIndicator1());
        out.append(field.getIndicator2());
        out.append(" L ");
        for (Subfield sfield : field.getSubfields()) {
            out.append("$$");
            out.append(sfield.getCode());
            out.append(sfield.getData());
        }
        out.append("\n");
    }
    return out.toString();
}
Also used : ControlField(org.marc4j.marc.ControlField) DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 69 with DataField

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

the class MarcRecordImpl method getFields.

@Override
public List<String> getFields(String tag, DataFieldMatcher matcher, SubfieldExtractionMethod method, String separator, char... subfields) {
    if (matcher == null) {
        matcher = MatchAllDataFieldMatcher.INSTANCE;
    }
    List<DataField> fields = dataFields.get(tag);
    if (fields == null) {
        return Collections.emptyList();
    }
    List<String> result = new ArrayList<String>(fields.size());
    for (DataField field : fields) {
        if (matcher.matches(field)) {
            List<String> sfValues = parseSubfields(field, separator, method, subfields);
            for (String sfValue : sfValues) {
                if (sfValue != null && !sfValue.trim().isEmpty()) {
                    result.add(sfValue);
                }
            }
        }
    }
    return result;
}
Also used : DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList)

Example 70 with DataField

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

the class MarcRecordImpl method getFields.

@Override
public List<String> getFields(String tag, DataFieldMatcher matcher, String separator, char... subfields) {
    List<DataField> fields = dataFields.get(tag);
    if (fields == null) {
        return Collections.emptyList();
    }
    List<String> result = new ArrayList<String>(fields.size());
    for (DataField field : fields) {
        if (matcher.matches(field)) {
            String content = parseSubfields(field, separator, subfields);
            if (content != null && !content.trim().isEmpty()) {
                result.add(content);
            }
        }
    }
    return result;
}
Also used : DataField(org.marc4j.marc.DataField) ArrayList(java.util.ArrayList)

Aggregations

DataField (org.marc4j.marc.DataField)82 ArrayList (java.util.ArrayList)18 Subfield (org.marc4j.marc.Subfield)17 MarcRecord (cz.mzk.recordmanager.server.marc.MarcRecord)15 ControlField (org.marc4j.marc.ControlField)13 Record (org.marc4j.marc.Record)13 MarcRecordImpl (cz.mzk.recordmanager.server.marc.MarcRecordImpl)12 RecordImpl (cz.mzk.recordmanager.server.marc.marc4j.RecordImpl)11 List (java.util.List)11 TreeSet (java.util.TreeSet)11 Matcher (java.util.regex.Matcher)11 MarcFactory (org.marc4j.marc.MarcFactory)8 MarcFactoryImpl (cz.mzk.recordmanager.server.marc.marc4j.MarcFactoryImpl)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 NoDataException (cz.mzk.recordmanager.server.util.identifier.NoDataException)4 HarvestedRecord (cz.mzk.recordmanager.server.model.HarvestedRecord)3 IOException (java.io.IOException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 ImportConfiguration (cz.mzk.recordmanager.server.model.ImportConfiguration)2 ShortTitle (cz.mzk.recordmanager.server.model.ShortTitle)2