comparison software/eXist/webapp/mpdl/doc/doc-operation-exist.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 d6f528ad5d96
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 existLink = "http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/page-query-result.xql?document=".concat(existIdentifier);
41 var existIdentifierSplit = existIdentifier.split("/");
42 var docBase = existIdentifierSplit[1];
43 var language = existIdentifierSplit[2];
44 var fileName = existIdentifierSplit[3];
45 document.formDocOperation.docBase.value = docBase;
46 document.formDocOperation.language.value = language;
47 document.formDocOperation.fileName.value = fileName;
48 document.getElementById("existLink").href = existLink;
49 document.getElementById("existLink").firstChild.nodeValue = existIdentifier;
50 document.formDocOperation.srcLocalFileName.value = "";
51 document.formDocOperation.srcUrl.value = "";
52 }
53 function OperationSelection() {
54 if (document.formDocOperation.operation.selectedIndex == 1) {
55 document.formDocOperation.srcLocalFileName.value = "";
56 document.formDocOperation.srcUrl.value = "";
57 }
58 }
59 function LocalFileNameSelection() {
60 var srcLocalFileName = document.formDocOperation.srcLocalFileName.value;
61 document.formDocOperation.fileName.value = srcLocalFileName;
62 document.formDocOperation.srcUrl.value = "";
63 document.getElementById("existLink").href = "";
64 document.getElementById("existLink").firstChild.nodeValue = "";
65 }
66 function UrlSelection() {
67 var srcUrl = document.formDocOperation.srcUrl.value;
68 var startPos = srcUrl.lastIndexOf("/");
69 var endPos = srcUrl.length;
70 var fileName = srcUrl.substring(startPos + 1, endPos);
71 document.formDocOperation.fileName.value = fileName;
72 document.formDocOperation.srcLocalFileName.value = "";
73 document.getElementById("existLink").href = "";
74 document.getElementById("existLink").firstChild.nodeValue = "";
75 }
76 function ResetSrcLocalFileName() {
77 document.formDocOperation.srcLocalFileName.value = "";
78 document.formDocOperation.srcUrl.value = "";
79 document.formDocOperation.fileName.value = "";
80 }
81 function DocBaseRefreshDest() {
82 var docBase = document.formDocOperation.docBase[document.formDocOperation.docBase.selectedIndex].value;
83 DocBaseRefresh(docBase);
84 }
85 function DocBaseRefreshList() {
86 var docBase = document.docBaseList.docBase[document.docBaseList.docBase.selectedIndex].value;
87 DocBaseRefresh(docBase);
88 }
89 function DocBaseRefresh(docBase) {
90 document.docBaseList.docBase.value = docBase;
91 for (i = 0; i < document.docBaseList.doc.length; i++)
92 document.docBaseList.doc[i].selected = false;
93 document.docBaseList.submit();
94 }
95 function LanguageRefreshDest() {
96 var lang = document.formDocOperation.language[document.formDocOperation.language.selectedIndex].value;
97 LanguageRefresh(lang);
98 }
99 function LanguageRefreshList() {
100 var lang = document.docBaseList.language[document.docBaseList.language.selectedIndex].value;
101 LanguageRefresh(lang);
102 }
103 function LanguageRefresh(language) {
104 document.docBaseList.language.value = language;
105 for (i = 0; i < document.docBaseList.doc.length; i++)
106 document.docBaseList.doc[i].selected = false;
107 document.docBaseList.submit();
108 }
109 -->
110 </script>
111
112 let $eSciDocCookieId := session:get-attribute("eSciDocCookieId")
113
114 let $docBaseOptions :=
115 <select>
116 <option value ="archimedes">Archimedes</option>
117 <option value ="echo">Echo</option>
118 </select>
119 let $docBaseOptionsSelected :=
120 for $option in $docBaseOptions/option
121 return element { node-name($option)}
122 { if ($option/@value = $docBase)
123 then attribute {'selected'}
124 {'true'}
125 else (),
126 $option/@*,
127 $option/node() }
128 let $docBaseSelectBoxDest :=
129 <select name="docBase" onchange="DocBaseRefreshDest()">{$docBaseOptionsSelected}</select>
130 let $docBaseSelectBoxList :=
131 <select name="docBase" onchange="DocBaseRefreshList()">{$docBaseOptionsSelected}</select>
132
133 let $languageOptions :=
134 <select>
135 <option value = "ar">Arabic</option>
136 <option value = "zh">Chinese</option>
137 <option value = "nl">Dutch</option>
138 <option value = "en">English</option>
139 <option value = "fr">French</option>
140 <option value = "de">German</option>
141 <option value = "el">Greek</option>
142 <option value = "it">Italian</option>
143 <option value = "la">Latin</option>
144 </select>
145 let $languageOptionsSelected :=
146 for $option in $languageOptions/option
147 return element { node-name($option)}
148 { if ($option/@value = $language)
149 then attribute {'selected'}
150 {'true'}
151 else (),
152 $option/@*,
153 $option/node() }
154 let $languageSelectBoxDest :=
155 <select name="language" onchange="LanguageRefreshDest()">{$languageOptionsSelected}</select>
156 let $languageSelectBoxList :=
157 <select name="language" onchange="LanguageRefreshList()">{$languageOptionsSelected}</select>
158
159 let $docsSelectBoxOptions :=
160 for $docFileName at $pos in $docFileNames
161 let $existIdentifier := concat("/", $docBase, "/", $language, "/", $docFileName)
162 let $option := <option value ="{$existIdentifier}">{$docFileName}</option>
163 order by $docFileName
164 return $option
165 let $docsSelectBox :=
166 <select name="doc" style="width: 100%;" size="20" onclick="DocumentSelection()">
167 {$docsSelectBoxOptions}
168 </select>
169
170 let $error :=
171 if ($eSciDocCookieId = '' or empty($eSciDocCookieId))
172 then <bla>No login context available. Please <a href="login-exist.xql">login</a> before you do an operation</bla>
173 else "no"
174
175 let $resultHtml :=
176 if ($error = 'no')
177 then
178 <div>
179 <table align="middle" width="100%">
180 <colgroup>
181 <col width="50%"/>
182 <col width="50%"/>
183 </colgroup>
184 <tr>
185 <td valign="top">
186 <form name="formDocOperation" action="{session:encode-url(xs:anyURI('doc-operation-result-exist.xql'))}" method="post" enctype="multipart/form-data">
187 <table>
188 <tr><td><b>Operation</b></td></tr>
189 <tr>
190 <td>
191 <select name="operation" onchange="OperationSelection()">
192 <option value ="updateExist" selected="true">Create/Update</option>
193 <option value ="deleteExist">Delete</option>
194 </select>
195 <input type="submit" name="performOperation" value="Execute"/>
196 <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>
197 </td>
198 </tr>
199 <tr><td><br/></td></tr>
200 <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>
201 <tr><td>Local file: <input type="file" size="40" name="srcLocalFileName" onchange="LocalFileNameSelection()" maxlength="10000000" accept="text/xml" value="srcLocalFileName"/>
202 <input type="button" name="resetSrcLocalFileName" value="Reset" onclick="ResetSrcLocalFileName()"/></td></tr>
203 <tr><td><text style="margin-left:10px;"></text>or</td></tr>
204 <tr><td>Url: <input type="text" size="40" name="srcUrl" onchange="UrlSelection()" value=""/></td></tr>
205 <tr><td><br/></td></tr>
206 <tr><td><b>Destination</b></td></tr>
207 <tr>
208 <td>Document base:
209 {$docBaseSelectBoxDest}
210 </td>
211 </tr>
212 <tr>
213 <td>Language:
214 {$languageSelectBoxDest}
215 </td>
216 </tr>
217 <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>
218 <tr><td>Document link: <a id="existLink" href=""></a></td></tr>
219 </table>
220 </form>
221 </td>
222 <td valign="top">
223 <form name="docBaseList" action="doc-operation-exist.xql" method="get">
224 <table>
225 <tr>
226 <td>
227 <b>Documents</b><br/>
228 <br/>
229 Document base:
230 {$docBaseSelectBoxList}
231 Language:
232 {$languageSelectBoxList}
233 </td>
234 </tr>
235 <tr><td>{$docsSelectBox}</td></tr>
236 </table>
237 </form>
238 </td>
239 </tr>
240 </table>
241 </div>
242 else
243 <div><b>Error in operation:</b> {$error}</div>
244
245
246
247 let $title := "MPDL: eXist document interface"
248 return
249 <html>
250 <head>
251 <title>{$title}</title>
252 {$javascriptHtml}
253 </head>
254 <body>
255 <h1>{$title}</h1>
256 {$resultHtml}
257 <hr/>
258 See the <a href="doc-operation-exist.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>
259 </body>
260 </html>