comparison software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtElement.java @ 6:2396a569e446

new functions: externalObjects, normalizer, Unicode2Betacode
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 08 Feb 2011 14:54:09 +0100
parents
children 1ec29fdd0db8
comparison
equal deleted inserted replaced
5:94305c504178 6:2396a569e446
1 package de.mpg.mpiwg.berlin.mpdl.externalObjects.app;
2
3 import java.util.Date;
4
5 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException;
6 import de.mpg.mpiwg.berlin.mpdl.util.XmlUtil;
7
8 public class ExtElement extends ExtObject {
9 private String pageNumber;
10 private String xmlNodeId;
11 private String before;
12 private String charPos;
13 private String xpath;
14
15 public static ExtElement parseXmlStr(String xmlStr) throws ApplicationException {
16 XmlUtil xmlUtil = XmlUtil.getInstance();
17 String uid = xmlUtil.evaluateToString(xmlStr, "/object/@uid", null);
18 String dateStr = xmlUtil.evaluateToString(xmlStr, "/object/@modificationDate", null);
19 String docId = xmlUtil.evaluateToString(xmlStr, "/object/@documentId", null);
20 String pageNumber = xmlUtil.evaluateToString(xmlStr, "/object/@pageNumber", null);
21 String xmlNodeId = xmlUtil.evaluateToString(xmlStr, "/object/@xmlNodeId", null);
22 String before = xmlUtil.evaluateToString(xmlStr, "/object/@before", null);
23 String charPos = xmlUtil.evaluateToString(xmlStr, "/object/@charPos", null);
24 String xpath = xmlUtil.evaluateToString(xmlStr, "/object/@xpath", null);
25 String content = xmlUtil.evaluateToXmlString(xmlStr, "/object/content/*", null);
26 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();
30 e.setUid(uid);
31 e.setModificationDate(modDate);
32 e.setDocumentId(docId);
33 e.setPageNumber(pageNumber);
34 e.setXmlNodeId(xmlNodeId);
35 e.setXpath(xpath);
36 e.setBefore(before);
37 e.setCharPos(charPos);
38 e.setContent(content);
39 return e;
40 }
41
42 public String toString() {
43 return getXmlString();
44 }
45
46 public String getXmlString() {
47 String xmlString = "<object";
48 if (uid != null)
49 xmlString = xmlString + " uid=\"" + uid + "\"";
50 if (documentId != null)
51 xmlString = xmlString + " documentId=\"" + documentId + "\"";
52 if (pageNumber != null)
53 xmlString = xmlString + " pageNumber=\"" + pageNumber + "\"";
54 if (xmlNodeId != null)
55 xmlString = xmlString + " xmlNodeId=\"" + xmlNodeId + "\"";
56 if (before != null)
57 xmlString = xmlString + " before=\"" + before + "\"";
58 if (charPos != null)
59 xmlString = xmlString + " charPos=\"" + charPos + "\"";
60 if (xpath != null)
61 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 + ">";
68 if (content != null) {
69 // write the uid and modificationDate into the content node
70 if (! content.contains("uid")) {
71 int firstClose = content.indexOf(">");
72 if (firstClose != -1)
73 content = content.substring(0, firstClose) + " uid=\"" + uid + "\" modificationDate=\"" + modificationDate + "\" " + content.substring(firstClose);
74 }
75 xmlString = xmlString + "<content>" + content + "</content>";
76 }
77 xmlString = xmlString + "</object>";
78 return xmlString;
79 }
80
81 public String getXpath() {
82 return xpath;
83 }
84
85 public void setXpath(String xpath) {
86 this.xpath = xpath;
87 }
88
89 public String getXmlNodeId() {
90 return xmlNodeId;
91 }
92
93 public void setXmlNodeId(String xmlNodeId) {
94 this.xmlNodeId = xmlNodeId;
95 }
96
97 public String getCharPos() {
98 return charPos;
99 }
100
101 public void setCharPos(String charPos) {
102 this.charPos = charPos;
103 }
104
105 public String getPageNumber() {
106 return pageNumber;
107 }
108
109 public void setPageNumber(String pageNumber) {
110 this.pageNumber = pageNumber;
111 }
112
113 public String getBefore() {
114 return before;
115 }
116
117 public void setBefore(String before) {
118 this.before = before;
119 }
120
121 }