Skip to content

Commit 576c5ad

Browse files
committed
Implement comment
Allow again null values of literals in general, but prohibit it explicitly in the MarcXmlEncoder. - add test Complements ad48cd4. See #333 (comment).
1 parent 59c516d commit 576c5ad

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void literal(final String name, final String value) {
175175
if (currentEntity.equals("")) {
176176
prettyPrintIndentation();
177177
writeRaw(String.format(CONTROLFIELD_OPEN_TEMPLATE, name));
178-
if (value!=null)
178+
if (value != null)
179179
writeEscaped(value.trim());
180180
writeRaw(CONTROLFIELD_CLOSE);
181181
prettyPrintNewLine();

metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,17 @@ public void sendAndClearDataWhenOnResetStream() {
204204
String actual = resultCollector.toString();
205205
assertEquals(expected, actual);
206206
}
207+
208+
@Test
209+
public void shouldIgnoreNullValueOfLiteral() {
210+
encoder.startRecord(RECORD_ID);
211+
encoder.literal("type", null);
212+
encoder.endRecord();
213+
encoder.closeStream();
214+
String expected = XML_DECLARATION + XML_ROOT_OPEN
215+
+ "<marc:record><marc:controlfield tag=\"type\"></marc:controlfield></marc:record>"
216+
+ XML_MARC_COLLECTION_END_TAG;
217+
String actual = resultCollector.toString();
218+
assertEquals(expected, actual);
219+
}
207220
}

metamorph/src/main/java/org/metafacture/metamorph/Metamorph.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,11 @@ protected void dispatch(final String path, final String value, final List<NamedV
323323
}
324324
}
325325

326-
private void send(final String path, final String value, final List<NamedValueReceiver> dataList, final boolean fallback) {
326+
private void send(final String path, final String value, final List<NamedValueReceiver> dataList,
327+
final boolean fallback) {
327328
for (final NamedValueReceiver data : dataList) {
328-
String key=path;
329-
if (fallback && value != null && elseNested) {
329+
String key = path;
330+
if (fallback && elseNested) {
330331
if (flattener.getCurrentEntityName() != null) {
331332
outputStreamReceiver.startEntity(flattener.getCurrentEntityName());
332333
key = literalPatternOfEntityMarker.split(path)[1];
@@ -337,7 +338,7 @@ private void send(final String path, final String value, final List<NamedValueRe
337338
} catch (final RuntimeException e) {
338339
errorHandler.error(e);
339340
}
340-
if (fallback && value != null && elseNested) {
341+
if (fallback && elseNested) {
341342
if (flattener.getCurrentEntityName() != null) {
342343
outputStreamReceiver.endEntity();
343344
}

0 commit comments

Comments
 (0)