comparison software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtElement.java @ 9:1ec29fdd0db8

neue .lex Dateien f?r Normalisierung / externe Objekte update
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 22 Feb 2011 16:03:45 +0100
parents 2396a569e446
children fba5577e49d9
comparison
equal deleted inserted replaced
8:d2a1c14fde31 9:1ec29fdd0db8
6 import de.mpg.mpiwg.berlin.mpdl.util.XmlUtil; 6 import de.mpg.mpiwg.berlin.mpdl.util.XmlUtil;
7 7
8 public class ExtElement extends ExtObject { 8 public class ExtElement extends ExtObject {
9 private String pageNumber; 9 private String pageNumber;
10 private String xmlNodeId; 10 private String xmlNodeId;
11 private String before; 11 private String before = "false";
12 private String charPos; 12 private String charPos;
13 private String xpath; 13 private String xpath;
14 14
15 public ExtElement() {
16 this.type = "element";
17 }
18
15 public static ExtElement parseXmlStr(String xmlStr) throws ApplicationException { 19 public static ExtElement parseXmlStr(String xmlStr) throws ApplicationException {
16 XmlUtil xmlUtil = XmlUtil.getInstance(); 20 XmlUtil xmlUtil = XmlUtil.getInstance();
21 xmlUtil.setNsContext("general");
17 String uid = xmlUtil.evaluateToString(xmlStr, "/object/@uid", null); 22 String uid = xmlUtil.evaluateToString(xmlStr, "/object/@uid", null);
18 String dateStr = xmlUtil.evaluateToString(xmlStr, "/object/@modificationDate", null); 23 String dateStr = xmlUtil.evaluateToString(xmlStr, "/object/@modificationDate", null);
19 String docId = xmlUtil.evaluateToString(xmlStr, "/object/@documentId", null); 24 String docId = xmlUtil.evaluateToString(xmlStr, "/object/@documentId", null);
20 String pageNumber = xmlUtil.evaluateToString(xmlStr, "/object/@pageNumber", null); 25 String pageNumber = xmlUtil.evaluateToString(xmlStr, "/object/@pageNumber", null);
21 String xmlNodeId = xmlUtil.evaluateToString(xmlStr, "/object/@xmlNodeId", null); 26 String xmlNodeId = xmlUtil.evaluateToString(xmlStr, "/object/@xmlNodeId", null);
22 String before = xmlUtil.evaluateToString(xmlStr, "/object/@before", null); 27 String before = xmlUtil.evaluateToString(xmlStr, "/object/@before", null);
23 String charPos = xmlUtil.evaluateToString(xmlStr, "/object/@charPos", null); 28 String charPos = xmlUtil.evaluateToString(xmlStr, "/object/@charPos", null);
24 String xpath = xmlUtil.evaluateToString(xmlStr, "/object/@xpath", null); 29 String xpath = xmlUtil.evaluateToString(xmlStr, "/object/@xpath", null);
25 String content = xmlUtil.evaluateToXmlString(xmlStr, "/object/content/*", null); 30 String content = xmlUtil.evaluateToXmlString(xmlStr, "/object/content/*", null);
26 Date modDate = xmlUtil.toDate(dateStr); 31 Date modDate = xmlUtil.toDate(dateStr);
27 if (uid == null || docId == null || pageNumber == null)
28 throw new ApplicationException("one of the required fields could not be read in: " + xmlStr);
29 ExtElement e = new ExtElement(); 32 ExtElement e = new ExtElement();
30 e.setUid(uid); 33 e.setUid(uid);
31 e.setModificationDate(modDate); 34 e.setModificationDate(modDate);
32 e.setDocumentId(docId); 35 e.setDocumentId(docId);
33 e.setPageNumber(pageNumber); 36 e.setPageNumber(pageNumber);
42 public String toString() { 45 public String toString() {
43 return getXmlString(); 46 return getXmlString();
44 } 47 }
45 48
46 public String getXmlString() { 49 public String getXmlString() {
47 String xmlString = "<object"; 50 String xmlString = "<object xmlns:xlink=\"http://www.w3.org/1999/xlink\"";
51 xmlString = xmlString + " type=\"" + type + "\"";
52 if (modificationDate != null) {
53 XmlUtil xmlUtil = XmlUtil.getInstance();
54 String dateStr = xmlUtil.toXsDate(modificationDate);
55 xmlString = xmlString + " modificationDate=\"" + dateStr + "\"";
56 }
48 if (uid != null) 57 if (uid != null)
49 xmlString = xmlString + " uid=\"" + uid + "\""; 58 xmlString = xmlString + " uid=\"" + uid + "\"";
50 if (documentId != null) 59 if (documentId != null)
51 xmlString = xmlString + " documentId=\"" + documentId + "\""; 60 xmlString = xmlString + " documentId=\"" + documentId + "\"";
52 if (pageNumber != null) 61 if (pageNumber != null)
57 xmlString = xmlString + " before=\"" + before + "\""; 66 xmlString = xmlString + " before=\"" + before + "\"";
58 if (charPos != null) 67 if (charPos != null)
59 xmlString = xmlString + " charPos=\"" + charPos + "\""; 68 xmlString = xmlString + " charPos=\"" + charPos + "\"";
60 if (xpath != null) 69 if (xpath != null)
61 xmlString = xmlString + " xpath=\"" + xpath + "\""; 70 xmlString = xmlString + " xpath=\"" + xpath + "\"";
62 if (modificationDate != null) {
63 XmlUtil xmlUtil = XmlUtil.getInstance();
64 String dateStr = xmlUtil.toXsDate(modificationDate);
65 xmlString = xmlString + " modificationDate=\"" + dateStr + "\"";
66 }
67 xmlString = xmlString + ">"; 71 xmlString = xmlString + ">";
68 if (content != null) { 72 if (content != null) {
69 // write the uid and modificationDate into the content node 73 // write the uid and modificationDate into the content node
70 if (! content.contains("uid")) { 74 if (! content.contains("uid")) {
71 int firstClose = content.indexOf(">"); 75 int firstClose = content.indexOf(">");
108 112
109 public void setPageNumber(String pageNumber) { 113 public void setPageNumber(String pageNumber) {
110 this.pageNumber = pageNumber; 114 this.pageNumber = pageNumber;
111 } 115 }
112 116
117 public boolean isBefore() {
118 if (before != null && before.equals("true"))
119 return true;
120 else
121 return false;
122 }
123
113 public String getBefore() { 124 public String getBefore() {
114 return before; 125 return before;
115 } 126 }
116 127
117 public void setBefore(String before) { 128 public void setBefore(String before) {