comparison software/eXist/webapp/mpdl/doc/doc-operation.xql @ 7:5589d865af7a

Erstellung XQL/XSL Applikation
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Tue, 08 Feb 2011 15:16:46 +0100
parents
children
comparison
equal deleted inserted replaced
6:2396a569e446 7:5589d865af7a
1 xquery version "1.0";
2
3 declare namespace request="http://exist-db.org/xquery/request";
4 declare namespace util = "http://exist-db.org/xquery/util";
5
6 declare namespace escidocItem="http://www.escidoc.de/schemas/item/0.9";
7 declare namespace container="http://www.escidoc.de/schemas/container/0.8";
8 declare namespace escidocMetadataRecords="http://www.escidoc.de/schemas/metadatarecords/0.5";
9 declare namespace dc="http://purl.org/dc/elements/1.1/";
10 declare namespace xlink="http://www.w3.org/1999/xlink";
11 declare namespace mpiwg="http://www.mpiwg-berlin.mpg.de/ns/mpiwg";
12
13 let $docBaseReq := request:get-parameter("docBase", "")
14 let $docBase :=
15 if ($docBaseReq = '')
16 then 'echo'
17 else $docBaseReq
18 let $languageReq := request:get-parameter("language", "")
19 let $language :=
20 if ($languageReq = '')
21 then 'la'
22 else string($languageReq)
23
24 let $docPathStandard := "/db/mpdl/documents/standard"
25 let $docPath := concat($docPathStandard, "/", $docBase, "/", $language)
26 let $docCollectionStr := concat("collection('", $docPath, "')")
27 let $docCollection := util:eval($docCollectionStr)
28 let $docFileNames :=
29 for $elem at $pos in $docCollection
30 let $doc := $elem/fn:root()
31 let $documentUriOrig := document-uri($doc)
32 let $documentFileName := substring-after(substring-after($documentUriOrig, $docPath), "/")
33 return $documentFileName
34
35 let $javascriptHtml :=
36 <script type="text/javascript">
37 <!--
38 function DocumentSelection() {
39 var existIdentifier = document.docBaseList.doc[document.docBaseList.doc.selectedIndex].value;
40 var eSciDocCookieId = document.docBaseList.eSciDocCookieId.value;
41 var existLink = "http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/page-query-result.xql?document=".concat(existIdentifier);
42 var existIdentifierSplit = existIdentifier.split("/");
43 var docBase = existIdentifierSplit[1];
44 var language = existIdentifierSplit[2];
45 var fileName = existIdentifierSplit[3];
46 document.formDocOperation.docBase.value = docBase;
47 document.formDocOperation.language.value = language;
48 document.formDocOperation.fileName.value = fileName;
49 document.getElementById("existLink").href = existLink;
50 document.getElementById("existLink").firstChild.nodeValue = existIdentifier;
51 UpdateESciDocLink(existIdentifier, eSciDocCookieId);
52 document.formDocOperation.srcLocalFileName.value = "";
53 document.formDocOperation.srcUrl.value = "";
54 }
55 function OperationSelection() {
56 if (document.formDocOperation.operation.selectedIndex == 1) {
57 document.formDocOperation.srcLocalFileName.value = "";
58 document.formDocOperation.srcUrl.value = "";
59 }
60 }
61 function LocalFileNameSelection() {
62 var srcLocalFileName = document.formDocOperation.srcLocalFileName.value;
63 document.formDocOperation.fileName.value = srcLocalFileName;
64 document.formDocOperation.srcUrl.value = "";
65 document.getElementById("existLink").href = "";
66 document.getElementById("existLink").firstChild.nodeValue = "";
67 document.getElementById("eSciDocLink").href = "";
68 document.getElementById("eSciDocLink").firstChild.nodeValue = "";
69 }
70 function UrlSelection() {
71 var srcUrl = document.formDocOperation.srcUrl.value;
72 var startPos = srcUrl.lastIndexOf("/");
73 var endPos = srcUrl.length;
74 var fileName = srcUrl.substring(startPos + 1, endPos);
75 document.formDocOperation.fileName.value = fileName;
76 document.formDocOperation.srcLocalFileName.value = "";
77 document.getElementById("existLink").href = "";
78 document.getElementById("existLink").firstChild.nodeValue = "";
79 document.getElementById("eSciDocLink").href = "";
80 document.getElementById("eSciDocLink").firstChild.nodeValue = "";
81 }
82 function ResetSrcLocalFileName() {
83 document.formDocOperation.srcLocalFileName.value = "";
84 document.formDocOperation.srcUrl.value = "";
85 document.formDocOperation.fileName.value = "";
86 }
87 function DocBaseRefreshDest() {
88 var docBase = document.formDocOperation.docBase[document.formDocOperation.docBase.selectedIndex].value;
89 DocBaseRefresh(docBase);
90 }
91 function DocBaseRefreshList() {
92 var docBase = document.docBaseList.docBase[document.docBaseList.docBase.selectedIndex].value;
93 DocBaseRefresh(docBase);
94 }
95 function DocBaseRefresh(docBase) {
96 document.docBaseList.docBase.value = docBase;
97 for (i = 0; i < document.docBaseList.doc.length; i++)
98 document.docBaseList.doc[i].selected = false;
99 document.docBaseList.submit();
100 }
101 function LanguageRefreshDest() {
102 var lang = document.formDocOperation.language[document.formDocOperation.language.selectedIndex].value;
103 LanguageRefresh(lang);
104 }
105 function LanguageRefreshList() {
106 var lang = document.docBaseList.language[document.docBaseList.language.selectedIndex].value;
107 LanguageRefresh(lang);
108 }
109 function LanguageRefresh(language) {
110 document.docBaseList.language.value = language;
111 for (i = 0; i < document.docBaseList.doc.length; i++)
112 document.docBaseList.doc[i].selected = false;
113 document.docBaseList.submit();
114 }
115 function UpdateESciDocLinkTemp() {
116 if (http.readyState == 4) {
117 var eSciDocContainerId = http.responseText.trim();
118 if (eSciDocContainerId != "") {
119 var eSciDocLink = "http://euler.mpiwg-berlin.mpg.de:8080".concat(eSciDocContainerId);
120 document.getElementById("eSciDocLink").href = eSciDocLink;
121 document.getElementById("eSciDocLink").firstChild.nodeValue = eSciDocContainerId;
122 } else {
123 document.getElementById("eSciDocLink").href = "";
124 document.getElementById("eSciDocLink").firstChild.nodeValue = "";
125 }
126 isWorking = false;
127 }
128 }
129 function UpdateESciDocLink(existId, eSciDocCookieId) {
130 if (!isWorking && http) {
131 http.open("GET", "get-escidoc-containerid.xql?existId=" + existId + "&eSciDocCookieId=" + eSciDocCookieId);
132 http.onreadystatechange = UpdateESciDocLinkTemp;
133 // this sets the call-back function to be invoked when a response from the HTTP request is returned
134 isWorking = true;
135 http.send(null);
136 }
137 }
138 function GetHTTPObject() {
139 var xmlhttp;
140 /*@cc_on
141 @if (@_jscript_version >= 5)
142 try {
143 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
144 } catch (e) {
145 try {
146 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
147 } catch (E) {
148 xmlhttp = false;
149 }
150 }
151 @else
152 xmlhttp = false;
153 @end @*/
154 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
155 try {
156 xmlhttp = new XMLHttpRequest();
157 xmlhttp.overrideMimeType("text/xml");
158 } catch (e) {
159 xmlhttp = false;
160 }
161 }
162 return xmlhttp;
163 }
164 var http = GetHTTPObject(); // create the HTTP Object
165 var isWorking = false;
166 -->
167 </script>
168
169 let $eSciDocCookieId := session:get-attribute("eSciDocCookieId")
170
171 let $docBaseOptions :=
172 <select>
173 <option value ="archimedes">Archimedes</option>
174 <option value ="echo">Echo</option>
175 </select>
176 let $docBaseOptionsSelected :=
177 for $option in $docBaseOptions/option
178 return element { node-name($option)}
179 { if ($option/@value = $docBase)
180 then attribute {'selected'}
181 {'true'}
182 else (),
183 $option/@*,
184 $option/node() }
185 let $docBaseSelectBoxDest :=
186 <select name="docBase" onchange="DocBaseRefreshDest()">{$docBaseOptionsSelected}</select>
187 let $docBaseSelectBoxList :=
188 <select name="docBase" onchange="DocBaseRefreshList()">{$docBaseOptionsSelected}</select>
189
190 let $languageOptions :=
191 <select>
192 <option value = "ar">Arabic</option>
193 <option value = "zh">Chinese</option>
194 <option value = "nl">Dutch</option>
195 <option value = "en">English</option>
196 <option value = "fr">French</option>
197 <option value = "de">German</option>
198 <option value = "el">Greek</option>
199 <option value = "it">Italian</option>
200 <option value = "la">Latin</option>
201 </select>
202 let $languageOptionsSelected :=
203 for $option in $languageOptions/option
204 return element { node-name($option)}
205 { if ($option/@value = $language)
206 then attribute {'selected'}
207 {'true'}
208 else (),
209 $option/@*,
210 $option/node() }
211 let $languageSelectBoxDest :=
212 <select name="language" onchange="LanguageRefreshDest()">{$languageOptionsSelected}</select>
213 let $languageSelectBoxList :=
214 <select name="language" onchange="LanguageRefreshList()">{$languageOptionsSelected}</select>
215
216 let $docsSelectBoxOptions :=
217 for $docFileName at $pos in $docFileNames
218 let $existIdentifier := concat("/", $docBase, "/", $language, "/", $docFileName)
219 let $option := <option value ="{$existIdentifier}">{$docFileName}</option>
220 order by $docFileName
221 return $option
222 let $docsSelectBox :=
223 <select name="doc" style="width: 100%;" size="20" onclick="DocumentSelection()">
224 {$docsSelectBoxOptions}
225 </select>
226
227 let $error :=
228 if ($eSciDocCookieId = '' or empty($eSciDocCookieId))
229 then <bla>No login context available. Please <a href="login.xql">login</a> before you do an operation</bla>
230 else "no"
231
232 let $resultHtml :=
233 if ($error = 'no')
234 then
235 <div>
236 <table align="middle" width="100%">
237 <colgroup>
238 <col width="50%"/>
239 <col width="50%"/>
240 </colgroup>
241 <tr>
242 <td valign="top">
243 <form name="formDocOperation" action="{session:encode-url(xs:anyURI('doc-operation-result.xql'))}" method="post" enctype="multipart/form-data">
244 <table>
245 <tr><td><b>Operation</b></td></tr>
246 <tr>
247 <td>
248 <select name="operation" onchange="OperationSelection()">
249 <option value ="create" selected="true">Create</option>
250 <option value ="update">Update</option>
251 <option value ="delete">Delete</option>
252 </select>
253 <input type="submit" name="performOperation" value="Execute"/>
254 <a href="../info.xql?info=docInterfaceOperation" onclick="window.open(&quot;../info.xql?info=docInterfaceOperation&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="../images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info document interface operation"/></a>
255 </td>
256 </tr>
257 <tr><td><br/></td></tr>
258 <tr><td><b>Source <a href="../info.xql?info=docInterfaceSource" onclick="window.open(&quot;../info.xql?info=docInterfaceSource&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="../images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info document interface source"/></a></b></td></tr>
259 <tr><td>Local file: <input type="file" size="40" name="srcLocalFileName" onchange="LocalFileNameSelection()" maxlength="10000000" accept="text/xml" value="srcLocalFileName"/>
260 <input type="button" name="resetSrcLocalFileName" value="Reset" onclick="ResetSrcLocalFileName()"/></td></tr>
261 <tr><td><text style="margin-left:10px;"></text>or</td></tr>
262 <tr><td>Url: <input type="text" size="40" name="srcUrl" onchange="UrlSelection()" value=""/></td></tr>
263 <tr><td><br/></td></tr>
264 <tr><td><b>Destination</b></td></tr>
265 <tr>
266 <td>Document base:
267 {$docBaseSelectBoxDest}
268 </td>
269 </tr>
270 <tr>
271 <td>Language:
272 {$languageSelectBoxDest}
273 </td>
274 </tr>
275 <tr><td>Document name: <input type="text" size="40" name="fileName" value=""/> <a href="../info.xql?info=docInterfaceDestDocName" onclick="window.open(&quot;../info.xql?info=docInterfaceDestDocName&quot;, &quot;InfoWindow&quot;, &quot;menubar=no,width=500,height=500,toolbar=no&quot;);return false"><img src="../images/info.png" valign="bottom" width="18" height="18" border="0" alt="Info document interface source"/></a></td></tr>
276 <tr><td>eXist document link: <a id="existLink" href=""></a></td></tr>
277 <tr><td>eSciDoc document link: <a id="eSciDocLink" href=""></a></td></tr>
278 </table>
279 </form>
280 </td>
281 <td valign="top">
282 <form name="docBaseList" action="doc-operation.xql" method="get">
283 <input type="hidden" name="eSciDocCookieId" value="{$eSciDocCookieId}"/>
284 <table>
285 <tr>
286 <td>
287 <b>Documents</b><br/>
288 <br/>
289 Document base:
290 {$docBaseSelectBoxList}
291 Language:
292 {$languageSelectBoxList}
293 </td>
294 </tr>
295 <tr><td>{$docsSelectBox}</td></tr>
296 </table>
297 </form>
298 </td>
299 </tr>
300 </table>
301 </div>
302 else
303 <div><b>Error in operation:</b> {$error}</div>
304
305
306
307 let $title := "MPDL: eXist/eSciDoc document interface"
308 return
309 <html>
310 <head>
311 <title>{$title}</title>
312 {$javascriptHtml}
313 </head>
314 <body>
315 <h1>{$title}</h1>
316 {$resultHtml}
317 <hr/>
318 See the <a href="doc-operation.xql?_source=yes">XQuery source</a> of this page, if you find a bug <a href="https://itgroup.mpiwg-berlin.mpg.de:8080/tracs/mpdl-project-software/newticket">let us know</a>
319 </body>
320 </html>