home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / file-upload-blob.xsp < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  5.3 KB  |  145 lines

  1. <?xml version="1.0"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17.  
  18. <xsp:page language="java"
  19.     xmlns:xsp="http://apache.org/xsp"
  20.       xmlns:esql="http://apache.org/cocoon/SQL/v2"
  21.     xmlns:xsp-request="http://apache.org/xsp/request/2.0"
  22.   >
  23.   <!-- Need this import for dumping the request parameters -->
  24.   <xsp:structure>
  25.     <xsp:include>java.util.Enumeration</xsp:include>
  26.   </xsp:structure>
  27.   
  28.   <page>
  29.     <resources>
  30.        <resource type="file" href="database.xml?cocoon-view=pretty-content">Descriptor</resource>
  31.        <resource type="file" href="schema.sql">Schema</resource>
  32.        <resource type="doc" href="userdocs/actions/database-actions.html">Actions</resource>
  33.        <resource type="doc" href="userdocs/xsp/esql.html">ESQL</resource>
  34.     </resources>
  35.  
  36.     <title>file-upload-blob</title>
  37.  
  38.    <!-- create image tags out of the images stored in the database, the browser will subsequently
  39.         request those images and they will be served by a special pipeline in the sitemap using 
  40.         the database reader component
  41.    -->    
  42.    <esql:connection>
  43.       <esql:pool>personnel</esql:pool>
  44.     
  45.       <esql:execute-query>
  46.              <esql:query>select media.id from media</esql:query>
  47.              <esql:results>
  48.                <esql:row-results>
  49.                  <img><xsp:attribute name="src">image/<esql:get-string column="id"/></xsp:attribute>
  50.                  </img>
  51.                </esql:row-results>
  52.              </esql:results>
  53.              <esql:no-results>no images yet</esql:no-results>
  54.       </esql:execute-query>
  55.     </esql:connection>
  56.      
  57.  
  58.       <h1>Upload Media</h1>
  59.       <p>What's happening?  This example interacts with a simple database schema, set up by 
  60.       default in the sample "personnel" hsql database installed with the database block.  There 
  61.       is one table "media" with two fields: a primary key, and a binary field "image".  
  62.       When a file upload is received from the simple form on this page, the modular db action 
  63.       auto increments the primary key, and loads the binary file contents into the column (declared
  64.       as type="binary" in database.xml).  That's it.</p>
  65.       <p>Additionally, when this page is loaded, esql queries the media table and places an image tag 
  66.       for each row, using "primarykeyvalue".jpg for the src.  The sitemap is configured to serve 
  67.       *.jpg using the database reader (declared in the root database samples sitemap) which simply
  68.       retrieves the binary data from the database and streams it to the browser.</p>
  69.  
  70.       <p>The default installation of Apache Cocoon does not allow
  71.       uploads. This feature needs to be enabled in web.xml</p>
  72.  
  73.  
  74.       <table cellpadding="2" cellspacing="2" border="0">
  75.         <tbody>
  76.           <form method="POST" enctype="multipart/form-data">
  77.             <tr>
  78.               <td valign="Top" align="Right">File (must be an image)</td>
  79.               <td valign="Top">
  80.                 <input type="file" name="media.image"/>
  81.               </td>
  82.             <td>
  83.               <input type="submit" name="add-image" value="add image"/>
  84.             </td>
  85.           </tr>
  86.         </form>
  87.         </tbody>
  88.         </table>
  89.  
  90.  
  91.  
  92.     <!-- the following is absolutely irrelevant for the example. It only serves to show what happens
  93.          during the processing e.g. what parameters were sent to the server and what request attributes
  94.          were set by the database actions. You might find such information valuable when debugging your
  95.          own applications :-) -->
  96.     <hr/>
  97.  
  98.     <p><h3>Request Attributes</h3></p>
  99.     <p>
  100.       <table border="0">
  101.         <tbody>
  102.           <xsp:logic>{
  103.              Enumeration e=request.getAttributeNames();
  104.              while ( e.hasMoreElements() ) {
  105.                  String attribute = (String) e.nextElement();
  106.                  Object value = request.getAttribute(attribute);
  107.                  <tr>
  108.                    <td align="right"><xsp:expr>attribute</xsp:expr></td>
  109.                    <td>="<xsp:expr>value</xsp:expr>"</td>
  110.                  </tr>
  111.              }
  112.           }</xsp:logic>
  113.         </tbody>
  114.       </table>
  115.     </p>
  116.  
  117.     <hr/>
  118.  
  119.     <p><h3>Request Parameters</h3></p>
  120.     <p>
  121.       <table border="0">
  122.         <tbody>
  123.           <xsp:logic>{
  124.                Enumeration e=request.getParameterNames();
  125.                while ( e.hasMoreElements() ) {
  126.                    String attribute = (String) e.nextElement();
  127.                    Object[] value = request.getParameterValues(attribute);
  128.                    for (int i=0; i < value.length; i++) {
  129.                       <tr>
  130.                         <td align="right"><xsp:expr>attribute</xsp:expr>[<xsp:expr>i</xsp:expr>]</td>
  131.                         <td>="<xsp:expr>value[i]</xsp:expr>"</td>
  132.                       </tr>
  133.                    }
  134.                }
  135.           }</xsp:logic>
  136.         </tbody>
  137.       </table>
  138.     </p>
  139.  
  140.     <hr/>
  141.  
  142.   </page>
  143.  
  144. </xsp:page>
  145.