Class ISBNValidator
- java.lang.Object
-
- org.apache.commons.validator.routines.ISBNValidator
-
- All Implemented Interfaces:
java.io.Serializable
public class ISBNValidator extends java.lang.Object implements java.io.Serializable
ISBN-10 and ISBN-13 Code Validation.This validator validates the code is either a valid ISBN-10 (using a
CodeValidator
with theISBN10CheckDigit
) or a valid ISBN-13 code (using aCodeValidator
with the theEAN13CheckDigit
routine).The
validate()
methods return the ISBN code with formatting characters removed if valid ornull
if invalid.This validator also provides the facility to convert ISBN-10 codes to ISBN-13 if the
convert
property istrue
.From 1st January 2007 the book industry will start to use a new 13 digit ISBN number (rather than this 10 digit ISBN number). ISBN-13 codes are EAN codes, for more information see:
- Since:
- Validator 1.4
- Version:
- $Revision: 1649191 $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
convert
private static java.lang.String
GROUP
private static ISBNValidator
ISBN_VALIDATOR
ISBN Code Validator (which converts ISBN-10 codes to ISBN-13private static ISBNValidator
ISBN_VALIDATOR_NO_CONVERT
ISBN Code Validator (which converts ISBN-10 codes to ISBN-13(package private) static java.lang.String
ISBN10_REGEX
ISBN-10 consists of 4 groups of numbers separated by either dashes (-) or spaces.private CodeValidator
isbn10Validator
ISBN-10 Code Validator(package private) static java.lang.String
ISBN13_REGEX
ISBN-13 consists of 5 groups of numbers separated by either dashes (-) or spaces.private CodeValidator
isbn13Validator
ISBN-13 Code Validatorprivate static java.lang.String
PUBLISHER
private static java.lang.String
SEP
private static long
serialVersionUID
private static java.lang.String
TITLE
-
Constructor Summary
Constructors Constructor Description ISBNValidator()
Construct an ISBN validator which converts ISBN-10 codes to ISBN-13.ISBNValidator(boolean convert)
Construct an ISBN validator indicating whether ISBN-10 codes should be converted to ISBN-13.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
convertToISBN13(java.lang.String isbn10)
Convert an ISBN-10 code to an ISBN-13 code.static ISBNValidator
getInstance()
Return a singleton instance of the ISBN validator which converts ISBN-10 codes to ISBN-13.static ISBNValidator
getInstance(boolean convert)
Return a singleton instance of the ISBN validator specifying whether ISBN-10 codes should be converted to ISBN-13.boolean
isValid(java.lang.String code)
Check the code is either a valid ISBN-10 or ISBN-13 code.boolean
isValidISBN10(java.lang.String code)
Check the code is a valid ISBN-10 code.boolean
isValidISBN13(java.lang.String code)
Check the code is a valid ISBN-13 code.java.lang.String
validate(java.lang.String code)
Check the code is either a valid ISBN-10 or ISBN-13 code.java.lang.String
validateISBN10(java.lang.String code)
Check the code is a valid ISBN-10 code.java.lang.String
validateISBN13(java.lang.String code)
Check the code is a valid ISBN-13 code.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
SEP
private static final java.lang.String SEP
- See Also:
- Constant Field Values
-
GROUP
private static final java.lang.String GROUP
- See Also:
- Constant Field Values
-
PUBLISHER
private static final java.lang.String PUBLISHER
- See Also:
- Constant Field Values
-
TITLE
private static final java.lang.String TITLE
- See Also:
- Constant Field Values
-
ISBN10_REGEX
static final java.lang.String ISBN10_REGEX
ISBN-10 consists of 4 groups of numbers separated by either dashes (-) or spaces. The first group is 1-5 characters, second 1-7, third 1-6, and fourth is 1 digit or an X.- See Also:
- Constant Field Values
-
ISBN13_REGEX
static final java.lang.String ISBN13_REGEX
ISBN-13 consists of 5 groups of numbers separated by either dashes (-) or spaces. The first group is 978 or 979, the second group is 1-5 characters, third 1-7, fourth 1-6, and fifth is 1 digit.- See Also:
- Constant Field Values
-
ISBN_VALIDATOR
private static final ISBNValidator ISBN_VALIDATOR
ISBN Code Validator (which converts ISBN-10 codes to ISBN-13
-
ISBN_VALIDATOR_NO_CONVERT
private static final ISBNValidator ISBN_VALIDATOR_NO_CONVERT
ISBN Code Validator (which converts ISBN-10 codes to ISBN-13
-
isbn10Validator
private final CodeValidator isbn10Validator
ISBN-10 Code Validator
-
isbn13Validator
private final CodeValidator isbn13Validator
ISBN-13 Code Validator
-
convert
private final boolean convert
-
-
Constructor Detail
-
ISBNValidator
public ISBNValidator()
Construct an ISBN validator which converts ISBN-10 codes to ISBN-13.
-
ISBNValidator
public ISBNValidator(boolean convert)
Construct an ISBN validator indicating whether ISBN-10 codes should be converted to ISBN-13.- Parameters:
convert
-true
if valid ISBN-10 codes should be converted to ISBN-13 codes orfalse
if valid ISBN-10 codes should be returned unchanged.
-
-
Method Detail
-
getInstance
public static ISBNValidator getInstance()
Return a singleton instance of the ISBN validator which converts ISBN-10 codes to ISBN-13.- Returns:
- A singleton instance of the ISBN validator.
-
getInstance
public static ISBNValidator getInstance(boolean convert)
Return a singleton instance of the ISBN validator specifying whether ISBN-10 codes should be converted to ISBN-13.- Parameters:
convert
-true
if valid ISBN-10 codes should be converted to ISBN-13 codes orfalse
if valid ISBN-10 codes should be returned unchanged.- Returns:
- A singleton instance of the ISBN validator.
-
isValid
public boolean isValid(java.lang.String code)
Check the code is either a valid ISBN-10 or ISBN-13 code.- Parameters:
code
- The code to validate.- Returns:
true
if a valid ISBN-10 or ISBN-13 code, otherwisefalse
.
-
isValidISBN10
public boolean isValidISBN10(java.lang.String code)
Check the code is a valid ISBN-10 code.- Parameters:
code
- The code to validate.- Returns:
true
if a valid ISBN-10 code, otherwisefalse
.
-
isValidISBN13
public boolean isValidISBN13(java.lang.String code)
Check the code is a valid ISBN-13 code.- Parameters:
code
- The code to validate.- Returns:
true
if a valid ISBN-13 code, otherwisefalse
.
-
validate
public java.lang.String validate(java.lang.String code)
Check the code is either a valid ISBN-10 or ISBN-13 code.If valid, this method returns the ISBN code with formatting characters removed (i.e. space or hyphen).
Converts an ISBN-10 codes to ISBN-13 if
convertToISBN13
istrue
.- Parameters:
code
- The code to validate.- Returns:
- A valid ISBN code if valid, otherwise
null
.
-
validateISBN10
public java.lang.String validateISBN10(java.lang.String code)
Check the code is a valid ISBN-10 code.If valid, this method returns the ISBN-10 code with formatting characters removed (i.e. space or hyphen).
- Parameters:
code
- The code to validate.- Returns:
- A valid ISBN-10 code if valid,
otherwise
null
.
-
validateISBN13
public java.lang.String validateISBN13(java.lang.String code)
Check the code is a valid ISBN-13 code.If valid, this method returns the ISBN-13 code with formatting characters removed (i.e. space or hyphen).
- Parameters:
code
- The code to validate.- Returns:
- A valid ISBN-13 code if valid,
otherwise
null
.
-
convertToISBN13
public java.lang.String convertToISBN13(java.lang.String isbn10)
Convert an ISBN-10 code to an ISBN-13 code.This method requires a valid ISBN-10 with NO formatting characters.
- Parameters:
isbn10
- The ISBN-10 code to convert- Returns:
- A converted ISBN-13 code or
null
if the ISBN-10 code is not valid
-
-