Author: mrdon
Date: Fri Mar 25 16:12:21 2005
New Revision: 159078

URL: http://svn.apache.org/viewcvs?view=rev&rev=159078
Log:
 * Added source code comments and javadocs
 * Updated Javascript Templates file
 * Removed cocoon legacy from examples

Modified:
    struts/flow/trunk/src/examples/WEB-INF/guess/success.jsp
    struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp
    struts/flow/trunk/src/examples/WEB-INF/remote/success.jsp
    struts/flow/trunk/src/examples/WEB-INF/templates/success.jt
    struts/flow/trunk/src/examples/templates/template.js
    struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java
    struts/flow/trunk/src/java/org/apache/struts/flow/json/JSONSerializer.java
    struts/flow/trunk/src/java/struts.js
    struts/flow/trunk/src/java/system.js

Modified: struts/flow/trunk/src/examples/WEB-INF/guess/success.jsp
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/guess/success.jsp?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/guess/success.jsp (original)
+++ struts/flow/trunk/src/examples/WEB-INF/guess/success.jsp Fri Mar 25 
16:12:21 2005
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <html>
 <head>
-  <title>cocoon flow number guessing game</title>
+  <title>Struts Flow number guessing game</title>
 </head>
 <body>
 

Modified: struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp (original)
+++ struts/flow/trunk/src/examples/WEB-INF/remote/guess.jsp Fri Mar 25 16:12:21 
2005
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <html>
 <head>
-  <title>Struts Flow number guessing game</title>
+  <title>Struts Flow number guessing game - Remote edition</title>
     <script type="text/javascript">
   <!--
 function init() {

Modified: struts/flow/trunk/src/examples/WEB-INF/remote/success.jsp
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/remote/success.jsp?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/remote/success.jsp (original)
+++ struts/flow/trunk/src/examples/WEB-INF/remote/success.jsp Fri Mar 25 
16:12:21 2005
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <html>
 <head>
-  <title>cocoon flow number guessing game</title>
+  <title>Struts Flow number guessing game - Remote edition</title>
 </head>
 <body>
 

Modified: struts/flow/trunk/src/examples/WEB-INF/templates/success.jt
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/WEB-INF/templates/success.jt?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/examples/WEB-INF/templates/success.jt (original)
+++ struts/flow/trunk/src/examples/WEB-INF/templates/success.jt Fri Mar 25 
16:12:21 2005
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <html>
 <head>
-  <title>cocoon flow number guessing game</title>
+  <title>Struts Flow number guessing game</title>
 </head>
 <body>
 

Modified: struts/flow/trunk/src/examples/templates/template.js
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/examples/templates/template.js?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/examples/templates/template.js (original)
+++ struts/flow/trunk/src/examples/templates/template.js Fri Mar 25 16:12:21 
2005
@@ -1,5 +1,5 @@
 /**
- * TrimPath Template. Release 1.0.20.
+ * TrimPath Template. Release 1.0.26.
  * Copyright (C) 2004, 2005 Metaha.
  * 
  * TrimPath Template is licensed under the GNU General Public License
@@ -30,39 +30,40 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-var TrimPath;
-
-// TODO: Debugging mode vs stop-on-error mode - runtime flag.
+var TrimPath;
+
+// TODO: Debugging mode vs stop-on-error mode - runtime flag.
 // TODO: Handle || (or) characters and backslashes.
 // TODO: Add more modifiers.
-
-(function() {               // Using a closure to keep global namespace clean.
-    var theEval = eval;     // Security, to ensure eval cleanliness.
-    if (TrimPath == null)
-        TrimPath = new Object();
-
-    TrimPath.parseTemplate = function(tmplContent, optTmplName, optEtc) {
-        if (optEtc == null)
-            optEtc = TrimPath.parseTemplate_etc;
+
+(function() {               // Using a closure to keep global namespace clean.
+    if (TrimPath == null)
+        TrimPath = new Object();
+    if (TrimPath.evalEx == null)
+        TrimPath.evalEx = function(src) { return eval(src); };
+
+    TrimPath.parseTemplate = function(tmplContent, optTmplName, optEtc) {
+        if (optEtc == null)
+            optEtc = TrimPath.parseTemplate_etc;
         var funcSrc = parse(tmplContent, optTmplName, optEtc);
-        var func = eval(funcSrc, optTmplName, 1);
+        var func = TrimPath.evalEx(funcSrc, optTmplName, 1);
         if (func != null)
             return new optEtc.Template(optTmplName, tmplContent, funcSrc, 
func, optEtc);
         return null;
-    }
-    
-    try {
-        String.prototype.process = function(context, optFlags) {
+    }
+    
+    try {
+        String.prototype.process = function(context, optFlags) {
             var template = TrimPath.parseTemplate(this, null);
             if (template != null)
                 return template.process(context, optFlags);
-            return this;
-        }
-    } catch (e) { // Swallow exception, such as when String.prototype is 
sealed.
-    }
-    
-    TrimPath.parseTemplate_etc = {};            // Exposed for extensibility.
-    TrimPath.parseTemplate_etc.statementTag = 
"forelse|for|if|elseif|else|var|macro";
+            return this;
+        }
+    } catch (e) { // Swallow exception, such as when String.prototype is 
sealed.
+    }
+    
+    TrimPath.parseTemplate_etc = {};            // Exposed for extensibility.
+    TrimPath.parseTemplate_etc.statementTag = 
"forelse|for|if|elseif|else|var|macro";
     TrimPath.parseTemplate_etc.statementDef = { // Lookup table for statement 
tags.
         "if"     : { delta:  1, prefix: "if (", suffix: ") {", paramMin: 1 },
         "else"   : { delta:  0, prefix: "} else {" },
@@ -84,53 +85,55 @@
         "var"     : { delta:  0, prefix: "var ", suffix: ";" },
         "macro"   : { delta:  1, prefix: "function ", suffix: "{ var _OUT_arr 
= []; var _OUT = { write: function(m) { if (m) _OUT_arr.push(m); } }; " }, 
         "/macro"  : { delta: -1, prefix: " return _OUT_arr.join(''); }" }
-    }
-    TrimPath.parseTemplate_etc.modifierDef = {
-        "eat"        : function(v)    { return ""; },
-        "escape"     : function(s)    { return String(s).replace(/&/g, 
"&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); },
-        "capitalize" : function(s)    { return String(s).toUpperCase(); },
-        "default"    : function(s, d) { return s != null ? s : d; }
+    }
+    TrimPath.parseTemplate_etc.modifierDef = {
+        "eat"        : function(v)    { return ""; },
+        "escape"     : function(s)    { return String(s).replace(/&/g, 
"&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;"); },
+        "capitalize" : function(s)    { return String(s).toUpperCase(); },
+        "default"    : function(s, d) { return s != null ? s : d; }
     }
     TrimPath.parseTemplate_etc.modifierDef.h = 
TrimPath.parseTemplate_etc.modifierDef.escape;
-
+
     TrimPath.parseTemplate_etc.Template = function(tmplName, tmplContent, 
funcSrc, func, etc) {
-        this.process = function(context, flags) {
-            if (context == null)
-                context = {};
-            if (context._MODIFIERS == null)
+        this.process = function(context, flags) {
+            if (context == null)
+                context = {};
+            if (context._MODIFIERS == null)
                 context._MODIFIERS = {};
-            for (var k in etc.modifierDef) {
-                if (context._MODIFIERS[k] == null)
-                    context._MODIFIERS[k] = etc.modifierDef[k];
-            }
-            if (flags == null)
-                flags = {};
+            if (context.defined == null)
+                context.defined = function(str) { return (context[str] != 
undefined); };
+            for (var k in etc.modifierDef) {
+                if (context._MODIFIERS[k] == null)
+                    context._MODIFIERS[k] = etc.modifierDef[k];
+            }
+            if (flags == null)
+                flags = {};
             var resultArr = [];
-            var resultOut = { write: function(m) { if (m) resultArr.push(m); } 
};
+            var resultOut = { write: function(m) { resultArr.push(m); } };
             try {
-                func(resultOut, context, flags);
-            } catch (e) {
-                if (flags.throwExceptions == true)
-                    throw e;
+                func(resultOut, context, flags);
+            } catch (e) {
+                if (flags.throwExceptions == true)
+                    throw e;
                 var result = new String(resultArr.join("") + "[ERROR: " + 
e.toString() + "]");
                 result["exception"] = e;
-                return result;
+                return result;
             }
             return resultArr.join("");
-        }
-        this.name       = tmplName;
-        this.source     = tmplContent; 
-        this.sourceFunc = funcSrc;
+        }
+        this.name       = tmplName;
+        this.source     = tmplContent; 
+        this.sourceFunc = funcSrc;
         this.toString   = function() { return "TrimPath.Template [" + tmplName 
+ "]"; }
     }
-    TrimPath.parseTemplate_etc.ParseError = function(name, line, message) {
+    TrimPath.parseTemplate_etc.ParseError = function(name, line, message) {
         this.name    = name;
         this.line    = line;
         this.message = message;
     }
     TrimPath.parseTemplate_etc.ParseError.prototype.toString = function() { 
         return ("TrimPath template ParseError in " + this.name + ": line " + 
this.line + ", " + this.msg);
-    }
+    }
     
     var parse = function(body, tmplName, etc) {
         body = cleanWhiteSpace(body);
@@ -203,12 +206,12 @@
             funcText.push(stmt.suffix);
         }
     }
-
+
     var emitSectionText = function(text, funcText) {
         if (text.length <= 0)
             return;
         var nlPrefix = 0;               // Index to first non-newline in 
prefix.
-        var nlSuffix = text.length - 1; // Index to first non-space/tab in 
suffix.
+        var nlSuffix = text.length - 1; // Index to first non-space/tab in 
suffix.
         while (nlPrefix < text.length && (text.charAt(nlPrefix) == '\n'))
             nlPrefix++;
         while (nlSuffix >= 0 && (text.charAt(nlSuffix) == ' ' || 
text.charAt(nlSuffix) == '\t'))
@@ -216,7 +219,7 @@
         if (nlSuffix < nlPrefix)
             nlSuffix = nlPrefix;
         if (nlPrefix > 0) {
-            funcText.push('if (_FLAGS.keepWhitespace == true) _OUT.write("');
+            funcText.push('if (_FLAGS.keepWhitespace == true) _OUT.write("');
             var s = text.substring(0, nlPrefix).replace('\n', '\\n'); // A 
macro IE fix from BJessen.
             if (s.charAt(s.length - 1) == '\n')
                s = s.substring(0, s.length - 1);
@@ -228,7 +231,7 @@
             emitSectionTextLine(lines[i], funcText);
             if (i < lines.length - 1)
                 funcText.push('_OUT.write("\\n");\n');
-        }
+        }
         if (nlSuffix + 1 < text.length) {
             funcText.push('if (_FLAGS.keepWhitespace == true) _OUT.write("');
             var s = text.substring(nlSuffix + 1).replace('\n', '\\n');
@@ -282,7 +285,7 @@
     var emitExpression = function(exprArr, index, funcText) {
         // Ex: foo|a:x|b:y1,y2|c:z1,z2 is emitted as c(b(a(foo,x),y1,y2),z1,z2)
         var expr = exprArr[index]; // Ex: exprArr == 
[firstName,capitalize,default:"John Doe"]
-        if (index <= 0) {          // Ex: expr    == 'default:"John Doe"'
+        if (index <= 0) {          // Ex: expr    == 'default:"John Doe"'
             funcText.push(expr);
             return;
         }
@@ -296,7 +299,7 @@
             funcText.push(parts[1]);
         }
         funcText.push(')');
-    }
+    }
 
     var cleanWhiteSpace = function(result) {
         result = result.replace(/\t/g,   "    ");

Modified: struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java (original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/FlowAction.java Fri Mar 
25 16:12:21 2005
@@ -116,6 +116,8 @@
             interp = getInterpreter(flowMapping.getModuleConfig().getPrefix(), 
flowMapping.getScript());
         }
 
+        // A FlowCall means the request came from client-side javascript that
+        // expects the return type to be JSON
         boolean isFlowCall = (request.getParameter("FlowCall") != null);
         String func = null;
         if (isFlowCall) {
@@ -156,6 +158,7 @@
             // kick off continuation
             context.put("id", "5");
             
+            // validate JSON in the body of a flowcall
             if (isFlowCall) {
                 StringBuffer sb = new StringBuffer();
                 char[] buffer = new char[1024];
@@ -185,7 +188,8 @@
             if (bizdata != null) {
                 atts = JSContext.jsobjectToMap(bizdata);
             }    
-            
+           
+            // if a flowcall, return pure json 
             if (isFlowCall) {
                 atts.put("contid", contid);
                 String json = new JSONSerializer().serialize(atts);

Modified: 
struts/flow/trunk/src/java/org/apache/struts/flow/json/JSONSerializer.java
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/org/apache/struts/flow/json/JSONSerializer.java?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/java/org/apache/struts/flow/json/JSONSerializer.java 
(original)
+++ struts/flow/trunk/src/java/org/apache/struts/flow/json/JSONSerializer.java 
Fri Mar 25 16:12:21 2005
@@ -16,11 +16,9 @@
 import java.beans.PropertyDescriptor;
 import java.lang.reflect.Array;
 import java.lang.reflect.Method;
-//import org.apache.commons.jxpath.*;
-
 
 /**
- *  Serializes objects by firing SAX events
+ *  Serializes objects into JSON
  */
 public class JSONSerializer {
 
@@ -49,7 +47,8 @@
     }
     
     /**
-     *  Recursive function to serialize objects to XML. Currently it will
+     *  Recursive function to serialize objects to JSON objects that will
+     *  handle serialization into JSON. Currently it will
      *  serialize Collections, Maps, Arrays, and javabeans. It maintains a 
      *  stack of objects serialized already in the
      *  current functioncall. This is used to avoid looping (stack overflow) of

Modified: struts/flow/trunk/src/java/struts.js
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/struts.js?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/java/struts.js (original)
+++ struts/flow/trunk/src/java/struts.js Fri Mar 25 16:12:21 2005
@@ -1,3 +1,7 @@
+/**
+ * This file contains convenience functions to get at Struts information.
+*/
+
 importClass(Packages.org.apache.struts.flow.Constants);
 importPackage(Packages.org.apache.struts.flow.core);
 

Modified: struts/flow/trunk/src/java/system.js
URL: 
http://svn.apache.org/viewcvs/struts/flow/trunk/src/java/system.js?view=diff&r1=159077&r2=159078
==============================================================================
--- struts/flow/trunk/src/java/system.js (original)
+++ struts/flow/trunk/src/java/system.js Fri Mar 25 16:12:21 2005
@@ -1,8 +1,7 @@
-
 var suicide;
-
 var lastContinuation = null;
 
+// starts a continuation
 function startContinuation(lastWebCont) {
     var k = new Continuation();
     
@@ -15,21 +14,29 @@
     return kont;
 } 
 
-
+// calls the specified function
 function callFunction(func, args)
 {
    suicide = new Continuation();
    return func.apply(this, args);
 }
 
+// Forwards to a page and creates a continuation. Contains special support
+// for client FlowCall's.
 function forwardAndWait(name, atts, allowedRemoteFuncs)
 {
    var kont = _forwardAndWait(name, atts);
    lastContinuation = kont;
+ 
+   // process the resulting request differently if a client-side call
    func = context.get("func");
    if (func != null) {
        var ret;
        var callFunc = false;
+
+       // if a list of allowed functions are provided, use it.  If the list is
+       // empty, assume any can be called.  If a list isn't provided, assume
+       // no functions can be called.
        if (allowedRemoteFuncs) {
            if (allowedRemoteFuncs.length == 0) {
                callFunc = true;
@@ -56,6 +63,7 @@
    return kont;
 }
 
+// do the actual work to forward to a page and create a continuation
 function _forwardAndWait(name, atts)
 {
    var k = new Continuation();



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to