001package org.kuali.ole.ingest.util;
002
003import java.util.regex.Matcher;
004import java.util.regex.Pattern;
005
006/**
007 * Created with IntelliJ IDEA.
008 * User: ?
009 * Date: 11/8/12
010 * Time: 2:41 PM
011 * To change this template use File | Settings | File Templates.
012 */
013public class OCLCUtil {
014
015    String normalizedOclc = null;
016
017    /**
018     * Gets oclc exists in the docstore and normalizes it.
019     * @param oclc
020     * @return normalizedOclc
021     */
022    public String normalizedOclc(String oclc) {
023
024        StringBuffer buffer = new StringBuffer();
025        String regex = "(ocl77|ocm|ocn|on)";
026        Pattern pattern = Pattern.compile(regex);
027        Matcher matcher = pattern.matcher(oclc);
028        String modifiedString = matcher.replaceAll(""); // removes ocl77,ocm,ocn,on
029        String[] splitValues = modifiedString.split(" ");
030        if (splitValues.length > 1) {
031            for (String splitValue : splitValues) {
032                if(splitValue.contains("(") && splitValue.contains(")")) {
033                    buffer.append(splitValue);
034                } else {
035                    buffer.append((Integer.parseInt(splitValue))); //removes leading zeros
036                }
037            }
038        }else {
039            String ocolc = modifiedString.substring(modifiedString.indexOf("("), modifiedString.indexOf(")") + 1);
040            buffer.append(ocolc);
041            String content = modifiedString.substring(modifiedString.indexOf(")")+1,modifiedString.length());
042            buffer.append((Integer.parseInt(content))); // removes leading zeros
043        }
044        normalizedOclc = buffer.toString();
045        return normalizedOclc;
046    }
047
048}