private void validateCodeAttributeValue(CodeAttribute attribute, ValidationResults results) { CodeParentValidator parentValidator = new CodeParentValidator(); ValidationResultFlag validParent = parentValidator.evaluate(attribute); if (validParent == ValidationResultFlag.OK) { CodeValidator codeValidator = new CodeValidator(); ValidationResultFlag result = codeValidator.evaluate(attribute); results.addResult(codeValidator, result); } else { results.addResult(parentValidator, ValidationResultFlag.WARNING); } }
/** * Convert an ISBN-10 code to an ISBN-13 code. * * <p>This method requires a valid ISBN-10 with NO formatting characters. * * @param isbn10 The ISBN-10 code to convert * @return A converted ISBN-13 code or <code>null</code> if the ISBN-10 code is not valid */ public String convertToISBN13(String isbn10) { if (isbn10 == null) { return null; } String input = isbn10.trim(); if (input.length() != 10) { throw new IllegalArgumentException( "Invalid length " + input.length() + " for '" + input + "'"); } // Calculate the new ISBN-13 code String isbn13 = "978" + input.substring(0, 9); try { String checkDigit = isbn13Validator.getCheckDigit().calculate(isbn13); isbn13 += checkDigit; return isbn13; } catch (CheckDigitException e) { throw new IllegalArgumentException( "Check digit error for '" + input + "' - " + e.getMessage()); } }
/** * Check the code is a valid ISBN-13 code. * * <p>If valid, this method returns the ISBN-13 code with formatting characters removed (i.e. * space or hyphen). * * @param code The code to validate. * @return A valid ISBN-13 code if valid, otherwise <code>null</code>. */ public String validateISBN13(String code) { Object result = isbn13Validator.validate(code); return (result == null ? null : result.toString()); }
/** * Check the code is a valid ISBN-13 code. * * @param code The code to validate. * @return <code>true</code> if a valid ISBN-13 code, otherwise <code>false</code>. */ public boolean isValidISBN13(String code) { return isbn13Validator.isValid(code); }