From 9c0b4afbb72c262644b0e6f2b45f246a13d6b734 Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Thu, 5 Sep 2024 14:42:40 +0200 Subject: [PATCH 1/3] Update test to show that marc:leader isn't pretty printed (#550) --- .../biblio/marc21/MarcXmlEncoderTest.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java index 23835ad8..7e4186a5 100644 --- a/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java +++ b/metafacture-biblio/src/test/java/org/metafacture/biblio/marc21/MarcXmlEncoderTest.java @@ -130,10 +130,19 @@ public void createAnEmptyRecord() { @Test public void createARecordPrettyPrint() { encoder.setFormatted(true); - addOneRecord(encoder); + encoder.startRecord(RECORD_ID); + encoder.startEntity(Marc21EventNames.LEADER_ENTITY); + encoder.literal(Marc21EventNames.LEADER_ENTITY, "dummy"); + encoder.endEntity(); + encoder.literal("001", RECORD_ID); + encoder.startEntity("010 "); + encoder.literal("a", RECORD_ID); + encoder.endEntity(); + encoder.endRecord(); encoder.closeStream(); - String expected = XML_DECLARATION + "\n" + XML_ROOT_OPEN + "\n"// " \n" + String expected = XML_DECLARATION + "\n" + XML_ROOT_OPEN + "\n" + "\t\n"// + + "\t\tdummy\n" + "\t\t92005291\n"// + "\t\t\n"// + "\t\t\t92005291\n"// From cdbde4227121d2f269a41f73f99d958b0e80bcfe Mon Sep 17 00:00:00 2001 From: Pascal Christoph Date: Thu, 5 Sep 2024 14:49:35 +0200 Subject: [PATCH 2/3] Fix pretty printing of marc:leader (#550) --- .../biblio/marc21/MarcXmlEncoder.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java index 912147a7..73baae94 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java @@ -437,11 +437,11 @@ private void writeEscaped(final String str) { private void writeLeader() { final String leader = leaderBuilder.toString(); if (leaderBuilder.length() > 0) { - prettyPrintIndentation(); + prettyPrintIndentationLeader(); writeTagLeader(Tag.leader::open); writeRawLeader(leader); writeTagLeader(Tag.leader::close); - prettyPrintNewLine(); + prettyPrintNewLineLeader(); } } @@ -462,12 +462,25 @@ private void prettyPrintIndentation() { } } + private void prettyPrintIndentationLeader() { + if (formatted) { + final String prefix = String.join("", Collections.nCopies(indentationLevel, INDENT)); + writeRawLeader(prefix); + } + } + private void prettyPrintNewLine() { if (formatted) { builder.append(NEW_LINE); } } + private void prettyPrintNewLineLeader() { + if (formatted) { + writeRawLeader(NEW_LINE); + } + } + private void sendAndClearData() { getReceiver().process(builder.toString()); builder.delete(0, builder.length()); From 066a4838d78fd4e293a20252dd5c644b60ab70ad Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 6 Sep 2024 15:50:27 +0200 Subject: [PATCH 3/3] Refactor pretty-printing MARC record leader. (#556) --- .../biblio/marc21/MarcXmlEncoder.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java index 73baae94..3d74a6f8 100644 --- a/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java +++ b/metafacture-biblio/src/main/java/org/metafacture/biblio/marc21/MarcXmlEncoder.java @@ -437,11 +437,17 @@ private void writeEscaped(final String str) { private void writeLeader() { final String leader = leaderBuilder.toString(); if (leaderBuilder.length() > 0) { - prettyPrintIndentationLeader(); + if (formatted) { + writeRawLeader(getIndentationPrefix()); + } + writeTagLeader(Tag.leader::open); writeRawLeader(leader); writeTagLeader(Tag.leader::close); - prettyPrintNewLineLeader(); + + if (formatted) { + writeRawLeader(NEW_LINE); + } } } @@ -455,17 +461,13 @@ private void writeTagLeader(final Function function) { writeRawLeader(function.apply(namespacePrefix)); } - private void prettyPrintIndentation() { - if (formatted) { - final String prefix = String.join("", Collections.nCopies(indentationLevel, INDENT)); - builder.append(prefix); - } + private String getIndentationPrefix() { + return String.join("", Collections.nCopies(indentationLevel, INDENT)); } - private void prettyPrintIndentationLeader() { + private void prettyPrintIndentation() { if (formatted) { - final String prefix = String.join("", Collections.nCopies(indentationLevel, INDENT)); - writeRawLeader(prefix); + builder.append(getIndentationPrefix()); } } @@ -475,12 +477,6 @@ private void prettyPrintNewLine() { } } - private void prettyPrintNewLineLeader() { - if (formatted) { - writeRawLeader(NEW_LINE); - } - } - private void sendAndClearData() { getReceiver().process(builder.toString()); builder.delete(0, builder.length());