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 / upload.xsp < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  3.8 KB  |  105 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. <!-- CVS $Id: upload.xsp,v 1.2 2004/04/05 12:25:30 antonio Exp $ -->
  19.  
  20. <xsp:page language="java"
  21.           xmlns:xsp="http://apache.org/xsp"
  22.           xmlns:xsp-request="http://apache.org/xsp/request/2.0"
  23.           xmlns:xsp-response="http://apache.org/xsp/response/2.0"
  24.           xmlns:log="http://apache.org/xsp/log/2.0">
  25.  
  26.   <xsp:structure>
  27.    <xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:include>
  28.    <xsp:include>org.apache.avalon.framework.context.ContextException</xsp:include>
  29.   </xsp:structure>
  30.  
  31.   <xsp:logic>
  32.   File uploadDir = null;
  33.   /** Contextualize this class */
  34.   public void contextualize(Context context) throws ContextException {
  35.     uploadDir = (File) context.get(Constants.CONTEXT_UPLOAD_DIR);
  36.   }
  37.   </xsp:logic>
  38.  
  39.   <page>
  40.    <title>This form allows you upload files</title>
  41.    <content>
  42.         <para>Uploads in cocoon are handled automatically, as configured in web.xml.  
  43.         The relevant init-params controlling upload behavior are: enable-uploads, 
  44.         upload-directory, autosave-uploads, overwrite-uploads, upload-max-size.
  45.         </para>
  46.      <para>All files are cleaned out of the upload directory at the end of the 
  47.      request.  The assumption is that other application logic will have acted on 
  48.      the files during the request.</para>
  49.      <para>
  50.        <form method="post" enctype="multipart/form-data" action="upload">
  51.          File:  <input type="file" name="uploaded_file" size="50" />
  52.          <p>
  53.            <input type="submit" value="Upload File" />
  54.          </p>
  55.        </form>
  56.      </para>
  57.      <para>
  58.        <xsp:logic>
  59.          if (<xsp-request:get-parameter name="uploaded_file"/> != null) {
  60.            <xsp:content>
  61.              Parameter uploaded_file:
  62.              <strong>
  63.                <xsp-request:get-parameter name="uploaded_file"/>
  64.              </strong>
  65.              <br/>
  66.  
  67.              Parameter uploaded_file is instance of:
  68.              <!-- note usage of get() instead of getParameter() -->
  69.              <strong>
  70.                <xsp:expr>
  71.                  request.get("uploaded_file").getClass()
  72.                </xsp:expr>
  73.              </strong>
  74.              <br/>
  75.            </xsp:content>
  76.          } else if (request.getContentType()!=null && request.getContentType().indexOf("multipart/form-data") != -1) {
  77.              <para><strong>Either uploads are turned off, or you submitted a blank form.</strong></para>
  78.              <para>To enable uploads, ensure that the value for the init-param "enable-uploads" in web.xml is set to true.</para>
  79.          }
  80.        </xsp:logic>
  81.  
  82.        Upload directory content:
  83.        <ul>
  84.          <xsp:logic>
  85.           getLogger().debug("Dir=" + uploadDir);
  86.            String[] filelist = uploadDir.list();
  87.            <![CDATA[
  88.            getLogger().debug("List=" + filelist.length);
  89.            for (int i = 0; i < filelist.length; i++) {
  90.               getLogger().debug("File [" + i + "]=" + filelist[i]);
  91.            ]]>
  92.              <li>
  93.                <xsp:expr>filelist[i]</xsp:expr>
  94.              </li>
  95.            <![CDATA[
  96.            }
  97.            ]]>
  98.          </xsp:logic>
  99.        </ul>
  100.      </para>
  101.      <para>Brought to you by Cocoon at <xsp:expr>new Date()</xsp:expr>.</para>
  102.    </content>
  103.   </page>
  104. </xsp:page>
  105.