Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty indent marc:leader #556

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading