Mercurial > hg > mpdl-group
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtElement.java Tue Feb 08 14:54:09 2011 +0100 @@ -0,0 +1,121 @@ +package de.mpg.mpiwg.berlin.mpdl.externalObjects.app; + +import java.util.Date; + +import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; +import de.mpg.mpiwg.berlin.mpdl.util.XmlUtil; + +public class ExtElement extends ExtObject { + private String pageNumber; + private String xmlNodeId; + private String before; + private String charPos; + private String xpath; + + public static ExtElement parseXmlStr(String xmlStr) throws ApplicationException { + XmlUtil xmlUtil = XmlUtil.getInstance(); + String uid = xmlUtil.evaluateToString(xmlStr, "/object/@uid", null); + String dateStr = xmlUtil.evaluateToString(xmlStr, "/object/@modificationDate", null); + String docId = xmlUtil.evaluateToString(xmlStr, "/object/@documentId", null); + String pageNumber = xmlUtil.evaluateToString(xmlStr, "/object/@pageNumber", null); + String xmlNodeId = xmlUtil.evaluateToString(xmlStr, "/object/@xmlNodeId", null); + String before = xmlUtil.evaluateToString(xmlStr, "/object/@before", null); + String charPos = xmlUtil.evaluateToString(xmlStr, "/object/@charPos", null); + String xpath = xmlUtil.evaluateToString(xmlStr, "/object/@xpath", null); + String content = xmlUtil.evaluateToXmlString(xmlStr, "/object/content/*", null); + Date modDate = xmlUtil.toDate(dateStr); + if (uid == null || docId == null || pageNumber == null) + throw new ApplicationException("one of the required fields could not be read in: " + xmlStr); + ExtElement e = new ExtElement(); + e.setUid(uid); + e.setModificationDate(modDate); + e.setDocumentId(docId); + e.setPageNumber(pageNumber); + e.setXmlNodeId(xmlNodeId); + e.setXpath(xpath); + e.setBefore(before); + e.setCharPos(charPos); + e.setContent(content); + return e; + } + + public String toString() { + return getXmlString(); + } + + public String getXmlString() { + String xmlString = "<object"; + if (uid != null) + xmlString = xmlString + " uid=\"" + uid + "\""; + if (documentId != null) + xmlString = xmlString + " documentId=\"" + documentId + "\""; + if (pageNumber != null) + xmlString = xmlString + " pageNumber=\"" + pageNumber + "\""; + if (xmlNodeId != null) + xmlString = xmlString + " xmlNodeId=\"" + xmlNodeId + "\""; + if (before != null) + xmlString = xmlString + " before=\"" + before + "\""; + if (charPos != null) + xmlString = xmlString + " charPos=\"" + charPos + "\""; + if (xpath != null) + xmlString = xmlString + " xpath=\"" + xpath + "\""; + if (modificationDate != null) { + XmlUtil xmlUtil = XmlUtil.getInstance(); + String dateStr = xmlUtil.toXsDate(modificationDate); + xmlString = xmlString + " modificationDate=\"" + dateStr + "\""; + } + xmlString = xmlString + ">"; + if (content != null) { + // write the uid and modificationDate into the content node + if (! content.contains("uid")) { + int firstClose = content.indexOf(">"); + if (firstClose != -1) + content = content.substring(0, firstClose) + " uid=\"" + uid + "\" modificationDate=\"" + modificationDate + "\" " + content.substring(firstClose); + } + xmlString = xmlString + "<content>" + content + "</content>"; + } + xmlString = xmlString + "</object>"; + return xmlString; + } + + public String getXpath() { + return xpath; + } + + public void setXpath(String xpath) { + this.xpath = xpath; + } + + public String getXmlNodeId() { + return xmlNodeId; + } + + public void setXmlNodeId(String xmlNodeId) { + this.xmlNodeId = xmlNodeId; + } + + public String getCharPos() { + return charPos; + } + + public void setCharPos(String charPos) { + this.charPos = charPos; + } + + public String getPageNumber() { + return pageNumber; + } + + public void setPageNumber(String pageNumber) { + this.pageNumber = pageNumber; + } + + public String getBefore() { + return before; + } + + public void setBefore(String before) { + this.before = before; + } + +}