1 package org.kuali.ole.utility.callnumber;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6 import org.solrmarc.callnum.AbstractCallNumber;
7 import org.solrmarc.callnum.CallNumber;
8
9
10
11
12
13
14
15
16 public class SuDocCallNumber extends AbstractCallNumber implements CallNumber {
17 private static final Logger Log = LoggerFactory.getLogger(SuDocCallNumber.class);
18
19
20
21
22
23 public static final String SUDOC_REGEX = "[^A-Z0-9]+|(?<=[A-Z])(?=[0-9])|(?<=[0-9])(?=[A-Z])";
24 protected String shelfKey;
25
26 private static SuDocCallNumber ourInstance = null;
27
28 public static SuDocCallNumber getInstance() {
29 if (null == ourInstance) {
30 ourInstance = new SuDocCallNumber();
31 }
32 return ourInstance;
33 }
34
35 @Override
36 public void parse(String call) {
37 try {
38 this.rawCallNum = call;
39 this.parse();
40 } catch (Exception e) {
41 Log.error("SuDoc Call Number Exception" + e);
42 }
43 }
44
45 @Override
46 public String getShelfKey() {
47 return shelfKey;
48 }
49
50 protected void parse() {
51 if (this.rawCallNum != null) {
52 this.buildShelfKey();
53 }
54
55 }
56
57 protected void buildShelfKey() {
58 String upcaseSuDoccallnum = rawCallNum.toUpperCase();
59 StringBuffer callNum = new StringBuffer();
60
61 String[] cNumSub = upcaseSuDoccallnum.split(SUDOC_REGEX);
62 for (String str : cNumSub) {
63 if (StringUtils.isNumeric(str)) {
64
65 str = StringUtils.leftPad(str, 5, "0");
66 callNum.append(str);
67 callNum.append(" ");
68 } else {
69
70 str = StringUtils.rightPad(str, 5);
71 callNum.append(str);
72 callNum.append(" ");
73 }
74 }
75 shelfKey = callNum.toString().trim();
76 }
77 }