home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / sourceflow.js < prev    next >
Encoding:
C/C++ Source or Header  |  2004-07-12  |  4.7 KB  |  149 lines

  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. *     http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17.  * Yeah, I know that hardwiring those is hacky as hell. But I'll try to
  18.  * fix this with link translation later on.
  19.  */
  20. var configPath = cocoon.context.getRealPath("/") + "samples/linotype/";
  21. var home = "webdav://user:password@host/dav/samples/linotype/";
  22.  
  23. var stream = new java.io.FileInputStream(configPath + "linotype.users.properties");
  24. var users = new Packages.org.apache.cocoon.components.UserManager.getInstance(stream);
  25. var repo = new Packages.org.apache.cocoon.components.SourceRepository.getInstance();
  26.  
  27. var userid = "";
  28. var username = "";
  29.  
  30. /*
  31.  * Main entry point for the flow. This is where user authorization takes place.
  32.  */
  33. function main(action) {
  34.     var args = new Array(arguments.length - 1);
  35.     for (var i = 1; i < arguments.length; i++) {
  36.         args[i-1] = arguments[i];
  37.     }            
  38.  
  39.     if ((userid == undefined) || (userid == "")) {
  40.         login(action, args);
  41.     }
  42.                 
  43.     invoke(action, args);
  44. }
  45.  
  46. /*
  47.  * If the user is not yet authorized, than authentication takes place
  48.  */
  49. function login(action, args) {
  50.     var name = "";
  51.     var password = "";
  52.     var userError = "";
  53.     var passError = "";
  54.  
  55.     while (true) {
  56.         sendPageAndWait("screen/login", { username : name, userError : userError, passError : passError});
  57.  
  58.         name = cocoon.request.getParameter("username");
  59.         password = cocoon.request.getParameter("password");
  60.                 
  61.         if (users.isValidName(name)) {
  62.             if (users.isValidPassword(name,password)) {
  63.                 userid = name;
  64.                 username = users.getFullName(name);
  65.                 break;
  66.             } else {
  67.                 userError = "";
  68.                 passError = "Password doesn't match";
  69.             }
  70.         } else {
  71.             userError = "User not found";
  72.             passError = "";
  73.         }
  74.     }
  75.         
  76.     cocoon.createSession();
  77. }
  78.  
  79. /*
  80.  * Now that the user has been authenticated and authorized, execute what 
  81.  * he's asking for. This method checks the flowscript to see if the
  82.  * called action exists as a flowscript function. If so, it's called with
  83.  * the given arguments. If not, the appropriate admin screen is sent
  84.  * to the user.
  85.  */
  86. function invoke(action, args) {
  87.     func = this[action];
  88.     if (func != undefined) {
  89.         func.apply(this,args);
  90.     } else {
  91.         sendPage("screen/" + action, {"user" : username});
  92.     }
  93. }
  94.  
  95. // ----------------------------- actions ----------------------------------
  96.  
  97. /*
  98.  * The logout action clears the userid from the session thus signaling
  99.  * that the user has logged out and should be further considered authenticated. 
  100.  */
  101. function logout() {
  102.     userid = "";
  103.     sendPage("screen/logout");
  104. }
  105.    
  106. /*
  107.  * The edit action performs the editing subflow.
  108.  */
  109. function edit(id,type,subpage) {
  110.     var repository = home + "repository/" + type + "/";
  111.     
  112.     if (id == "template") {
  113.         id = repo.getID(repository);
  114.         repo.copy(repository + "template", repository + id);
  115.         redirect("../" + id + "/");
  116.     } else if ((subpage != undefined) && (subpage != "")) {
  117.         sendPage("edit/" + type + "/" + id + "/" + subpage,{});
  118.     } else {
  119.         var document = repository + id;
  120.  
  121.         while (true) {
  122.             var versions = repo.getVersions(document);
  123.             sendPageAndWait("edit/" + type + "/" + id + "/", { 
  124.                 userid : userid, 
  125.                 username : username, 
  126.                 versions : versions,
  127.                 innerHTML : cocoon.request.getParameter("innerHTML") 
  128.             });
  129.             var action = cocoon.request.getParameter("action");
  130.             if (action == "delete") {
  131.                 repo.remove(document);
  132.                 break;
  133.             } else if (action == "restore") {
  134.                 var version = cocoon.request.getParameter("version");
  135.                 repo.revertFrom(document,version);
  136.             } else {
  137.                 var output = repo.getOutputStream(document);
  138.                 process("samples/linotype/action/save-" + type,{},output);
  139.                 output.close();
  140.                 repo.save(cocoon.request, document);
  141.                 if (action == "finish") break;
  142.             }                   
  143.         }
  144.  
  145.         redirect("../../../" + type);
  146.     }
  147. }
  148.  
  149.