cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgritse...@apache.org
Subject svn commit: r233389 - in /cocoon/blocks/cron/trunk: WEB-INF/xconf/cocoon-cron.xconf samples/cron.js
Date Thu, 18 Aug 2005 22:00:24 GMT
Author: vgritsenko
Date: Thu Aug 18 15:00:18 2005
New Revision: 233389

URL: http://svn.apache.org/viewcvs?rev=233389&view=rev
Log:
Fix cron sample (bug #34754)
Updated flow function to use cocoon.parameters.
Reformat flowsciprt.

Modified:
    cocoon/blocks/cron/trunk/WEB-INF/xconf/cocoon-cron.xconf
    cocoon/blocks/cron/trunk/samples/cron.js

Modified: cocoon/blocks/cron/trunk/WEB-INF/xconf/cocoon-cron.xconf
URL: http://svn.apache.org/viewcvs/cocoon/blocks/cron/trunk/WEB-INF/xconf/cocoon-cron.xconf?rev=233389&r1=233388&r2=233389&view=diff
==============================================================================
--- cocoon/blocks/cron/trunk/WEB-INF/xconf/cocoon-cron.xconf (original)
+++ cocoon/blocks/cron/trunk/WEB-INF/xconf/cocoon-cron.xconf Thu Aug 18 15:00:18 2005
@@ -149,7 +149,8 @@
 
   <!--+
       | Sample definition of the TestCronJob cron job, used by
-      | trigger configuration above.
+      | trigger configuration above, as well as by sample page.
+      +-->
   <component role="org.apache.cocoon.components.cron.CronJob/test"
              class="org.apache.cocoon.components.cron.TestCronJob"
              logger="cron.test">
@@ -157,7 +158,6 @@
     <sleep>23000</sleep>
     <pipeline>samples/hello-world/hello.xhtml</pipeline>
   </component>
-      +-->
 
   <!--+
       | Sample definition of the CocoonPipelineCronJob cron job, used by

Modified: cocoon/blocks/cron/trunk/samples/cron.js
URL: http://svn.apache.org/viewcvs/cocoon/blocks/cron/trunk/samples/cron.js?rev=233389&r1=233388&r2=233389&view=diff
==============================================================================
--- cocoon/blocks/cron/trunk/samples/cron.js (original)
+++ cocoon/blocks/cron/trunk/samples/cron.js Thu Aug 18 15:00:18 2005
@@ -13,29 +13,33 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
+
 function Format() {
 }
-    
+
 Format.prototype.format = function(date) {
-    if( date == null || date == undefined )
+    if (date == null || date == undefined) {
         return "-";
-       return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
+    }
+    return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
 }
+
 Format.prototype.parse = function(date) {
-    if( date == null || date == undefined )
+    if (date == null || date == undefined) {
         return "";
-       return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
+    }
+    return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(date);
 }
 
-function cron( realPath )
-{
-    var done = false;
+function cron() {
+    var realPath = cocoon.parameters.realPath;
+
     var scheduler = cocoon.getComponent(Packages.org.apache.cocoon.components.cron.JobScheduler.ROLE);
     var msg_param_key = Packages.org.apache.cocoon.components.cron.TestCronJob.PARAMETER_MESSAGE;
     var sleep_param_key = Packages.org.apache.cocoon.components.cron.TestCronJob.PARAMETER_SLEEP;
     var pipeline_param_key = Packages.org.apache.cocoon.components.cron.TestCronJob.PARAMETER_PIPELINE;
     var testjobrole = "org.apache.cocoon.components.cron.CronJob/test";
-    var logsize = 15;
+    var logsize = 50;
     var formatter = new Format();
     var jobname = "";
     var message = "I'm here";
@@ -45,103 +49,99 @@
     var intervalexpr = "";
     var atexpr = "";
     var i = 0;
-    while( ! done )
-    {
+
+    var done = false;
+    while (!done) {
+        // List scheduled jobs
         var jobnames = scheduler.getJobNames();
         var list = [];
-        for( i = 0; i < jobnames.length; i++ ) 
-        {
-            list[ i ] = scheduler.getJobSchedulerEntry( jobnames[ i ] );
+        for (i = 0; i < jobnames.length; i++) {
+            list[i] = scheduler.getJobSchedulerEntry(jobnames[i]);
         }
-        
-        var fileName = realPath + "/WEB-INF/logs/cron.log";
-        var rdr = new java.io.BufferedReader( java.io.FileReader( fileName ) );
+
+        // Load log file content - last logsize lines.
+        var fileName = realPath + "/WEB-INF/logs/cocoon.log";
+        var rdr = new java.io.BufferedReader(java.io.FileReader(fileName));
         var count = 0;
         var lines = new java.util.LinkedList();
         var line = rdr.readLine();
-        while( line != null )
-        {
+        while (line != null) {
             count++;
-            lines.addLast( line );
-            if( count > logsize )
-            {
+            lines.addLast(line);
+            if (count > logsize) {
                 lines.removeFirst();
             }
             line = rdr.readLine();
         }
-        cocoon.sendPageAndWait( "cron.view", { "entries"      : list, 
+
+        cocoon.sendPageAndWait( "cron.view", { "entries"      : list,
                                                "log"          : lines,
                                                "formatter"    : formatter,
                                                "jobname"      : jobname,
                                                "message"      : message,
                                                "sleep"        : sleep,
-                                               "pipeline"     : pipeline,               
                               
+                                               "pipeline"     : pipeline,
                                                "cronexpr"     : cronexpr,
                                                "intervalexpr" : intervalexpr,
                                                "atexpr"       : atexpr
-                                             } 
+                                             }
         );
+
         var action = cocoon.request.getParameter( "action" );
-        if( action == "remove" )
-        {
+        if (action == "remove") {
             var name = cocoon.request.getParameter( "name" );
             scheduler.removeJob( name );
-        }
-        else if( action == "add" )
-        {
-            jobname = cocoon.request.getParameter( "jobname" );
-            message = cocoon.request.getParameter( "message" );
-            sleep = cocoon.request.getParameter( "sleep" );
-            pipeline = cocoon.request.getParameter( "pipeline" );
-            cronexpr = cocoon.request.getParameter( "cronexpr" );
-            intervalexpr = cocoon.request.getParameter( "intervalexpr" );
-            atexpr = cocoon.request.getParameter( "atexpr" );
-            
-            var scheduletype = cocoon.request.getParameter( "cron" );
-            if( scheduletype != null )
-            {
+        } else if (action == "add") {
+            jobname = cocoon.request.getParameter("jobname");
+            message = cocoon.request.getParameter("message");
+            sleep = cocoon.request.getParameter("sleep");
+            pipeline = cocoon.request.getParameter("pipeline");
+            cronexpr = cocoon.request.getParameter("cronexpr");
+            intervalexpr = cocoon.request.getParameter("intervalexpr");
+            atexpr = cocoon.request.getParameter("atexpr");
+
+            var scheduletype = cocoon.request.getParameter("cron");
+            if (scheduletype != null) {
                 var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
-                params.setParameter( msg_param_key, message );
+                params.setParameter(msg_param_key, message);
                 var sleepms = sleep * 1000;
-                params.setParameter( sleep_param_key, sleepms );
-                params.setParameter( pipeline_param_key, pipeline );
+                params.setParameter(sleep_param_key, sleepms);
+                params.setParameter(pipeline_param_key, pipeline);
                 scheduler.addJob(jobname, testjobrole, cronexpr, false, params, null);
             }
-            scheduletype = cocoon.request.getParameter( "periodic" );
-            if( scheduletype != null )
-            {
+
+            scheduletype = cocoon.request.getParameter("periodic");
+            if (scheduletype != null) {
                 var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
-                params.setParameter( msg_param_key, message );
+                params.setParameter(msg_param_key, message);
                 var sleepms = sleep * 1000;
-                params.setParameter( sleep_param_key, sleepms );
-                params.setParameter( pipeline_param_key, pipeline );                
+                params.setParameter(sleep_param_key, sleepms);
+                params.setParameter(pipeline_param_key, pipeline);
                 scheduler.addPeriodicJob(jobname, testjobrole, intervalexpr, false, params,
null);
             }
-            scheduletype = cocoon.request.getParameter( "at" );
-            if( scheduletype != null )
-            {
+
+            scheduletype = cocoon.request.getParameter("at");
+            if (scheduletype != null) {
                 var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
-                params.setParameter( msg_param_key, message );
+                params.setParameter(msg_param_key, message);
                 var sleepms = sleep * 1000;
-                params.setParameter( sleep_param_key, sleepms );
-                params.setParameter( pipeline_param_key, pipeline );                
-                var date = formatter.parse( atexpr );
+                params.setParameter(sleep_param_key, sleepms);
+                params.setParameter(pipeline_param_key, pipeline);
+                var date = formatter.parse(atexpr);
                 scheduler.fireJobAt(date, jobname, testjobrole, params, null)
             }
-            scheduletype = cocoon.request.getParameter( "immediately" );
-            if( scheduletype != null )
-            {
+
+            scheduletype = cocoon.request.getParameter("immediately");
+            if (scheduletype != null) {
                 var params = new Packages.org.apache.avalon.framework.parameters.Parameters();
-                params.setParameter( msg_param_key, message );
+                params.setParameter(msg_param_key, message);
                 var sleepms = sleep * 1000;
-                params.setParameter( sleep_param_key, sleepms );
-                params.setParameter( pipeline_param_key, pipeline );                
+                params.setParameter(sleep_param_key, sleepms);
+                params.setParameter(pipeline_param_key, pipeline);
                 scheduler.fireJob(testjobrole, params, null)
             }
-        }
-        else
-        {
+        } else {
             // do a refresh
         }
     }
-}
\ No newline at end of file
+}



Mime
View raw message