pier 2003/02/26 09:15:41
Modified: src/java/org/apache/cocoon/components/flow AbstractInterpreter.java src/java/org/apache/cocoon/components/flow/javascript JSCocoon.java system.js Log: Added subrequest processing from the JavaScript flow. Revision Changes Path 1.12 +56 -0 xml-cocoon2/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java Index: AbstractInterpreter.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/AbstractInterpreter.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- AbstractInterpreter.java 31 Jan 2003 22:51:24 -0000 1.11 +++ AbstractInterpreter.java 26 Feb 2003 17:15:40 -0000 1.12 @@ -57,10 +57,14 @@ import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.SingleThreaded; import org.apache.cocoon.Constants; +import org.apache.cocoon.Processor; +import org.apache.cocoon.components.CocoonComponentManager; import org.apache.cocoon.components.treeprocessor.sitemap.PipelinesNode; import org.apache.cocoon.environment.Context; import org.apache.cocoon.environment.Environment; +import org.apache.cocoon.environment.wrapper.EnvironmentWrapper; +import java.io.OutputStream; import java.util.ArrayList; /** @@ -154,6 +158,58 @@ { synchronized(this) { needResolve.add(source); + } + } + + /** + * Call the Cocoon sitemap for the given URI, sending the output of the + * eventually matched pipeline to the specified outputstream. + * + * @param uri The URI for which the request should be generated. + * @param biz Extra data associated with the subrequest. + * @param out An OutputStream where the output should be written to. + * @param env The environment of the original request. + * @return Whatever the Cocoon processor returns (????). + * @exception Exception If an error occurs. + */ + public boolean process(String uri, Object biz, OutputStream out, Environment env) + throws Exception { + if (out == null) { + throw new NullPointerException("No outputstream specified for process"); + } + + // Create a wrapper environment for the subrequest to be processed. + EnvironmentWrapper wrapper = new EnvironmentWrapper(env, uri, "", getLogger()); + wrapper.setURI("",uri); + wrapper.setOutputStream(out); + wrapper.setAttribute("bean-dict", biz); + + // Attermpt to start processing the wrapper environment + Object key = CocoonComponentManager.startProcessing(wrapper); + + Processor processor = null; + boolean result = false; + try { + // Retrieve a processor instance + processor = (Processor)this.manager.lookup(Processor.ROLE); + + // Enter the environment + CocoonComponentManager.enterEnvironment(wrapper, wrapper.getObjectModel(), processor); + + // Process the subrequest + result = processor.process(wrapper); + wrapper.commitResponse(); + out.flush(); + + // Return whatever the processor returned us + return(result); + } catch (Exception any) { + throw(any); + } finally { + // Leave the environment, terminate processing and release processor + CocoonComponentManager.leaveEnvironment(); + CocoonComponentManager.endProcessing(wrapper, key); + this.manager.release(processor); } } 1.17 +22 -0 xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java Index: JSCocoon.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/JSCocoon.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- JSCocoon.java 23 Feb 2003 19:26:57 -0000 1.16 +++ JSCocoon.java 26 Feb 2003 17:15:41 -0000 1.17 @@ -45,6 +45,7 @@ */ package org.apache.cocoon.components.flow.javascript; +import java.io.OutputStream; import java.util.Map; import java.util.HashMap; @@ -226,7 +227,28 @@ if (cont != null) kont = ((JSWebContinuation)cont).getWebContinuation(); + if (bizData != null) System.err.println("FWD:" + bizData.getClass().getName()); + interpreter.forwardTo(uri, bizData, kont, environment); + } + + /** + * Call the Cocoon sitemap for the given URI, sending the output of the + * eventually matched pipeline to the specified outputstream. + * + * @param uri The URI for which the request should be generated. + * @param biz Extra data associated with the subrequest. + * @param out An OutputStream where the output should be written to. + * @return Whatever the Cocoon processor returns (????). + * @exception Exception If an error occurs. + */ + public boolean jsFunction_process(String uri, Object biz, Object out) + throws Exception + { + out = jsobjectToObject(out); + biz = jsobjectToObject(biz); + if (biz != null) System.err.println("PRC:"+biz.getClass().getName()); + return interpreter.process(uri, biz, (OutputStream)out, environment); } /** 1.8 +5 -0 xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/system.js Index: system.js =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/flow/javascript/system.js,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- system.js 23 Feb 2003 19:20:25 -0000 1.7 +++ system.js 26 Feb 2003 17:15:41 -0000 1.8 @@ -43,6 +43,11 @@ bizData, null); } +function process(uri, bizData, output) +{ + cocoon.process(uri, bizData, output); +} + // This function is called to restart a previously saved continuation // passed as argument. function handleContinuation(kont)