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 }
41 else if (matcher2.find()) {
42 doc.getContent()
43 .setContent(matcher2.replaceAll("<controlfield tag=\"001\">" + fileNodeUUID + "</controlfield>"));
44 }
45 else {
46 int ind = content.indexOf("</leader>") + 9;
47 if (ind == 8) {
48 ind = content.indexOf("<leader/>") + 9;
49 if (ind == 8) {
50 ind = content.indexOf("record>") + 7;
51 }
52 }
53 StringBuilder sb = new StringBuilder();
54 sb.append(content.substring(0, ind));
55 sb.append("<controlfield tag=\"001\">");
56 sb.append(fileNodeUUID);
57 sb.append("</controlfield>");
58 sb.append(content.substring(ind + 1));
59 doc.getContent().setContent(sb.toString());
60 }
61 }
62 }
63 }