Hello, everybody,

I do not understand the XSP upload example. Yes, it works fine, but I would
like to understand as much as possible. I guess their is some "magic" behind
the scene.

I did some reading of the API Javadoc, but I'am still not experienced enough
reading source code. What to do? Should I give up learning Cocoon :-(


The example XSP-Source follows. I added comments about what I don't
understand.


<?xml version="1.0" encoding="ISO-8859-1"?>

<!-- CVS: $Id: upload.xsp,v 1.3 2002/02/09 06:21:57 vgritsenko Exp $ -->


<!--
QUESTION: the namespace declarations for request, response and log are
not used and could be omitted? Is this correct?
-->

<xsp:page language="java"
          xmlns:xsp="http://apache.org/xsp";
          xmlns:xsp-request="http://apache.org/xsp/request/2.0";
          xmlns:xsp-response="http://apache.org/xsp/response/2.0";
          xmlns:log="http://apache.org/xsp/log/2.0";>

  <xsp:structure>
<!--
QUESTION: Same with the XSPUtil import. Am I right?
-->

<xsp:include>org.apache.cocoon.components.language.markup.xsp.XSPUtil</xsp:i
nclude>

<xsp:include>org.apache.avalon.framework.context.ContextException</xsp:inclu
de>
  </xsp:structure>

<!--
QUESTIONS: I do not understand this part. Who calls conceptualize?
   Where does context
(org.apache.cocoon.generation.ServletGenerator.context?)
   come from? And the get method of context? Their must be some "build in"
upload
   functionality, please explain if You are patient enough.
-->
  <xsp:logic>
  File uploadDir = null;
  /** Contextualize this class */
  public void contextualize(Context context) throws ContextException {
    uploadDir = (File) context.get(Constants.CONTEXT_UPLOAD_DIR);
  }
  </xsp:logic>

  <page>
   <title>This form allows you upload files</title>
   <content>
     <para>
       <form method="post" enctype="multipart/form-data"
action="upload.xsp">
         File:  <input type="file" name="uploaded_file" size="50" />
     <p><input type="submit" value="Upload File" /></p>
       </form>
     </para>
     <para>
     <ul>
       <xsp:logic>
        getLogger().debug("Dir=" + uploadDir);
         String[] filelist = uploadDir.list();
         <![CDATA[
         getLogger().debug("List=" + filelist.length);
         for (int i = 0; i < filelist.length; i++) {
            getLogger().debug("File [" + i + "]=" + filelist[i]);
         ]]>
           <li>
             <xsp:expr>filelist[i]</xsp:expr>
           </li>
         <![CDATA[
         }
         ]]>
       </xsp:logic>
     </ul>
     </para>
     <para>Brought to you by Cocoon at <xsp:expr>new
Date()</xsp:expr>.</para>

   </content>
  </page>
</xsp:page>


Thank You.

Regards
Stefan
--

Stefan Riegel


---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <[EMAIL PROTECTED]>
For additional commands, e-mail:   <[EMAIL PROTECTED]>

Reply via email to