diff software/eXist/mpdl-modules/src/de/mpg/mpiwg/berlin/mpdl/externalObjects/app/ExtQuery.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/ExtQuery.java	Tue Feb 08 14:54:09 2011 +0100
@@ -0,0 +1,83 @@
+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 ExtQuery extends ExtObject {
+  private String queryType;  // url, fulltext or fulltextMorph
+  private String queryName;  // optional: name of the query
+
+  public static ExtQuery 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 queryType = xmlUtil.evaluateToString(xmlStr, "/object/@queryType", null);
+    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);
+    return e;
+  }
+
+  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 + "\"";
+    if (modificationDate != null) {
+      XmlUtil xmlUtil = XmlUtil.getInstance();
+      String dateStr = xmlUtil.toXsDate(modificationDate);
+      xmlString = xmlString + " modificationDate=\"" + dateStr + "\"";
+    }
+    if (documentId != null)
+      xmlString = xmlString + " documentId=\"" + documentId + "\"";
+    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 getQueryType() {
+    return queryType;
+  }
+
+  public void setQueryType(String queryType) {
+    this.queryType = queryType;
+  }
+
+  public String getQueryName() {
+    return queryName;
+  }
+
+  public void setQueryName(String queryName) {
+    this.queryName = queryName;
+  }
+
+}