cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/generation PhpGenerator.java
Date Fri, 20 Apr 2001 12:03:32 GMT
cziegeler    01/04/20 05:03:31

  Modified:    src/org/apache/cocoon/environment/http Tag: xml-cocoon2
                        HttpEnvironment.java
               src/org/apache/cocoon/generation Tag: xml-cocoon2
                        PhpGenerator.java
  Log:
  Fix for the PhpServlet (and any other components based on the javax.servlet
  package).
  The HttpEnvironment adds the HttpServletResponse, the HttpServletRequest
  and the ServletContext to the objectModel. So any component can get
  these objects.
  For the PhpGenerator this is very legal as the generator itself uses a servlet
  environment.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.25  +8 -0      xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java
  
  Index: HttpEnvironment.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/environment/http/Attic/HttpEnvironment.java,v
  retrieving revision 1.1.2.24
  retrieving revision 1.1.2.25
  diff -u -r1.1.2.24 -r1.1.2.25
  --- HttpEnvironment.java	2001/04/20 11:27:18	1.1.2.24
  +++ HttpEnvironment.java	2001/04/20 12:03:22	1.1.2.25
  @@ -28,6 +28,10 @@
   
   public class HttpEnvironment extends AbstractEnvironment {
   
  +    public static final String HTTP_REQUEST_OBJECT = "httprequest";
  +    public static final String HTTP_RESPONSE_OBJECT= "httpresponse";
  +    public static final String HTTP_SERVLET_CONTEXT= "httpservletcontext";
  +
       /** The HttpRequest */
       private HttpRequest request = null;
   
  @@ -57,6 +61,10 @@
           this.objectModel.put(Constants.REQUEST_OBJECT, this.request);
           this.objectModel.put(Constants.RESPONSE_OBJECT, this.response);
           this.objectModel.put(Constants.CONTEXT_OBJECT, this.context);
  +        // This is a hack for the Php Generator
  +        this.objectModel.put(HTTP_REQUEST_OBJECT, req);
  +        this.objectModel.put(HTTP_RESPONSE_OBJECT, res);
  +        this.objectModel.put(HTTP_SERVLET_CONTEXT, servletContext);
       }
   
      /**
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.19  +19 -8     xml-cocoon/src/org/apache/cocoon/generation/Attic/PhpGenerator.java
  
  Index: PhpGenerator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/generation/Attic/PhpGenerator.java,v
  retrieving revision 1.1.2.18
  retrieving revision 1.1.2.19
  diff -u -r1.1.2.18 -r1.1.2.19
  --- PhpGenerator.java	2001/04/19 16:58:19	1.1.2.18
  +++ PhpGenerator.java	2001/04/20 12:03:25	1.1.2.19
  @@ -18,11 +18,13 @@
   import javax.servlet.http.HttpServletResponse;
   import javax.servlet.ServletException;
   
  -import org.apache.cocoon.components.parser.Parser;
  -
  -import org.apache.avalon.Poolable;
   import org.apache.avalon.Component;
  +import org.apache.avalon.Poolable;
  +
  +import org.apache.cocoon.ProcessingException;
   import org.apache.cocoon.Roles;
  +import org.apache.cocoon.components.parser.Parser;
  +import org.apache.cocoon.environment.http.HttpEnvironment;
   
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  @@ -33,7 +35,7 @@
    * results into SAX events.
    *
    * @author <a href="mailto:rubys@us.ibm.com">Sam Ruby</a>
  - * @version CVS $Revision: 1.1.2.18 $ $Date: 2001/04/19 16:58:19 $
  + * @version CVS $Revision: 1.1.2.19 $ $Date: 2001/04/20 12:03:25 $
    */
   public class PhpGenerator extends ServletGenerator implements Poolable {
   
  @@ -113,7 +115,16 @@
       /**
        * Generate XML data from PHP.
        */
  -    public void generate() throws IOException, SAXException {
  +    public void generate() throws IOException, SAXException, ProcessingException {
  +
  +        // ensure that we are running in a servlet environment
  +        HttpServletResponse httpResponse =
  +            (HttpServletResponse)this.objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
  +        HttpServletRequest httpRequest =
  +            (HttpServletRequest)this.objectModel.get(HttpEnvironment.HTTP_REQUEST_OBJECT);
  +        if (httpResponse == null || httpRequest == null) {
  +            throw new ProcessingException("HttpServletRequest or HttpServletResponse object
not available");
  +        }
   
           // ensure that we are serving a file...
           InputSource inputSource = this.resolver.resolveEntity(null, this.source);
  @@ -128,11 +139,11 @@
   
               // start PHP producing results into the pipe
               PhpServlet php = new PhpServlet();
  -            php.init(new config((ServletContext)context));
  +            php.init(new config((ServletContext)this.objectModel.get(HttpEnvironment.HTTP_SERVLET_CONTEXT)));
               php.setInput(systemId.substring(6));
               php.setOutput(new PipedOutputStream(input));
  -            php.setRequest((HttpServletRequest)request);
  -            php.setResponse((HttpServletResponse)response);
  +            php.setRequest(httpRequest);
  +            php.setResponse(httpResponse);
               new Thread(php).start();
   
               // pipe the results into the parser
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message