1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.documenthandler;
17
18 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
19
20 import java.util.regex.Matcher;
21 import java.util.regex.Pattern;
22
23
24
25
26
27
28
29 public class WorkBibMarcContentHandler {
30
31 public void doPreIngestContentManipulations(RequestDocument doc, final String fileNodeUUID) {
32 String content = doc.getContent().getContent();
33 if (content != null && content != "" && content.length() > 0) {
34 Pattern pattern = Pattern.compile("tag=\"001\">.*?</controlfield");
35 Pattern pattern2 = Pattern.compile("<controlfield.*?tag=\"001\"/>");
36 Matcher matcher = pattern.matcher(content);
37 Matcher matcher2 = pattern2.matcher(content);
38 if (matcher.find()) {
39 doc.getContent().setContent(matcher.replaceAll("tag=\"001\">" + fileNodeUUID + "</controlfield"));
40 } else if (matcher2.find()) {
41 doc.getContent()
42 .setContent(matcher2.replaceAll("<controlfield tag=\"001\">" + fileNodeUUID + "</controlfield>"));
43 } else {
44 int ind = content.indexOf("</leader>") + 9;
45 if (ind == 8) {
46 ind = content.indexOf("<leader/>") + 9;
47 if (ind == 8) {
48 ind = content.indexOf("record>") + 7;
49 }
50 }
51 StringBuilder sb = new StringBuilder();
52 sb.append(content.substring(0, ind));
53 sb.append("<controlfield tag=\"001\">");
54 sb.append(fileNodeUUID);
55 sb.append("</controlfield>");
56 sb.append(content.substring(ind + 1));
57 doc.getContent().setContent(sb.toString());
58 }
59 }
60 }
61
62
63 public void doPreIngestContentManipulationsForTesting(RequestDocument doc, final String fileNodeUUID) {
64 String content = doc.getContent().getContent();
65 int ind = content.indexOf("</leader>") + 9;
66 if (ind == 8) {
67 ind = content.indexOf("<leader/>") + 9;
68 if (ind == 8) {
69 ind = content.indexOf("record>") + 7;
70 }
71 }
72 StringBuilder sb = new StringBuilder();
73 sb.append(content.substring(0, ind));
74 sb.append("<controlfield tag=\"001\">");
75 sb.append(fileNodeUUID);
76 sb.append("</controlfield>");
77 sb.append(content.substring(ind + 1));
78 doc.getContent().setContent(sb.toString());
79 }
80 }