cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject cvs commit: cocoon-2.2/src/java/org/apache/cocoon/generation StreamGenerator.java
Date Sat, 06 Mar 2004 14:34:40 GMT
joerg       2004/03/06 06:34:40

  Modified:    src/webapp/samples components-samples.xml
               src/webapp/samples/stream sitemap.xmap
               .        status.xml
               src/java/org/apache/cocoon/generation StreamGenerator.java
  Added:       src/webapp/samples/stream uploadfile.xml uploadstring.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.2       +6 -3      cocoon-2.2/src/webapp/samples/components-samples.xml
  
  Index: components-samples.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/webapp/samples/components-samples.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- components-samples.xml	7 Sep 2003 06:16:41 -0000	1.1
  +++ components-samples.xml	6 Mar 2004 14:34:40 -0000	1.2
  @@ -11,8 +11,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.5       +4 -4      cocoon-2.2/src/webapp/samples/stream/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/webapp/samples/stream/sitemap.xmap,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- sitemap.xmap	29 Jul 2003 03:15:48 -0000	1.4
  +++ sitemap.xmap	6 Mar 2004 14:34:40 -0000	1.5
  @@ -29,14 +29,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.2/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.1                  cocoon-2.2/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.185     +4 -1      cocoon-2.2/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/status.xml,v
  retrieving revision 1.184
  retrieving revision 1.185
  diff -u -r1.184 -r1.185
  --- status.xml	5 Mar 2004 02:24:35 -0000	1.184
  +++ status.xml	6 Mar 2004 14:34:40 -0000	1.185
  @@ -189,6 +189,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="27254" due-to="Georg Ragaller" due-to-email="georg.ragaller@nse.de">
        Fixed path separator handling in cocoon.bat/.sh and Loader.java.
      </action>
  
  
  
  1.10      +20 -7     cocoon-2.2/src/java/org/apache/cocoon/generation/StreamGenerator.java
  
  Index: StreamGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.2/src/java/org/apache/cocoon/generation/StreamGenerator.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- StreamGenerator.java	30 Dec 2003 11:25:45 -0000	1.9
  +++ StreamGenerator.java	6 Mar 2004 14:34:40 -0000	1.10
  @@ -51,6 +51,8 @@
   package org.apache.cocoon.generation;
   
   import java.io.IOException;
  +import java.io.InputStreamReader;
  +import java.io.Reader;
   import java.io.StringReader;
   
   import javax.servlet.http.HttpServletRequest;
  @@ -60,6 +62,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;
  @@ -127,12 +130,13 @@
               if (contentType == null) {
                   contentType = parameters.getParameter("defaultContentType", null);
                   if (getLogger().isDebugEnabled()) {
  -                    getLogger().debug("no Content-Type header - using contentType parameter");
  +                    getLogger().debug("no Content-Type header - using contentType parameter:
" + contentType);
  +                }
  +                if (contentType == null) {
  +                    throw new IOException("both Content-Type header and defaultContentType
parameter are not set");
                   }
               }
  -            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") ||
  +            if (contentType.startsWith("application/x-www-form-urlencoded") ||
                       contentType.startsWith("multipart/form-data")) {
                   String parameter = parameters.getParameter(FORM_NAME, null);
                   if (parameter == null) {
  @@ -141,8 +145,17 @@
                           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 encountered named
" + 
  +                                                  parameter + " : " + xmlObject);
  +                }                
  +                inputSource = new InputSource(xmlReader);
               } else if (contentType.startsWith("text/plain") ||
                       contentType.startsWith("text/xml") ||
                       contentType.startsWith("application/xml")) {
  
  
  

Mime
View raw message