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