Mercurial > hg > mpdl-group
view 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 |
line wrap: on
line source
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 = "false"; private String charPos; private String xpath; public ExtElement() { this.type = "element"; } public static ExtElement parseXmlStr(String xmlStr) throws ApplicationException { XmlUtil xmlUtil = XmlUtil.getInstance(); xmlUtil.setNsContext("general"); 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); 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 xmlns:xlink=\"http://www.w3.org/1999/xlink\""; xmlString = xmlString + " type=\"" + type + "\""; if (modificationDate != null) { XmlUtil xmlUtil = XmlUtil.getInstance(); String dateStr = xmlUtil.toXsDate(modificationDate); xmlString = xmlString + " modificationDate=\"" + dateStr + "\""; } 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 + "\""; 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 boolean isBefore() { if (before != null && before.equals("true")) return true; else return false; } public String getBefore() { return before; } public void setBefore(String before) { this.before = before; } }