-
Notifications
You must be signed in to change notification settings - Fork 34
Improve Exception messages when working on "leader" #573
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
06a62ff
29b9759
eab57cd
b7d9e81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,6 +81,7 @@ public final class Marc21Encoder extends | |||||
private State state = State.IN_STREAM; | ||||||
|
||||||
private boolean generateIdField; | ||||||
private boolean validateLeader = true; | ||||||
|
||||||
/** | ||||||
* Initializes the encoder with MARC 21 constants and charset. | ||||||
|
@@ -108,6 +109,18 @@ public void setGenerateIdField(final boolean generateIdField) { | |||||
this.generateIdField = generateIdField; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Controls whether the leader should be validated. | ||||||
* <p> | ||||||
* The default value of {@code validateLeader} is true. | ||||||
* <p> | ||||||
* | ||||||
* @param validateLeader if false the leader is not validated | ||||||
*/ | ||||||
public void setValidateLeader(final boolean validateLeader) { | ||||||
this.validateLeader = validateLeader; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Gets the flag to decide whether the ID field is generated. | ||||||
* | ||||||
|
@@ -157,7 +170,7 @@ public void startEntity(final String name) { | |||||
|
||||||
private void startField(final String name) { | ||||||
if (name.length() != NAME_LENGTH) { | ||||||
throw new FormatException("invalid entity name: " + name); | ||||||
throw new FormatException("invalid leader entity name: " + name); | ||||||
} | ||||||
final char[] tag = new char[RecordFormat.TAG_LENGTH]; | ||||||
final char[] indicators = new char[Marc21Constants.MARC21_FORMAT.getIndicatorLength()]; | ||||||
|
@@ -214,7 +227,7 @@ private void processLeaderAsOneLiteral(final String value) { | |||||
private void processLeaderAsSubfields(final String name, final String value) { | ||||||
if (value.length() != 1) { | ||||||
throw new FormatException( | ||||||
"literal must only contain a single character:" + name); | ||||||
"leader literal must only contain a single character:" + name); | ||||||
} | ||||||
processLeaderAsSubfields(name, value.charAt(0)); | ||||||
} | ||||||
|
@@ -259,12 +272,14 @@ private void processLeaderAsSubfields(final String name, final char code) { | |||||
} | ||||||
|
||||||
private void requireValidCode(final char code, final char[] validCodes) { | ||||||
for (final char validCode: validCodes) { | ||||||
if (validCode == code) { | ||||||
return; | ||||||
if (validateLeader) { | ||||||
for (final char validCode : validCodes) { | ||||||
if (validCode == code) { | ||||||
return; | ||||||
} | ||||||
} | ||||||
throw new FormatException("invalid code in leader'" + code + "'; allowed codes are: " + Arrays.toString(validCodes)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dr0i is it possible to add the info about the leader element? like this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You've proposed to add |
||||||
} | ||||||
throw new FormatException("invalid code '" + code + "'; allowed codes are: " + Arrays.toString(validCodes)); | ||||||
} | ||||||
|
||||||
private void processTopLevelLiteral(final String name, final String value) { | ||||||
|
Uh oh!
There was an error while loading. Please reload this page.