1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.common;
|
5
|
|
6
|
import java.util.regex.Pattern;
|
7
|
|
8
|
import org.apache.log4j.Logger;
|
9
|
|
10
|
/**
|
11
|
* @author a.mueller
|
12
|
* @created 2013-Aug-02
|
13
|
*
|
14
|
*/
|
15
|
public class GeneralParser {
|
16
|
@SuppressWarnings("unused")
|
17
|
private static final Logger logger = Logger.getLogger(GeneralParser.class);
|
18
|
|
19
|
static String isbnPatternStr = "^(ISBN\\s*)?(\\d-?){9}((\\d-?){3})?(\\d|X)$";
|
20
|
static Pattern isbnPattern;
|
21
|
|
22
|
/**
|
23
|
* Checks if a string follows the ISBN pattern (10 and 13 digits). It does not check the
|
24
|
* checksum of an isbn (http://en.wikipedia.org/wiki/International_Standard_Book_Number#ISBN-13_check_digit_calculation).
|
25
|
* We may implement this separately as sometimes additional checksum validation is unwanted.
|
26
|
* @param isbn
|
27
|
* @return
|
28
|
*/
|
29
|
public static boolean isIsbn(String isbn){
|
30
|
// if (isbnPattern == null){
|
31
|
// isbnPattern = Pattern.compile(isbnPatternStr);
|
32
|
// }
|
33
|
// Matcher matcher = isbnPattern.matcher(isbn);
|
34
|
if (isbn == null){
|
35
|
return false;
|
36
|
}else{
|
37
|
return isbn.matches(isbnPatternStr);
|
38
|
}
|
39
|
|
40
|
|
41
|
|
42
|
}
|
43
|
|
44
|
}
|