You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by jo...@apache.org on 2004/03/06 15:05:04 UTC

cvs commit: cocoon-2.1/src/java/org/apache/cocoon/generation StreamGenerator.java

joerg       2004/03/06 06:05:04

  Modified:    src/webapp/samples/stream sitemap.xmap
               .        status.xml
               src/webapp/samples components-samples.xml
               src/java/org/apache/cocoon/generation StreamGenerator.java
  Added:       src/webapp/samples/stream uploadstring.xml uploadfile.xml
  Removed:     src/webapp/samples/stream OrderPage.xml
  Log:
  fixes-bug 25594, thanks to Gernot Koller: Allow streaming of uploaded files into a pipeline using StreamGenerator.
  
  Revision  Changes    Path
  1.6       +4 -4      cocoon-2.1/src/webapp/samples/stream/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/stream/sitemap.xmap,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sitemap.xmap	6 Mar 2004 02:26:06 -0000	1.5
  +++ sitemap.xmap	6 Mar 2004 14:05:03 -0000	1.6
  @@ -44,14 +44,14 @@
   
     <map:pipeline>
   
  -   <map:match pattern="order">
  -     <map:generate src="OrderPage.xml"/>
  +   <map:match pattern="upload*">
  +     <map:generate src="{0}.xml"/>
        <map:transform src="context://samples/stylesheets/dynamic-page2html.xsl">
           <map:parameter name="servletPath" value="{request:servletPath}"/>
           <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
           <map:parameter name="contextPath" value="{request:contextPath}"/>
           <map:parameter name="remove" value="order"/>
  -        <map:parameter name="file" value="OrderPage.xml"/>
  +        <map:parameter name="file" value="{0}.xml"/>
        </map:transform>
        <map:serialize type="html"/>
      </map:match>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/stream/uploadstring.xml
  
  Index: uploadstring.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
    Copyright 1999-2004 The Apache Software Foundation
  
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
  
        http://www.apache.org/licenses/LICENSE-2.0
  
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
  -->
  <page>
   <title>B2B processing</title>
    <content>
     <form action="process-order" id="FORM1" method="post" name="FORM1">
  	<para>Input your XML document here:</para>
  	<textarea cols="80" id="TEXTAREA1" name="Foo" rows="60">&lt;?xml version="1.0"?&gt;
  		&lt;Orders&gt;
  		&lt;OrderID&gt;20259&lt;/OrderID&gt;
  		&lt;CustomerID&gt;WWWWWWW&lt;/CustomerID&gt;
  		&lt;EmployeeID&gt;6&lt;/EmployeeID&gt;
  		&lt;OrderDate&gt;2001-05-05 00:00:00&lt;/OrderDate&gt;
  		&lt;RequiredDate&gt;2001-06-05 00:00:00&lt;/RequiredDate&gt;
  		&lt;ShippedDate&gt;2001-06-01 00:00:00&lt;/ShippedDate&gt;
  		&lt;ShipVia&gt;1&lt;/ShipVia&gt;
  		&lt;Freight&gt;11.6100&lt;/Freight&gt;
  		&lt;ShipName&gt;Thoms White&lt;/ShipName&gt;
  		&lt;ShipAddress&gt;Somestr. 48&lt;/ShipAddress&gt;
  		&lt;ShipCity&gt;Munster&lt;/ShipCity&gt;
  		&lt;ShipRegion&gt;West&lt;/ShipRegion&gt;
  		&lt;ShipPostalCode&gt;00000&lt;/ShipPostalCode&gt;
  		&lt;ShipCountry&gt;Germany&lt;/ShipCountry&gt;
  		&lt;OrderDetails&gt;
  			&lt;OrderID&gt;20259&lt;/OrderID&gt;
  			&lt;ProductID&gt;51&lt;/ProductID&gt;
  			&lt;UnitPrice&gt;42.4000&lt;/UnitPrice&gt;
  			&lt;Quantity&gt;40&lt;/Quantity&gt;
  			&lt;Discount&gt;0.0&lt;/Discount&gt;
  		&lt;/OrderDetails&gt;
  		&lt;OrderDetails&gt;
  				&lt;OrderID&gt;20259&lt;/OrderID&gt;
  				&lt;ProductID&gt;14&lt;/ProductID&gt;
  				&lt;UnitPrice&gt;18.6000&lt;/UnitPrice&gt;
  				&lt;Quantity&gt;9&lt;/Quantity&gt;
  				&lt;Discount&gt;0.0&lt;/Discount&gt;
  		&lt;/OrderDetails&gt;
  		&lt;OrderDetails&gt;
  				&lt;OrderID&gt;20259&lt;/OrderID&gt;
  				&lt;ProductID&gt;7&lt;/ProductID&gt;
  				&lt;UnitPrice&gt;12.4000&lt;/UnitPrice&gt;
  				&lt;Quantity&gt;30&lt;/Quantity&gt;
  				&lt;Discount&gt;0.0&lt;/Discount&gt;
  		&lt;/OrderDetails&gt;
  		&lt;Customers&gt;
  			&lt;CustomerID&gt;WWWWWWW&lt;/CustomerID&gt;
  			&lt;CompanyName&gt;Thomas White&lt;/CompanyName&gt;
  			&lt;ContactName&gt;Karin Black&lt;/ContactName&gt;
  			&lt;ContactTitle&gt;Marketing Manager&lt;/ContactTitle&gt;
  			&lt;Address&gt;Somestr. 48&lt;/Address&gt;
  			&lt;City&gt;Munster&lt;/City&gt;
  			&lt;Region&gt;West&lt;/Region&gt;
  			&lt;PostalCode&gt;00000&lt;/PostalCode&gt;
  			&lt;Country&gt;Germany&lt;/Country&gt;
  			&lt;Phone&gt;xxxx-yyyyyy&lt;/Phone&gt;
  			&lt;Fax&gt;xxxx-yyyyyy&lt;/Fax&gt;
  		&lt;/Customers&gt;
  	&lt;/Orders&gt;
  	</textarea>
  	<input id="submit1" name="submit1" type="submit" value="Submit"/>
    </form>
   </content>
  </page>
  
  
  
  1.1                  cocoon-2.1/src/webapp/samples/stream/uploadfile.xml
  
  Index: uploadfile.xml
  ===================================================================
  <?xml version="1.0"?>
  <!--
    Copyright 1999-2004 The Apache Software Foundation
  
    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
  
        http://www.apache.org/licenses/LICENSE-2.0
  
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
  -->
  <page>
   <title>B2B processing</title>
    <content>
    <form action="process-order" id="FORM1" method="post" name="FORM1"
          enctype="multipart/form-data">
  	<para>Upload your XML document here:</para>
  	<input type="file" name="Foo"/>
  	<input id="submit1" name="submit1" type="submit" value="Submit"/>
    </form>
   </content>
  </page>
  
  
  
  1.261     +4 -1      cocoon-2.1/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/status.xml,v
  retrieving revision 1.260
  retrieving revision 1.261
  diff -u -r1.260 -r1.261
  --- status.xml	6 Mar 2004 05:13:54 -0000	1.260
  +++ status.xml	6 Mar 2004 14:05:04 -0000	1.261
  @@ -196,6 +196,9 @@
     <changes>
   
    <release version="@version@" date="@date@">
  +   <action dev="JH" type="fix" fixes-bug="25594" due-to="Gernot Koller" due-to-email="grizzly@gmx.at">
  +     Allow streaming of uploaded files into a pipeline using StreamGenerator.
  +   </action>
      <action dev="JH" type="fix" fixes-bug="25483" due-to="Rui Alberto L. Gonçalves" due-to-email="rui-l-goncalves@ptinovacao.pt">
        Avoid accumulating of addresses and attachements in SendMailTransformer,
        when sending multiple mails, i.e. multiple sendmail elements at once.
  
  
  
  1.3       +6 -3      cocoon-2.1/src/webapp/samples/components-samples.xml
  
  Index: components-samples.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/components-samples.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- components-samples.xml	6 Mar 2004 02:25:40 -0000	1.2
  +++ components-samples.xml	6 Mar 2004 14:05:04 -0000	1.3
  @@ -26,8 +26,11 @@
     </group>
   
     <group name="Generators">
  -    <sample href="stream/order" name="B2B: Order Page" xlink:role="dynamic">
  -      An example of B2B processing using StreamGenerator.
  +    <sample href="stream/uploadstring" name="Stream parameter value" xlink:role="dynamic">
  +      An example getting a parameter value streamed into a pipeline using StreamGenerator.
  +    </sample>   
  +    <sample href="stream/uploadfile" name="Stream upload file" xlink:role="dynamic">
  +      An example getting an uploaded file streamed into a pipeline using StreamGenerator.
       </sample>   
       <sample href="request.html" name="Request Page">
         This example shows the usage of the RequestGenerator.
  
  
  
  1.8       +19 -5     cocoon-2.1/src/java/org/apache/cocoon/generation/StreamGenerator.java
  
  Index: StreamGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/StreamGenerator.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- StreamGenerator.java	5 Mar 2004 13:02:55 -0000	1.7
  +++ StreamGenerator.java	6 Mar 2004 14:05:04 -0000	1.8
  @@ -20,6 +20,7 @@
   import org.apache.cocoon.environment.ObjectModelHelper;
   import org.apache.cocoon.environment.Request;
   import org.apache.cocoon.environment.http.HttpEnvironment;
  +import org.apache.cocoon.servlet.multipart.Part;
   import org.apache.cocoon.util.PostInputStream;
   import org.apache.excalibur.xml.sax.SAXParser;
   import org.xml.sax.InputSource;
  @@ -28,6 +29,8 @@
   import javax.servlet.http.HttpServletRequest;
   
   import java.io.IOException;
  +import java.io.InputStreamReader;
  +import java.io.Reader;
   import java.io.StringReader;
   
   /**
  @@ -92,8 +95,8 @@
               }
               if (contentType == null) {
                   throw new IOException("both Content-Type header and defaultContentType parameter are not set");
  -            } else if (contentType.startsWith("application/x-www-form-urlencoded") ||
  -                    contentType.startsWith("multipart/form-data")) {
  +            } else if (contentType.startsWith("application/x-www-form-urlencoded")
  +                       || contentType.startsWith("multipart/form-data")) {
                   String parameter = parameters.getParameter(FORM_NAME, null);
                   if (parameter == null) {
                       throw new ProcessingException(
  @@ -101,8 +104,19 @@
                           FORM_NAME + "' for handling form data"
                       );
                   }
  -                String sXml = request.getParameter(parameter);
  -                inputSource = new InputSource(new StringReader(sXml));
  +                Object xmlObject = request.get(parameter);
  +                Reader xmlReader = null;
  +                if (xmlObject instanceof String){
  +                  xmlReader  = new StringReader((String)xmlObject);
  +                }
  +                else if (xmlObject instanceof Part){
  +                  xmlReader = new InputStreamReader(((Part)xmlObject).getInputStream());
  +                }
  +                else{
  +                  throw new ProcessingException("Unknown request object encountred named " + 
  +                parameter + " : " + xmlObject);
  +                }
  +                inputSource = new InputSource(xmlReader);
               } else if (contentType.startsWith("text/plain") ||
                       contentType.startsWith("text/xml") ||
                       contentType.startsWith("application/xml")) {