ovidiu      02/04/01 20:58:55

  Modified:    src/scratchpad/schecoon/src/org/apache/cocoon/components/flow
                        AbstractInterpreter.java
  Log:
  Refactor processPipeline() and forwardTo() from
  JavaScriptInterpreter. Continue reading scripts even if there are
  errors.
  
  Revision  Changes    Path
  1.5       +77 -7     
xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/AbstractInterpreter.java
  
  Index: AbstractInterpreter.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/scratchpad/schecoon/src/org/apache/cocoon/components/flow/AbstractInterpreter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractInterpreter.java  21 Mar 2002 23:10:55 -0000      1.4
  +++ AbstractInterpreter.java  2 Apr 2002 04:58:54 -0000       1.5
  @@ -4,6 +4,7 @@
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.Iterator;
  +import java.util.Map;
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
  @@ -15,6 +16,10 @@
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.components.source.SourceFactory;
   import org.apache.cocoon.components.treeprocessor.CategoryNode;
  +import org.apache.cocoon.components.treeprocessor.InvokeContext;
  +import org.apache.cocoon.components.treeprocessor.MapStackResolver;
  +import org.apache.cocoon.components.treeprocessor.ProcessingNode;
  +import org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode;
   import org.apache.cocoon.environment.Context;
   import org.apache.cocoon.environment.Environment;
   
  @@ -22,7 +27,8 @@
    * Abstract superclass for various scripting languages used by Cocoon
    * for flow control. Defines some useful behavior like the ability to
    * reload script files if they get modified (useful when doing
  - * development).
  + * development), and passing the control to Cocoon's sitemap for
  + * result page generation.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Ovidiu Predescu</a>
    * @since March 15, 2002
  @@ -31,8 +37,7 @@
     implements Component, Composable, Contextualizable, Interpreter, ThreadSafe
   {
     /**
  -   * Hash table of source locations -> DelayedRefreshSourceWrapper
  -   * instances
  +   * Hash table of source locations -> ScriptSource instances
      */
     protected HashMap scripts = new HashMap();
   
  @@ -63,7 +68,7 @@
      */
     protected long checkTime;
   
  -  CategoryNode resources;
  +  protected CategoryNode resources;
   
     public void compose(ComponentManager manager)
       throws ComponentException
  @@ -173,8 +178,15 @@
         Iterator iter = scripts.values().iterator();
         while (iter.hasNext()) {
           ScriptSource src = (ScriptSource)iter.next();
  -        if (src.getLastModified() > lastTimeCheck)
  -          src.refresh(environment);
  +        if (src.getLastModified() > lastTimeCheck) {
  +          try {
  +            src.refresh(environment);
  +          }
  +          catch (Exception ex) {
  +            System.out.println("Error reading script " + src.getSourceName()
  +                               + ", ignoring!");
  +          }
  +        }
         }
       }
   
  @@ -186,7 +198,12 @@
           ScriptSource src = new ScriptSource(this, source);
           scripts.put(source, src);
           needResolve.remove(0);
  -        src.refresh(environment);
  +        try {
  +          src.refresh(environment);
  +        }
  +        catch (Exception ex) {
  +          System.out.println("Error reading script " + source + ", ignoring!");
  +        }
         }
       }
   
  @@ -194,5 +211,58 @@
       // is not executed, so the next request will force a reparse of
       // the script files because of an old time stamp.
       lastTimeCheck = System.currentTimeMillis();
  +  }
  +
  +  public void processPipeline(String name, Map pipelineArgs, Object bizData,
  +                              WebContinuation continuation,
  +                              Environment environment, InvokeContext ctx)
  +    throws Exception
  +  {
  +    if (ctx == null) {
  +      String msg = "Cannot invoke pipeline with a null InvokeContext! Make sure"
  +        + " you're calling the pipeline during the execution of a request.";
  +      throw new RuntimeException(msg);
  +    }
  +
  +    environment.setAttribute("bean-dict", bizData);
  +    environment.setAttribute("kont", continuation);
  +
  +    ProcessingNode pipeline
  +      = resources.getNodeByName(MapStackResolver.unescape(name));
  +
  +    if (pipelineArgs != null)
  +      ctx.pushMap(pipelineArgs);
  +    try {
  +      pipeline.invoke(environment, ctx);
  +    }
  +    finally {
  +      environment.removeAttribute("bean-dict");
  +      environment.removeAttribute("kont");
  +      if (pipelineArgs != null)
  +        ctx.popMap();
  +    }
  +  }
  +
  +  public void forwardTo(String uri, Object bizData,
  +                        WebContinuation continuation,
  +                        Environment environment, InvokeContext ctx)
  +    throws Exception
  +  {
  +    if (ctx == null) {
  +      String msg = "Cannot invoke pipeline with a null InvokeContext! Make sure"
  +        + " you're calling the pipeline during the execution of a request.";
  +      throw new RuntimeException(msg);
  +    }
  +
  +    environment.setAttribute("bean-dict", bizData);
  +    environment.setAttribute("kont", continuation);
  +
  +    try {
  +      PipelinesNode.getRedirector(environment).redirect(false, uri);
  +    }
  +    finally {
  +      environment.removeAttribute("bean-dict");
  +      environment.removeAttribute("kont");
  +    }
     }
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to