|
25 | 25 | import org.culturegraph.mf.iso2709.Iso2709Format;
|
26 | 26 | import org.culturegraph.mf.iso2709.RecordBuilder;
|
27 | 27 | import org.culturegraph.mf.iso2709.RecordFormat;
|
| 28 | +import org.culturegraph.mf.stream.converter.xml.MarcXmlHandler; |
| 29 | +import org.slf4j.Logger; |
| 30 | +import org.slf4j.LoggerFactory; |
28 | 31 |
|
29 | 32 | /**
|
30 | 33 | * Encodes a stream in MARC21 format.
|
|
54 | 57 | * 2709:2008 record label and some of its contents (record status,
|
55 | 58 | * implementation codes, user system characters) are copied into the generated
|
56 | 59 | * record</li>
|
| 60 | + * |
| 61 | + * <li>literal named "type", which may be produced by {@link MarcXmlHandler} |
| 62 | + * are ignored.</li> |
57 | 63 | * </ul>
|
58 | 64 | *
|
59 | 65 | * <p>The stream expected by the encoder is compatible to the streams emitted by
|
60 |
| - * the {@link MarcDecoder} and the {MarcXmlHandler}. |
| 66 | + * the {@link MarcDecoder} and the {@link MarcXmlHandler}. |
61 | 67 | * </p>
|
62 | 68 | *
|
63 | 69 | * <p>The record identifier in {@code startRecord} is ignored. To add an identifier
|
|
76 | 82 | public final class Marc21Encoder extends
|
77 | 83 | DefaultStreamPipe<ObjectReceiver<String>> {
|
78 | 84 |
|
79 |
| - public static final String LEADER_LITERAL = "leader"; |
| 85 | + private static Logger LOG = LoggerFactory.getLogger(Marc21Encoder.class); |
80 | 86 |
|
81 | 87 | private static final RecordFormat MARC21 = new RecordFormat();
|
82 | 88 |
|
| 89 | + public static final String LEADER_LITERAL = "leader"; |
| 90 | + public static final String TYPE_LITERAL = "type"; |
| 91 | + |
83 | 92 | private final RecordBuilder builder = new RecordBuilder(MARC21);
|
84 | 93 | private final int nameLength;
|
85 | 94 |
|
@@ -131,12 +140,20 @@ public void endEntity() {
|
131 | 140 |
|
132 | 141 | @Override
|
133 | 142 | public void literal(final String name, final String value) {
|
134 |
| - if (LEADER_LITERAL.equals(name)) { |
135 |
| - setRecordLabel(value); |
136 |
| - } else if (inField) { |
| 143 | + if (inField) { |
137 | 144 | builder.appendSubfield(name, value);
|
138 | 145 | } else {
|
139 |
| - builder.appendReferenceField(name, value); |
| 146 | + if (LEADER_LITERAL.equals(name)) { |
| 147 | + setRecordLabel(value); |
| 148 | + } else if (TYPE_LITERAL.equals(name)) { |
| 149 | + // MarcXmlHandler may output `type` literals. The |
| 150 | + // information in these literals is not included in |
| 151 | + // marc21 records. Therefore, we need to ignore |
| 152 | + // these literals here. |
| 153 | + return; |
| 154 | + } else { |
| 155 | + builder.appendReferenceField(name, value); |
| 156 | + } |
140 | 157 | }
|
141 | 158 | }
|
142 | 159 |
|
|
0 commit comments