view software/eXist/webapp/mpdl/doc/doc-operation.xql @ 15:e99964f390e4

diverse Fehlerbehebungen
author Josef Willenborg <jwillenborg@mpiwg-berlin.mpg.de>
date Mon, 29 Aug 2011 17:40:19 +0200
parents 5589d865af7a
children
line wrap: on
line source

xquery version "1.0";

declare namespace request="http://exist-db.org/xquery/request";
declare namespace util = "http://exist-db.org/xquery/util";

declare namespace escidocItem="http://www.escidoc.de/schemas/item/0.9";
declare namespace container="http://www.escidoc.de/schemas/container/0.8";
declare namespace escidocMetadataRecords="http://www.escidoc.de/schemas/metadatarecords/0.5";
declare namespace dc="http://purl.org/dc/elements/1.1/";
declare namespace xlink="http://www.w3.org/1999/xlink";
declare namespace mpiwg="http://www.mpiwg-berlin.mpg.de/ns/mpiwg";

let $docBaseReq := request:get-parameter("docBase", "")
let $docBase :=
  if ($docBaseReq = '')
  then 'echo'
  else $docBaseReq
let $languageReq := request:get-parameter("language", "")
let $language :=
  if ($languageReq = '')
  then 'la'
  else string($languageReq)

let $docPathStandard := "/db/mpdl/documents/standard"
let $docPath := concat($docPathStandard, "/", $docBase, "/", $language)
let $docCollectionStr := concat("collection('", $docPath, "')")
let $docCollection := util:eval($docCollectionStr)
let $docFileNames := 
  for $elem at $pos in $docCollection
    let $doc := $elem/fn:root()
    let $documentUriOrig := document-uri($doc)
    let $documentFileName := substring-after(substring-after($documentUriOrig, $docPath), "/")
  return $documentFileName

let $javascriptHtml :=
  <script type="text/javascript">
    <!--
    function DocumentSelection() {
      var existIdentifier = document.docBaseList.doc[document.docBaseList.doc.selectedIndex].value;
      var eSciDocCookieId = document.docBaseList.eSciDocCookieId.value;
      var existLink = "http://mpdl-proto.mpiwg-berlin.mpg.de/mpdl/page-query-result.xql?document=".concat(existIdentifier);
      var existIdentifierSplit = existIdentifier.split("/");
      var docBase = existIdentifierSplit[1];
      var language = existIdentifierSplit[2];
      var fileName = existIdentifierSplit[3];
      document.formDocOperation.docBase.value = docBase;
      document.formDocOperation.language.value = language;
      document.formDocOperation.fileName.value = fileName;
      document.getElementById("existLink").href = existLink;
      document.getElementById("existLink").firstChild.nodeValue = existIdentifier;
      UpdateESciDocLink(existIdentifier, eSciDocCookieId);
      document.formDocOperation.srcLocalFileName.value = "";
      document.formDocOperation.srcUrl.value = "";
    }
    function OperationSelection() {
      if (document.formDocOperation.operation.selectedIndex == 1) {
        document.formDocOperation.srcLocalFileName.value = "";
        document.formDocOperation.srcUrl.value = "";
      }
    }
    function LocalFileNameSelection() {
      var srcLocalFileName = document.formDocOperation.srcLocalFileName.value;
      document.formDocOperation.fileName.value = srcLocalFileName;
      document.formDocOperation.srcUrl.value = "";
      document.getElementById("existLink").href = "";
      document.getElementById("existLink").firstChild.nodeValue = "";
      document.getElementById("eSciDocLink").href = "";
      document.getElementById("eSciDocLink").firstChild.nodeValue = "";
    }
    function UrlSelection() {
      var srcUrl = document.formDocOperation.srcUrl.value;
      var startPos = srcUrl.lastIndexOf("/");
      var endPos = srcUrl.length;
      var fileName = srcUrl.substring(startPos + 1, endPos);
      document.formDocOperation.fileName.value = fileName;
      document.formDocOperation.srcLocalFileName.value = "";
      document.getElementById("existLink").href = "";
      document.getElementById("existLink").firstChild.nodeValue = "";
      document.getElementById("eSciDocLink").href = "";
      document.getElementById("eSciDocLink").firstChild.nodeValue = "";
    }
    function ResetSrcLocalFileName() {
      document.formDocOperation.srcLocalFileName.value = "";
      document.formDocOperation.srcUrl.value = "";
      document.formDocOperation.fileName.value = "";
    }
    function DocBaseRefreshDest() {
      var docBase = document.formDocOperation.docBase[document.formDocOperation.docBase.selectedIndex].value;
      DocBaseRefresh(docBase);
    }
    function DocBaseRefreshList() {
      var docBase = document.docBaseList.docBase[document.docBaseList.docBase.selectedIndex].value;
      DocBaseRefresh(docBase);
    }
    function DocBaseRefresh(docBase) {
      document.docBaseList.docBase.value = docBase;
      for (i = 0; i < document.docBaseList.doc.length; i++)
        document.docBaseList.doc[i].selected = false;
      document.docBaseList.submit();
    }
    function LanguageRefreshDest() {
      var lang = document.formDocOperation.language[document.formDocOperation.language.selectedIndex].value;
      LanguageRefresh(lang);
    }
    function LanguageRefreshList() {
      var lang = document.docBaseList.language[document.docBaseList.language.selectedIndex].value;
      LanguageRefresh(lang);
    }
    function LanguageRefresh(language) {
      document.docBaseList.language.value = language;
      for (i = 0; i < document.docBaseList.doc.length; i++)
        document.docBaseList.doc[i].selected = false;
      document.docBaseList.submit();
    }
    function UpdateESciDocLinkTemp() {
      if (http.readyState == 4) {
      	var eSciDocContainerId = http.responseText.trim();
        if (eSciDocContainerId != "") {
          var eSciDocLink = "http://euler.mpiwg-berlin.mpg.de:8080".concat(eSciDocContainerId);
          document.getElementById("eSciDocLink").href = eSciDocLink;
          document.getElementById("eSciDocLink").firstChild.nodeValue = eSciDocContainerId;
        } else {
          document.getElementById("eSciDocLink").href = "";
          document.getElementById("eSciDocLink").firstChild.nodeValue = "";
        }
        isWorking = false;
      }
    }
    function UpdateESciDocLink(existId, eSciDocCookieId) {
      if (!isWorking && http) {
        http.open("GET", "get-escidoc-containerid.xql?existId=" + existId + "&eSciDocCookieId=" + eSciDocCookieId);
        http.onreadystatechange = UpdateESciDocLinkTemp;  
        // this sets the call-back function to be invoked when a response from the HTTP request is returned
        isWorking = true;
        http.send(null);
      }
    }
    function GetHTTPObject() {
      var xmlhttp;
      /*@cc_on
      @if (@_jscript_version >= 5)
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) {
            xmlhttp = false;
          }
        }
      @else
      xmlhttp = false;
      @end @*/
      if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
          xmlhttp = new XMLHttpRequest();
          xmlhttp.overrideMimeType("text/xml"); 
        } catch (e) {
          xmlhttp = false;
        }
      }
      return xmlhttp;
    }
    var http = GetHTTPObject(); //  create the HTTP Object
    var isWorking = false;
    -->
  </script>

let $eSciDocCookieId := session:get-attribute("eSciDocCookieId")

let $docBaseOptions :=
          <select>
            <option value ="archimedes">Archimedes</option>
            <option value ="echo">Echo</option>
          </select>
let $docBaseOptionsSelected :=
  for $option in $docBaseOptions/option
    return element { node-name($option)}
                   { if ($option/@value = $docBase)
                     then attribute {'selected'}
                                    {'true'}
                     else (),
                     $option/@*,
                     $option/node() }
let $docBaseSelectBoxDest :=  
  <select name="docBase" onchange="DocBaseRefreshDest()">{$docBaseOptionsSelected}</select>
let $docBaseSelectBoxList :=
  <select name="docBase" onchange="DocBaseRefreshList()">{$docBaseOptionsSelected}</select>

let $languageOptions :=
          <select>
            <option value = "ar">Arabic</option>
            <option value = "zh">Chinese</option>
            <option value = "nl">Dutch</option>
            <option value = "en">English</option>
            <option value = "fr">French</option>
            <option value = "de">German</option>
            <option value = "el">Greek</option>
            <option value = "it">Italian</option>
            <option value = "la">Latin</option>
          </select>
let $languageOptionsSelected :=
  for $option in $languageOptions/option
    return element { node-name($option)}
                   { if ($option/@value = $language)
                     then attribute {'selected'}
                                    {'true'}
                     else (),
                     $option/@*,
                     $option/node() }
let $languageSelectBoxDest :=  
  <select name="language" onchange="LanguageRefreshDest()">{$languageOptionsSelected}</select>
let $languageSelectBoxList :=
  <select name="language" onchange="LanguageRefreshList()">{$languageOptionsSelected}</select>

let $docsSelectBoxOptions := 
  for $docFileName at $pos in $docFileNames
    let $existIdentifier := concat("/", $docBase, "/", $language, "/", $docFileName)
    let $option := <option value ="{$existIdentifier}">{$docFileName}</option>
  order by $docFileName
  return $option
let $docsSelectBox := 
  <select name="doc" style="width: 100%;" size="20" onclick="DocumentSelection()">
    {$docsSelectBoxOptions}
  </select>

let $error :=
  if ($eSciDocCookieId = '' or empty($eSciDocCookieId))
  then <bla>No login context available. Please <a href="login.xql">login</a> before you do an operation</bla>
  else "no"

let $resultHtml := 
  if ($error = 'no')
  then 
    <div>
    <table align="middle" width="100%">
      <colgroup>
        <col width="50%"/>
        <col width="50%"/>
      </colgroup>
      <tr>
      <td valign="top">
        <form name="formDocOperation" action="{session:encode-url(xs:anyURI('doc-operation-result.xql'))}" method="post" enctype="multipart/form-data">
        <table>
          <tr><td><b>Operation</b></td></tr>
          <tr>
            <td>
              <select name="operation" onchange="OperationSelection()">
                <option value ="create" selected="true">Create</option>
                <option value ="update">Update</option>
                <option value ="delete">Delete</option>
              </select>
              <input type="submit" name="performOperation" value="Execute"/>
              <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>
            </td>
          </tr>
          <tr><td><br/></td></tr>
          <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>
          <tr><td>Local file: <input type="file" size="40" name="srcLocalFileName" onchange="LocalFileNameSelection()" maxlength="10000000" accept="text/xml" value="srcLocalFileName"/>
                              <input type="button" name="resetSrcLocalFileName" value="Reset" onclick="ResetSrcLocalFileName()"/></td></tr>
          <tr><td><text style="margin-left:10px;"></text>or</td></tr>
          <tr><td>Url: <input type="text" size="40" name="srcUrl" onchange="UrlSelection()" value=""/></td></tr>
          <tr><td><br/></td></tr>
          <tr><td><b>Destination</b></td></tr>
          <tr>
            <td>Document base: 
              {$docBaseSelectBoxDest}
            </td>
          </tr>
          <tr>
            <td>Language: 
              {$languageSelectBoxDest}
            </td>
          </tr>
          <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>
          <tr><td>eXist document link: <a id="existLink" href=""></a></td></tr>
          <tr><td>eSciDoc document link: <a id="eSciDocLink" href=""></a></td></tr>
        </table>
        </form>
      </td>
      <td valign="top">
        <form name="docBaseList" action="doc-operation.xql" method="get">
        <input type="hidden" name="eSciDocCookieId" value="{$eSciDocCookieId}"/>
        <table>
          <tr>
            <td>
              <b>Documents</b><br/>
              <br/>
              Document base: 
              {$docBaseSelectBoxList}
              Language:
              {$languageSelectBoxList}
            </td>
          </tr>
          <tr><td>{$docsSelectBox}</td></tr>
        </table>
        </form>
      </td>
      </tr>
    </table>
    </div>
  else 
    <div><b>Error in operation:</b> {$error}</div> 



let $title := "MPDL: eXist/eSciDoc document interface"
return
<html>
<head>
<title>{$title}</title>
{$javascriptHtml}
</head>
<body>
  <h1>{$title}</h1>
  {$resultHtml}
  <hr/>
  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>
</body>
</html>