/** * 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() != ISBN_10_LEN) { throw new IllegalArgumentException("Invalid length " + input.length() + " for '" + input + "'"); } // Calculate the new ISBN-13 code (drop the original checkdigit) String isbn13 = "978" + input.substring(0, ISBN_10_LEN - 1); try { String checkDigit = isbn13Validator.getCheckDigit().calculate(isbn13); isbn13 += checkDigit; return isbn13; } catch (CheckDigitException e) { throw new IllegalArgumentException("Check digit error for '" + input + "' - " + e.getMessage()); } }
return ean13; } catch (CheckDigitException e) { // Should not happen throw new IllegalArgumentException("Check digit error for '" + ean13 + "' - " + e.getMessage());
assertTrue("Invalid Character[" +i +"]=" + e.getMessage(), e.getMessage().startsWith("Invalid "));
/** * 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() != ISBN_10_LEN) { throw new IllegalArgumentException("Invalid length " + input.length() + " for '" + input + "'"); } // Calculate the new ISBN-13 code (drop the original checkdigit) String isbn13 = "978" + input.substring(0, ISBN_10_LEN - 1); try { String checkDigit = isbn13Validator.getCheckDigit().calculate(isbn13); isbn13 += checkDigit; return isbn13; } catch (CheckDigitException e) { throw new IllegalArgumentException("Check digit error for '" + input + "' - " + e.getMessage()); } }
return ean13; } catch (CheckDigitException e) { // Should not happen throw new IllegalArgumentException("Check digit error for '" + ean13 + "' - " + e.getMessage());