View Javadoc
1   package org.kuali.ole.ingest.util;
2   
3   import java.util.regex.Matcher;
4   import java.util.regex.Pattern;
5   
6   /**
7    * Created with IntelliJ IDEA.
8    * User: ?
9    * Date: 11/8/12
10   * Time: 2:41 PM
11   * To change this template use File | Settings | File Templates.
12   */
13  public class OCLCUtil {
14  
15      String normalizedOclc = null;
16  
17      /**
18       * Gets oclc exists in the docstore and normalizes it.
19       * @param oclc
20       * @return normalizedOclc
21       */
22      public String normalizedOclc(String oclc) {
23  
24          StringBuffer buffer = new StringBuffer();
25          String regex = "(ocl77|ocm|ocn|on)";
26          Pattern pattern = Pattern.compile(regex);
27          Matcher matcher = pattern.matcher(oclc);
28          String modifiedString = matcher.replaceAll(""); // removes ocl77,ocm,ocn,on
29          String[] splitValues = modifiedString.split(" ");
30          if (splitValues.length > 1) {
31              for (String splitValue : splitValues) {
32                  if(splitValue.contains("(") && splitValue.contains(")")) {
33                      buffer.append(splitValue);
34                  } else {
35                      buffer.append((Integer.parseInt(splitValue))); //removes leading zeros
36                  }
37              }
38          }else {
39              String ocolc = modifiedString.substring(modifiedString.indexOf("("), modifiedString.indexOf(")") + 1);
40              buffer.append(ocolc);
41              String content = modifiedString.substring(modifiedString.indexOf(")")+1,modifiedString.length());
42              buffer.append((Integer.parseInt(content))); // removes leading zeros
43          }
44          normalizedOclc = buffer.toString();
45          return normalizedOclc;
46      }
47  
48  }