Mercurial > hg > mpdl-group
comparison software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtElement.java @ 12:fba5577e49d9
diverse Fehlerbehebungen
author | Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 19 Apr 2011 16:51:26 +0200 |
parents | 1ec29fdd0db8 |
children | 5df60f24e997 |
comparison
equal
deleted
inserted
replaced
11:d6f528ad5d96 | 12:fba5577e49d9 |
---|---|
5 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; | 5 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; |
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 xpath; // path to element |
11 private String before = "false"; | 11 private String point; // ".0", ".1" or a positive integer |
12 private String charPos; | |
13 private String xpath; | |
14 | 12 |
15 public ExtElement() { | 13 public ExtElement() { |
16 this.type = "element"; | 14 this.type = "element"; |
17 } | 15 } |
18 | 16 |
20 XmlUtil xmlUtil = XmlUtil.getInstance(); | 18 XmlUtil xmlUtil = XmlUtil.getInstance(); |
21 xmlUtil.setNsContext("general"); | 19 xmlUtil.setNsContext("general"); |
22 String uid = xmlUtil.evaluateToString(xmlStr, "/object/@uid", null); | 20 String uid = xmlUtil.evaluateToString(xmlStr, "/object/@uid", null); |
23 String dateStr = xmlUtil.evaluateToString(xmlStr, "/object/@modificationDate", null); | 21 String dateStr = xmlUtil.evaluateToString(xmlStr, "/object/@modificationDate", null); |
24 String docId = xmlUtil.evaluateToString(xmlStr, "/object/@documentId", null); | 22 String docId = xmlUtil.evaluateToString(xmlStr, "/object/@documentId", null); |
25 String pageNumber = xmlUtil.evaluateToString(xmlStr, "/object/@pageNumber", null); | 23 String xpointer = xmlUtil.evaluateToString(xmlStr, "/object/@xpointer", null); |
26 String xmlNodeId = xmlUtil.evaluateToString(xmlStr, "/object/@xmlNodeId", null); | 24 String pageNumber = null; |
27 String before = xmlUtil.evaluateToString(xmlStr, "/object/@before", null); | 25 String xpath = null; |
28 String charPos = xmlUtil.evaluateToString(xmlStr, "/object/@charPos", null); | 26 String point = null; |
29 String xpath = xmlUtil.evaluateToString(xmlStr, "/object/@xpath", null); | 27 if (xpointer != null) { |
28 pageNumber = xpointer.replaceAll("#xpointer\\(id\\('page(.+)?'\\).*", "$1"); | |
29 if (xpointer.contains("point(")) { | |
30 xpath = xpointer.replaceAll("#xpointer\\(id\\('page.+?'\\)(.*)?/point\\(.+?\\)\\)", "$1"); | |
31 point = xpointer.replaceAll("#xpointer\\(id\\('page.+?'\\).*?/point\\((.+)?\\)\\)", "$1"); | |
32 } else { | |
33 xpath = xpointer.replaceAll("#xpointer\\(id\\('page.+?'\\)(.*)?.*?\\)", "$1"); | |
34 } | |
35 } | |
30 String content = xmlUtil.evaluateToXmlString(xmlStr, "/object/content/*", null); | 36 String content = xmlUtil.evaluateToXmlString(xmlStr, "/object/content/*", null); |
31 Date modDate = xmlUtil.toDate(dateStr); | 37 Date modDate = xmlUtil.toDate(dateStr); |
32 ExtElement e = new ExtElement(); | 38 ExtElement e = new ExtElement(); |
33 e.setUid(uid); | 39 e.setUid(uid); |
34 e.setModificationDate(modDate); | 40 e.setModificationDate(modDate); |
35 e.setDocumentId(docId); | 41 e.setDocumentId(docId); |
36 e.setPageNumber(pageNumber); | 42 e.setPageNumber(pageNumber); |
37 e.setXmlNodeId(xmlNodeId); | |
38 e.setXpath(xpath); | 43 e.setXpath(xpath); |
39 e.setBefore(before); | 44 e.setPoint(point); |
40 e.setCharPos(charPos); | |
41 e.setContent(content); | 45 e.setContent(content); |
42 return e; | 46 return e; |
43 } | 47 } |
44 | 48 |
45 public String toString() { | 49 public String toString() { |
56 } | 60 } |
57 if (uid != null) | 61 if (uid != null) |
58 xmlString = xmlString + " uid=\"" + uid + "\""; | 62 xmlString = xmlString + " uid=\"" + uid + "\""; |
59 if (documentId != null) | 63 if (documentId != null) |
60 xmlString = xmlString + " documentId=\"" + documentId + "\""; | 64 xmlString = xmlString + " documentId=\"" + documentId + "\""; |
65 if (xpath != null) | |
66 xmlString = xmlString + " xmlNodeId=\"" + xpath + "\""; | |
61 if (pageNumber != null) | 67 if (pageNumber != null) |
62 xmlString = xmlString + " pageNumber=\"" + pageNumber + "\""; | 68 xmlString = xmlString + " xpointer=\"#xpointer(id('page" + pageNumber + "')"; |
63 if (xmlNodeId != null) | |
64 xmlString = xmlString + " xmlNodeId=\"" + xmlNodeId + "\""; | |
65 if (before != null) | |
66 xmlString = xmlString + " before=\"" + before + "\""; | |
67 if (charPos != null) | |
68 xmlString = xmlString + " charPos=\"" + charPos + "\""; | |
69 if (xpath != null) | 69 if (xpath != null) |
70 xmlString = xmlString + " xpath=\"" + xpath + "\""; | 70 xmlString = xmlString + xpath; |
71 xmlString = xmlString + ">"; | 71 if (point != null) |
72 xmlString = xmlString + "/point(" + point + ")"; | |
73 xmlString = xmlString + ")\">"; | |
72 if (content != null) { | 74 if (content != null) { |
75 // TODO wieder ausbauen | |
73 // write the uid and modificationDate into the content node | 76 // write the uid and modificationDate into the content node |
74 if (! content.contains("uid")) { | 77 if (! content.contains("uid")) { |
75 int firstClose = content.indexOf(">"); | 78 int firstClose = content.indexOf(">"); |
76 if (firstClose != -1) | 79 if (firstClose != -1) |
77 content = content.substring(0, firstClose) + " uid=\"" + uid + "\" modificationDate=\"" + modificationDate + "\" " + content.substring(firstClose); | 80 content = content.substring(0, firstClose) + " uid=\"" + uid + "\" modificationDate=\"" + modificationDate + "\" " + content.substring(firstClose); |
88 | 91 |
89 public void setXpath(String xpath) { | 92 public void setXpath(String xpath) { |
90 this.xpath = xpath; | 93 this.xpath = xpath; |
91 } | 94 } |
92 | 95 |
93 public String getXmlNodeId() { | 96 public String getPoint() { |
94 return xmlNodeId; | 97 return point; |
95 } | 98 } |
96 | 99 |
97 public void setXmlNodeId(String xmlNodeId) { | 100 public void setPoint(String point) { |
98 this.xmlNodeId = xmlNodeId; | 101 this.point = point; |
99 } | |
100 | |
101 public String getCharPos() { | |
102 return charPos; | |
103 } | |
104 | |
105 public void setCharPos(String charPos) { | |
106 this.charPos = charPos; | |
107 } | 102 } |
108 | 103 |
109 public String getPageNumber() { | 104 public String getPageNumber() { |
110 return pageNumber; | 105 return pageNumber; |
111 } | 106 } |
112 | 107 |
113 public void setPageNumber(String pageNumber) { | 108 public void setPageNumber(String pageNumber) { |
114 this.pageNumber = pageNumber; | 109 this.pageNumber = pageNumber; |
115 } | 110 } |
116 | 111 |
117 public boolean isBefore() { | |
118 if (before != null && before.equals("true")) | |
119 return true; | |
120 else | |
121 return false; | |
122 } | |
123 | |
124 public String getBefore() { | |
125 return before; | |
126 } | |
127 | |
128 public void setBefore(String before) { | |
129 this.before = before; | |
130 } | |
131 | |
132 } | 112 } |