Skip to content

Commit fee2bcb

Browse files
committed
Merge #556 from branch '550-prettyIndentMarcLeader' of github.com:metafacture/metafacture-core
2 parents 57f9344 + 066a483 commit fee2bcb

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,17 @@ private void writeEscaped(final String str) {
437437
private void writeLeader() {
438438
final String leader = leaderBuilder.toString();
439439
if (leaderBuilder.length() > 0) {
440-
prettyPrintIndentation();
440+
if (formatted) {
441+
writeRawLeader(getIndentationPrefix());
442+
}
443+
441444
writeTagLeader(Tag.leader::open);
442445
writeRawLeader(leader);
443446
writeTagLeader(Tag.leader::close);
444-
prettyPrintNewLine();
447+
448+
if (formatted) {
449+
writeRawLeader(NEW_LINE);
450+
}
445451
}
446452
}
447453

@@ -455,10 +461,13 @@ private void writeTagLeader(final Function<Object[], String> function) {
455461
writeRawLeader(function.apply(namespacePrefix));
456462
}
457463

464+
private String getIndentationPrefix() {
465+
return String.join("", Collections.nCopies(indentationLevel, INDENT));
466+
}
467+
458468
private void prettyPrintIndentation() {
459469
if (formatted) {
460-
final String prefix = String.join("", Collections.nCopies(indentationLevel, INDENT));
461-
builder.append(prefix);
470+
builder.append(getIndentationPrefix());
462471
}
463472
}
464473

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,19 @@ public void createAnEmptyRecord() {
130130
@Test
131131
public void createARecordPrettyPrint() {
132132
encoder.setFormatted(true);
133-
addOneRecord(encoder);
133+
encoder.startRecord(RECORD_ID);
134+
encoder.startEntity(Marc21EventNames.LEADER_ENTITY);
135+
encoder.literal(Marc21EventNames.LEADER_ENTITY, "dummy");
136+
encoder.endEntity();
137+
encoder.literal("001", RECORD_ID);
138+
encoder.startEntity("010 ");
139+
encoder.literal("a", RECORD_ID);
140+
encoder.endEntity();
141+
encoder.endRecord();
134142
encoder.closeStream();
135-
String expected = XML_DECLARATION + "\n" + XML_ROOT_OPEN + "\n"// " <marc:record>\n"
143+
String expected = XML_DECLARATION + "\n" + XML_ROOT_OPEN + "\n"
136144
+ "\t<marc:record>\n"//
145+
+ "\t\t<marc:leader>dummy</marc:leader>\n"
137146
+ "\t\t<marc:controlfield tag=\"001\">92005291</marc:controlfield>\n"//
138147
+ "\t\t<marc:datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"//
139148
+ "\t\t\t<marc:subfield code=\"a\">92005291</marc:subfield>\n"//

0 commit comments

Comments
 (0)