Skip to content

Commit

Permalink
Merge #556 from branch '550-prettyIndentMarcLeader' of github.com:met…
Browse files Browse the repository at this point in the history
…afacture/metafacture-core
  • Loading branch information
dr0i committed Sep 6, 2024
2 parents 57f9344 + 066a483 commit fee2bcb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,17 @@ private void writeEscaped(final String str) {
private void writeLeader() {
final String leader = leaderBuilder.toString();
if (leaderBuilder.length() > 0) {
prettyPrintIndentation();
if (formatted) {
writeRawLeader(getIndentationPrefix());
}

writeTagLeader(Tag.leader::open);
writeRawLeader(leader);
writeTagLeader(Tag.leader::close);
prettyPrintNewLine();

if (formatted) {
writeRawLeader(NEW_LINE);
}
}
}

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

private String getIndentationPrefix() {
return String.join("", Collections.nCopies(indentationLevel, INDENT));
}

private void prettyPrintIndentation() {
if (formatted) {
final String prefix = String.join("", Collections.nCopies(indentationLevel, INDENT));
builder.append(prefix);
builder.append(getIndentationPrefix());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"// " <marc:record>\n"
String expected = XML_DECLARATION + "\n" + XML_ROOT_OPEN + "\n"
+ "\t<marc:record>\n"//
+ "\t\t<marc:leader>dummy</marc:leader>\n"
+ "\t\t<marc:controlfield tag=\"001\">92005291</marc:controlfield>\n"//
+ "\t\t<marc:datafield tag=\"010\" ind1=\" \" ind2=\" \">\n"//
+ "\t\t\t<marc:subfield code=\"a\">92005291</marc:subfield>\n"//
Expand Down

0 comments on commit fee2bcb

Please sign in to comment.