1 package org.kuali.ole.docstore.document.jcr;
2
3
4 import org.kuali.ole.docstore.OleDocStoreException;
5 import org.kuali.ole.docstore.model.xmlpojo.ingest.RequestDocument;
6
7 import javax.jcr.Session;
8 import java.util.List;
9 import java.util.regex.Matcher;
10 import java.util.regex.Pattern;
11
12
13
14
15
16
17
18
19 public class JcrWorkBibMarcDocumentManager
20 extends JcrWorkBibDocumentManager {
21 private static JcrWorkBibMarcDocumentManager ourInstance = null;
22
23 public static JcrWorkBibMarcDocumentManager getInstance() {
24 if (null == ourInstance) {
25 ourInstance = new JcrWorkBibMarcDocumentManager();
26 }
27 return ourInstance;
28 }
29
30 protected JcrWorkBibMarcDocumentManager() {
31 super();
32 }
33
34 @Override
35 protected void modifyDocumentContent(RequestDocument doc, String nodeIdentifier, String parentNodeIdentifier) {
36 String content = doc.getContent().getContent();
37 if (content != null && content != "" && content.length() > 0) {
38 Pattern pattern = Pattern.compile("tag=\"001\">.*?</controlfield");
39 Pattern pattern2 = Pattern.compile("<controlfield.*?tag=\"001\"/>");
40 Matcher matcher = pattern.matcher(content);
41 Matcher matcher2 = pattern2.matcher(content);
42 if (matcher.find()) {
43 doc.getContent().setContent(matcher.replaceAll("tag=\"001\">" + nodeIdentifier + "</controlfield"));
44 } else if (matcher2.find()) {
45 doc.getContent()
46 .setContent(matcher2.replaceAll("<controlfield tag=\"001\">" + nodeIdentifier + "</controlfield>"));
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 @Override
67 public void validateInput(RequestDocument requestDocument, Object object, List<String> valuesList) throws OleDocStoreException {
68 Session session = (Session) object;
69 for (RequestDocument linkDoc : requestDocument.getLinkedRequestDocuments()) {
70 JcrWorkInstanceDocumentManager.getInstance().validateInput(linkDoc, session, valuesList);
71 }
72 }
73 }