1 package org.kuali.ole.docstore.document;
2
3
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
6
7 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
8 import org.kuali.ole.docstore.repository.WorkBibNodeManager;
9
10
11
12
13
14
15
16
17 public class WorkBibMarcDocumentManager
18 extends WorkBibDocumentManager {
19 private static WorkBibMarcDocumentManager ourInstance = null;
20
21 public static WorkBibMarcDocumentManager getInstance() {
22 if (null == ourInstance) {
23 ourInstance = new WorkBibMarcDocumentManager();
24 }
25 return ourInstance;
26 }
27
28 protected WorkBibMarcDocumentManager() {
29 super();
30 }
31
32 @Override
33 protected void modifyDocumentContent(RequestDocument doc, String nodeIdentifier, String parentNodeIdentifier) {
34 String content = doc.getContent().getContent();
35 if (content != null && content != "" && content.length() > 0) {
36 Pattern pattern = Pattern.compile("tag=\"001\">.*?</controlfield");
37 Pattern pattern2 = Pattern.compile("<controlfield.*?tag=\"001\"/>");
38 Matcher matcher = pattern.matcher(content);
39 Matcher matcher2 = pattern2.matcher(content);
40 if (matcher.find()) {
41 doc.getContent().setContent(matcher.replaceAll("tag=\"001\">" + nodeIdentifier + "</controlfield"));
42 }
43 else if (matcher2.find()) {
44 doc.getContent()
45 .setContent(matcher2.replaceAll("<controlfield tag=\"001\">" + nodeIdentifier + "</controlfield>"));
46 }
47 else {
48 int ind = content.indexOf("</leader>") + 9;
49 if (ind == 8) {
50 ind = content.indexOf("<leader/>") + 9;
51 if (ind == 8) {
52 ind = content.indexOf("record>") + 7;
53 }
54 }
55 StringBuilder sb = new StringBuilder();
56 sb.append(content.substring(0, ind));
57 sb.append("<controlfield tag=\"001\">");
58 sb.append(nodeIdentifier);
59 sb.append("</controlfield>");
60 sb.append(content.substring(ind + 1));
61 doc.getContent().setContent(sb.toString());
62 }
63 }
64 }
65
66 }