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 2 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,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();
}
}

Expand All @@ -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());
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