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