Search in sources :

Example 46 with DataField

use of org.marc4j.marc.DataField 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 47 with DataField

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

the class MarcDSL method getAuthorDisplay.

public String getAuthorDisplay() {
    List<DataField> list = record.getDataFields("100");
    if (list.isEmpty())
        return null;
    DataField df = list.get(0);
    String name = getNameForDisplay(df);
    if (name != null && name.isEmpty())
        return null;
    else
        return name;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 48 with DataField

use of org.marc4j.marc.DataField 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 49 with DataField

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

the class AdresarKnihovenMarcFunctions method adresarGetNameAlt.

public List<String> adresarGetNameAlt(MarcFunctionContext ctx, String separator) {
    List<String> results = new ArrayList<>();
    for (DataField df : ctx.record().getDataFields("VAR")) {
        if (df.getIndicator1() == '2') {
            StringBuilder sb = new StringBuilder();
            for (char code : new char[] { 'a', 'b', 'c' }) {
                if (df.getSubfield(code) != null) {
                    sb.append(df.getSubfield(code).getData());
                    sb.append(separator);
                }
            }
            String temp = sb.toString();
            if (temp.endsWith(separator))
                temp = temp.substring(0, temp.length() - separator.length());
            results.add(temp);
        }
    }
    return results;
}
Also used : DataField(org.marc4j.marc.DataField)

Example 50 with DataField

use of org.marc4j.marc.DataField 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)

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