Class ISSNValidator
- java.lang.Object
-
- org.apache.commons.validator.routines.ISSNValidator
-
- All Implemented Interfaces:
java.io.Serializable
public class ISSNValidator extends java.lang.Object implements java.io.Serializable
International Standard Serial Number (ISSN) is an eight-digit serial number used to uniquely identify a serial publication.The format is: ISSN dddd-dddC where: d = decimal digit (0-9) C = checksum (0-9 or X) The checksum is formed by adding the first 7 digits multiplied by the position in the entire number (counting from the right). For example, abcd-efg would be 8a + 7b + 6c + 5d + 4e +3f +2g. The check digit is modulus 11, where the value 10 is represented by 'X' For example: ISSN 0317-8471 ISSN 1050-124X This class strips off the 'ISSN ' prefix if it is present before passing the remainder to the checksum routine.
Note: the
isValid(String)andvalidate(String)methods strip off any leading or trailing spaces before doing the validation. To ensure that only a valid code (without 'ISSN ' prefix) is passed to a method, use the following code:Object valid = validator.validate(input); if (valid != null) { some_method(valid.toString()); }- Since:
- 1.5.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ISSNValidator()Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringconvertToEAN13(java.lang.String issn, java.lang.String suffix)Converts an ISSN code to an EAN-13 code.java.lang.StringextractFromEAN13(java.lang.String ean13)Extracts an ISSN code from an ISSN-EAN-13 code.static ISSNValidatorgetInstance()Gets the singleton instance of the ISSN validator.booleanisValid(java.lang.String code)Tests whether the code is a valid ISSN code after any transformation by the validate routine.java.lang.Objectvalidate(java.lang.String code)Checks the code is valid ISSN code.java.lang.ObjectvalidateEan(java.lang.String code)Checks the code is a valid EAN code.
-
-
-
Constructor Detail
-
ISSNValidator
public ISSNValidator()
Constructs a new instance.
-
-
Method Detail
-
getInstance
public static ISSNValidator getInstance()
Gets the singleton instance of the ISSN validator.- Returns:
- A singleton instance of the ISSN validator.
-
convertToEAN13
public java.lang.String convertToEAN13(java.lang.String issn, java.lang.String suffix)
Converts an ISSN code to an EAN-13 code.This method requires a valid ISSN code. It may contain a leading 'ISSN ' prefix, as the input is passed through the
validate(String)method.- Parameters:
issn- The ISSN code to convertsuffix- the two digit suffix, for example, "00"- Returns:
- A converted EAN-13 code or
nullif the input ISSN code is not valid
-
extractFromEAN13
public java.lang.String extractFromEAN13(java.lang.String ean13)
Extracts an ISSN code from an ISSN-EAN-13 code.This method requires a valid ISSN-EAN-13 code with NO formatting characters. That is a 13 digit EAN-13 code with the '977' prefix.
- Parameters:
ean13- The ISSN code to convert- Returns:
- A valid ISSN code or
nullif the input ISSN EAN-13 code is not valid - Since:
- 1.7
-
isValid
public boolean isValid(java.lang.String code)
Tests whether the code is a valid ISSN code after any transformation by the validate routine.- Parameters:
code- The code to validate.- Returns:
trueif a valid ISSN code, otherwisefalse.
-
validate
public java.lang.Object validate(java.lang.String code)
Checks the code is valid ISSN code.If valid, this method returns the ISSN code with the 'ISSN ' prefix removed (if it was present)
- Parameters:
code- The code to validate.- Returns:
- A valid ISSN code if valid, otherwise
null.
-
validateEan
public java.lang.Object validateEan(java.lang.String code)
Checks the code is a valid EAN code.If valid, this method returns the EAN code
- Parameters:
code- The code to validate.- Returns:
- A valid EAN code if valid, otherwise
null. - Since:
- 1.7
-
-