Mercurial > hg > mpdl-group
diff software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtQuery.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 |
line wrap: on
line diff
--- a/software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtQuery.java Thu Feb 10 14:02:05 2011 +0100 +++ b/software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtQuery.java Tue Feb 22 16:03:45 2011 +0100 @@ -9,8 +9,13 @@ private String queryType; // url, fulltext or fulltextMorph private String queryName; // optional: name of the query + public ExtQuery() { + this.type = "query"; + } + public static ExtQuery 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); @@ -18,46 +23,43 @@ String queryName = xmlUtil.evaluateToString(xmlStr, "/object/@queryName", null); String content = xmlUtil.evaluateToXmlString(xmlStr, "/object/content/*", null); Date modDate = xmlUtil.toDate(dateStr); - if (uid == null || docId == null || queryType == null || content == null) - throw new ApplicationException("one of the required fields could not be read in: " + xmlStr); ExtQuery e = new ExtQuery(); e.setUid(uid); e.setModificationDate(modDate); e.setDocumentId(docId); e.setQueryType(queryType); e.setQueryName(queryName); - e.setContent(content); + if (content != null && ! content.isEmpty()) + e.setContent(content); return e; } + public ExtQuery getInstance(String xmlStr) throws ApplicationException { + return parseXmlStr(xmlStr); + } + public String toString() { return getXmlString(); } public String getXmlString() { String xmlString = "<object"; - xmlString = xmlString + " type=\"" + "query" + "\""; - if (uid != null) - xmlString = xmlString + " uid=\"" + uid + "\""; - if (queryType != null) - xmlString = xmlString + " queryType=\"" + queryType + "\""; - if (queryName != null) - xmlString = xmlString + " queryName=\"" + queryName + "\""; + 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 (queryType != null) + xmlString = xmlString + " queryType=\"" + queryType + "\""; + if (queryName != null) + xmlString = xmlString + " queryName=\"" + queryName + "\""; 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>";