Search in sources :

Example 16 with Subfield

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;
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 17 with Subfield

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;
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 18 with Subfield

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;
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 19 with Subfield

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;
}
Also used : DataField(org.marc4j.marc.DataField) Subfield(org.marc4j.marc.Subfield)

Example 20 with Subfield

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));
}
Also used : Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) 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