On Thu, Sep 11, 2003 at 11:09:41PM -0400, Geoff Howard wrote:
> >2.  It also says you can "Alternatively . . . write the following
> >Java code in your sitemap components."  What does it mean to write
> >Java code "in the sitemap components."  Does that mean use it as an
> >Action?  
> 
> Yes, but not limited to Actions.  You can use that section to modify the 
> portions of the upload action wiki page and be up and running sooner.
> 
> > I tried to do that and couldn't get it to work, but the
> >language here makes me think I'm supposed to do something different.
> >I'd actually rather do this without javascript, but at this point,
> >I'll settle for anything that works.
> 
> Let us know exactly what you tried, and what went wrong.

Okay, so let me pose the following scenario.  I'd like to do a file
upload using a simple action (i.e. without using flows).  Here's
some simple HTML for the upload

<html>
  <body>
      <form action="upload" method="post" enctype="multipart/form-data">
           File:  <input type="file" name="uploadfile" size="50">
          <input type="submit"/>
          </form>
        </body>
</html>

The wiki gives an example action, but it doesn't work because the
API has changed for Cocoon 2.1.  So let's try this:

package edu.uga.english.cantor;

// Lots of imports  . . .

public class SGUpload
  extends AbstractLogEnabled
      implements Action, ThreadSafe {

              public Map act(Redirector redirector, SourceResolver resolver,
                        Map objectModel, String source, Parameters par)
                                throws Exception {

                        Request request = ObjectModelHelper.getRequest(objectModel);

                        PartOnDisk filePart = (PartOnDisk) request.get("uploadfile");

                        if (filePart != null) {

                                getLogger().debug("Uploaded file = " +
                                filePart.getFileName());

                        } else {

                                getLogger().debug("File not found");

                        }

                return null;

        }

}

That compiles without incident, and I drop it (and its package tree)
into WEB-INF/classes.  I need to add a line to the components
section that tells Cocoon where it is, so I put:

<map:actions>
    <map:action name="sg-upload" src="edu.uga.english.cantor.SGFlow"/>
</map:actions>

I think I'm stuck trying to figure out what to put in the pipeline
(the examples online and in the book I'm using aren't exactly on
point).  I realize that I can trap on <map:match pattern="upload">,
trigger the action with <map:act type="sg-upload">, and then do
whatever (presumably something as simple as "<map:read
src="static/success.html" mime-type="text/html"/>), but all I get is
404s and NullPointerExceptions.  

What's the dumbest thing that can work in this situation?

Oh, and here's a possibly dumb question: Where is this getting
logged?  I understand that AbstractLogEnabled is an avalon facade
for whatever logging system is in use, but I don't know where my
calls to debug() are getting written (and in any event, they're not
being written to any file in my tomcat tree).

I'm definitely a beginner with Cocoon (though not with Java and
XML).  I have a complete site running on Cocoon that uses lots of
conditional logic and whatnot, but I haven't tried to do anything
fancy with it yet.  I'd really like to do all my computational logic
without XSP, so if anyone knows of a lucid explanation of Actions,
I'd be much obliged.  

Thanks,

Steve

-- 
Stephen Ramsay
Assistant Professor
Department of English
University of Georgia
email: [EMAIL PROTECTED]
web: http://cantor.english.uga.edu/
PGP Public Key ID: 0xA38D7B11

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

Reply via email to