Mercurial > hg > mpdl-group
comparison software/eXist/mpdl-modules/src/org/exist/xquery/modules/mpdltext/ExternalObject.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 | 5df60f24e997 |
comparison
equal
deleted
inserted
replaced
8:d2a1c14fde31 | 9:1ec29fdd0db8 |
---|---|
21 * $Id: TextModule.java $ | 21 * $Id: TextModule.java $ |
22 */ | 22 */ |
23 package org.exist.xquery.modules.mpdltext; | 23 package org.exist.xquery.modules.mpdltext; |
24 | 24 |
25 import java.util.ArrayList; | 25 import java.util.ArrayList; |
26 import java.util.Date; | |
27 | 26 |
28 import org.exist.dom.QName; | 27 import org.exist.dom.QName; |
29 import org.exist.xquery.BasicFunction; | 28 import org.exist.xquery.BasicFunction; |
30 import org.exist.xquery.Cardinality; | 29 import org.exist.xquery.Cardinality; |
31 import org.exist.xquery.FunctionSignature; | 30 import org.exist.xquery.FunctionSignature; |
37 import org.exist.xquery.value.Type; | 36 import org.exist.xquery.value.Type; |
38 import org.exist.xquery.value.ValueSequence; | 37 import org.exist.xquery.value.ValueSequence; |
39 | 38 |
40 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; | 39 import de.mpg.mpiwg.berlin.mpdl.exception.ApplicationException; |
41 import de.mpg.mpiwg.berlin.mpdl.externalObjects.app.ExtElement; | 40 import de.mpg.mpiwg.berlin.mpdl.externalObjects.app.ExtElement; |
41 import de.mpg.mpiwg.berlin.mpdl.externalObjects.app.ExtObject; | |
42 import de.mpg.mpiwg.berlin.mpdl.externalObjects.app.ExtQuery; | |
42 import de.mpg.mpiwg.berlin.mpdl.externalObjects.app.ExternalObjectsHandler; | 43 import de.mpg.mpiwg.berlin.mpdl.externalObjects.app.ExternalObjectsHandler; |
43 | 44 |
44 /** | 45 /** |
45 * @author Josef Willenborg (jwillenborg@mpiwg-berlin.mpg.de) | 46 * @author Josef Willenborg (jwillenborg@mpiwg-berlin.mpg.de) |
46 */ | 47 */ |
59 super(context, signature); | 60 super(context, signature); |
60 } | 61 } |
61 | 62 |
62 public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { | 63 public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { |
63 Sequence operation = args[0]; // read, update or delete | 64 Sequence operation = args[0]; // read, update or delete |
64 Sequence type = args[1]; | 65 Sequence type = args[1]; // element, query |
65 Sequence object = args[2]; | 66 Sequence object = args[2]; // the object as an xml string |
66 if (operation.isEmpty() || type.isEmpty()) | 67 if (operation.isEmpty() || type.isEmpty() || object.isEmpty()) |
67 return Sequence.EMPTY_SEQUENCE; | 68 return Sequence.EMPTY_SEQUENCE; |
68 String operationStr = operation.getStringValue(); | 69 String operationStr = operation.getStringValue(); |
69 String typeStr = type.getStringValue(); | 70 String typeStr = type.getStringValue(); |
70 String objectStr = object.getStringValue(); | 71 String objectStr = object.getStringValue(); |
71 | 72 |
72 ValueSequence result = null; | 73 ValueSequence result = null; |
73 String resultStr = ""; | 74 String resultStr = ""; |
74 try { | 75 try { |
76 ExternalObjectsHandler externalObjectsHandler = ExternalObjectsHandler.getInstance(); | |
75 if (typeStr.equals("element")) { | 77 if (typeStr.equals("element")) { |
76 ExtElement e = ExtElement.parseXmlStr(objectStr); | 78 ExtElement e = ExtElement.parseXmlStr(objectStr); |
77 if (operation.equals("create") || operation.equals("update")) { | |
78 Date now = new Date(); | |
79 e.setModificationDate(now); | |
80 } | |
81 String documentId = e.getDocumentId(); | |
82 String pageNumber = e.getPageNumber(); | |
83 if (operationStr.equals("read")) { | 79 if (operationStr.equals("read")) { |
84 ExternalObjectsHandler externalObjectsHandler = ExternalObjectsHandler.getInstance(); | 80 ArrayList<ExtElement> elems = externalObjectsHandler.readExternalElements(e); |
85 ArrayList<ExtElement> elems = externalObjectsHandler.readExternalElements(documentId, pageNumber); | |
86 if (elems != null && elems.size() > 0) { | 81 if (elems != null && elems.size() > 0) { |
87 resultStr = "<result>"; | 82 resultStr = "<result>"; |
88 for (int i=0; i<elems.size(); i++) { | 83 for (int i=0; i<elems.size(); i++) { |
89 ExtElement elem = elems.get(i); | 84 ExtElement elem = elems.get(i); |
90 String elemXmlStr = elem.getXmlString(); | 85 String elemXmlStr = elem.getXmlString(); |
91 resultStr = resultStr + elemXmlStr; | 86 resultStr = resultStr + elemXmlStr; |
92 } | 87 } |
93 resultStr = resultStr + "</result>"; | 88 resultStr = resultStr + "</result>"; |
94 } | 89 } |
95 } else if (operationStr.equals("create")) { | 90 } else if (operationStr.equals("create")) { |
96 // TODO | 91 externalObjectsHandler.createExternalElement(e); |
97 } else if (operationStr.equals("update")) { | 92 } else if (operationStr.equals("update")) { |
98 // TODO | 93 externalObjectsHandler.updateExternalElement(e); |
99 } else if (operationStr.equals("delete")) { | 94 } else if (operationStr.equals("delete")) { |
100 // TODO | 95 externalObjectsHandler.deleteExternalElement(e); |
101 } | 96 } |
102 } else if (typeStr.equals("query")) { | 97 } else if (typeStr.equals("query")) { |
103 // TODO | 98 ExtQuery q = ExtQuery.parseXmlStr(objectStr); |
99 if (operationStr.equals("read")) { | |
100 ArrayList<ExtObject> objects = externalObjectsHandler.readExternalObjects(q); | |
101 if (objects != null && objects.size() > 0) { | |
102 resultStr = "<result>"; | |
103 for (int i=0; i<objects.size(); i++) { | |
104 ExtObject obj = objects.get(i); | |
105 String elemXmlStr = obj.getXmlString(); | |
106 resultStr = resultStr + elemXmlStr; | |
107 } | |
108 resultStr = resultStr + "</result>"; | |
109 } | |
110 } else if (operationStr.equals("create")) { | |
111 externalObjectsHandler.createExternalObject(q); | |
112 } else if (operationStr.equals("update")) { | |
113 externalObjectsHandler.updateExternalObject(q); | |
114 } else if (operationStr.equals("delete")) { | |
115 externalObjectsHandler.deleteExternalObject(q); | |
116 } | |
104 } | 117 } |
105 result = new ValueSequence(); | 118 result = new ValueSequence(); |
106 result.add(new StringValue(resultStr)); | 119 result.add(new StringValue(resultStr)); |
107 } catch (ApplicationException e) { | 120 } catch (ApplicationException e) { |
108 throw new XPathException(e); | 121 throw new XPathException(e); |