use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class MarcDSL method getAllFields.
/*
* Get all fields starting with the 100 and ending with the 839
* This will ignore any "code" fields and only use textual fields
*/
public List<String> getAllFields() {
Map<String, List<DataField>> allFields = record.getAllFields();
List<String> result = new ArrayList<String>();
for (Entry<String, List<DataField>> entry : allFields.entrySet()) {
int tag = -1;
try {
tag = Integer.parseInt(entry.getKey());
} catch (NumberFormatException nfe) {
continue;
}
if ((tag < 100) || (tag >= 840)) {
continue;
}
List<DataField> fields = entry.getValue();
StringBuffer buffer = new StringBuffer();
for (DataField field : fields) {
List<Subfield> subfields = field.getSubfields();
Iterator<Subfield> subfieldsIter = subfields.iterator();
while (subfieldsIter.hasNext()) {
Subfield subfield = (Subfield) subfieldsIter.next();
if (buffer.length() > 0) {
buffer.append(" " + subfield.getData());
} else {
buffer.append(subfield.getData());
}
}
}
result.add(buffer.toString());
}
return result;
}
use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class AdresarKnihovenMarcFunctions method adresarGetResponsibility.
public List<String> adresarGetResponsibility(MarcFunctionContext ctx) {
List<String> results = new ArrayList<>();
char[] sfCodes = new char[] { 't', 'k', 'p', 'r', 'f', 'e' };
Subfield sf;
for (DataField df : ctx.record().getDataFields("JMN")) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < sfCodes.length; i++) {
if ((sf = df.getSubfield(sfCodes[i])) == null)
continue;
switch(sf.getCode()) {
case 'k':
case 'p':
sb.append(" ");
sb.append(sf.getData());
break;
case 'r':
sb.append(" (");
sb.append(sf.getData());
sb.append(")");
break;
case 'f':
case 'e':
sb.append(" ; ");
sb.append(sf.getData());
break;
default:
sb.append(sf.getData());
break;
}
}
results.add(sb.toString().trim());
}
return results;
}
use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class AdresarKnihovenMarcFunctions method getAllLibraryFields.
public Set<String> getAllLibraryFields(MarcFunctionContext ctx) {
Set<String> results = new HashSet<>();
for (List<DataField> list : ctx.record().getAllFields().values()) {
StringBuffer sb = new StringBuffer();
for (DataField df : list) {
for (Subfield sf : df.getSubfields()) {
if (sb.length() > 0)
sb.append(" ");
sb.append(sf.getData());
}
}
results.add(sb.toString());
}
return results;
}
use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class AdresarKnihovenMarcFunctions method adresarGetAddress.
public List<String> adresarGetAddress(MarcFunctionContext ctx) {
List<String> results = new ArrayList<>();
char[] sfCodes = new char[] { 'u', 'c', 'm', 'p' };
Subfield sf;
for (DataField df : ctx.record().getDataFields("ADR")) {
StringBuilder sb = new StringBuilder();
boolean isData = false;
for (int i = 0; i < sfCodes.length; i++) {
if ((sf = df.getSubfield(sfCodes[i])) == null)
continue;
switch(sf.getCode()) {
case 'c':
if (isData)
sb.append(", ");
sb.append(sf.getData());
break;
case 'm':
if (isData)
sb.append(" ");
sb.append(sf.getData());
break;
case 'p':
if (isData)
sb.append(" ");
sb.append("(");
sb.append(sf.getData());
sb.append(")");
break;
default:
sb.append(sf.getData());
break;
}
isData = true;
}
results.add(sb.toString().trim());
}
return results;
}
use of org.marc4j.marc.Subfield in project RecordManager2 by moravianlibrary.
the class ISMNUtils method createIsmn.
/**
* @param rawDataField {@link DataField}, usually tag 024, 1. indicator = 2
* @return {@link Ismn}
*/
public static Ismn createIsmn(final DataField rawDataField) {
Subfield subfieldA = rawDataField.getSubfield('a');
if (rawDataField.getIndicator1() != '2' || subfieldA == null)
throw new NoDataException(IdentifierUtils.NO_SUBFIELD);
Matcher matcher = ISMN_PATTERN.matcher(subfieldA.getData());
if (!matcher.find())
throw new NoDataException(IdentifierUtils.NO_USABLE_DATA);
Long validIsmn = toIsmn13LongThrowing(matcher.group(1));
List<String> notes = new ArrayList<>();
notes.add(IdentifierUtils.parseNote(matcher.group(2)));
for (Subfield subfieldQ : rawDataField.getSubfields('q')) {
notes.add(IdentifierUtils.parseNote(subfieldQ.getData()));
}
return Ismn.create(validIsmn, 1L, String.join(" ", notes));
}
Aggregations