You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Stephen Ramsay <sr...@uga.edu> on 2003/09/12 02:14:52 UTC

File upload with flow (Wiki examples)

I've spent the last couple of weeks beating my head against the wall
trying to get file uploading to work in Cocoon 2.1.  I've read the
"File Uploads with Flow" howto on the Wiki (as well as the other
upload howtos, the docs, the update guide, and the list archives),
but I'm still confused about a few points.  Any help would be greatly
appreciated.

1.  The javascript example sets the following variable

var role = Packages.org.mystuff.UploadManager.ROLE;

and then passes it in like so:

var uploader = cocoon.componentManager.getComponent(role);

What is the ROLE attribute and how (or where) do I call it?  I
gather that I need to call some class that implements some kind of
component interface, but I can't figure out which one.

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?  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.

3.  The Wiki howto shows you to how call a flow script from the
sitemap (and the Cocoon docs show you how to set up the scripting
environment for flows, and so forth), but I'm not sure what I'm
supposed to do in the sitemap if I want to do a file upload with an
action.  Most of the explanations out there seem deprecated.

I'm sorry if these questions seem really dense.   

Thanks,

Steve

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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Stephen Ramsay <sr...@uga.edu>.
On Sun, Sep 14, 2003 at 02:40:54PM -0400, Stephen Ramsay wrote:
> On Sun, Sep 14, 2003 at 08:33:01AM -0400, Geoff Howard wrote:
> > Aha!  That wiki example has a problem I just noticed -- you shouldn't 
> > return null here (I just corrected the wiki).  Use the corrected version 
> > above - I'll explain below.
> 
> Thanks again, Greg.

Geoff, that is :)

Steve

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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Stephen Ramsay <sr...@uga.edu>.
On Sun, Sep 14, 2003 at 10:21:35PM -0400, Stephen Ramsay wrote:
> (it resides in
> cocoon/WEB-INF/classes/edu/uga/cantor/english/SGUpload.java)

Sorry, I meant "edu/uga/english/cantor"  I think it's getting to the
action successfully, in any event (which is a start!)

Steve

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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Geoff Howard <co...@leverageweb.com>.
Geoff Howard wrote:

> I just finally got a second to look at the code, and my vague memory was 
> right.  During a security related refactoring of the upload code before 
> 2.1M1 (U2/MLK  fans may be interested to know it was early morning, 
> April 4 by complete coincidence) an unconfigurable (means it can't be 
> turned off) step was added to the CocoonServlet at the end of the 
> request processing which automatically removes the temporary files saved 
> during the upload process when autosave-uploads is set to true.  Until 
> that point, it was possible to set the upload directory to the final 
> desired location of the uploads.  By design, this is no longer possible. 
>  Either from flow script or an Action, the application programmer must 
> move the file if they desire it to persist past the end of the request.
> 
> I've just now added a brief debugging statement to the servlet 
> mentioning the multipart cleanup.
> 

And now I've started some improvements at the wiki:
http://wiki.cocoondev.org/Wiki.jsp?page=FileUploadsWithCocoon2.1

Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Geoff Howard <co...@leverageweb.com>.
Geoff Howard wrote:

> Stephen Ramsay wrote:
> 
>> On Sun, Sep 14, 2003 at 10:01:05PM -0400, Geoff Howard wrote:
>>
>>> Stephen Ramsay wrote:
>>>
>>>> On Sun, Sep 14, 2003 at 08:33:01AM -0400, Geoff Howard wrote:
>>>>
>>>>> Aha!  That wiki example has a problem I just noticed -- you 
>>>>> shouldn't return null here (I just corrected the wiki).  Use the 
>>>>> corrected version above - I'll explain below.
>>
>> Well, Geoff, I just can't get it to work.  I'm no longer getting
>> 404s, but it's still not uploading the file.
> 
> How do you know?  By default, the servlet cleans up the file at the end 
> of the request (I think -- it didn't used to be this way, but I think 
> this was done when this was refactored to address some security 
> concerns).  So, unless you are reading your debug statements (which it 
> seems you're not getting) you wouldn't know.

I just finally got a second to look at the code, and my vague memory was 
right.  During a security related refactoring of the upload code before 
2.1M1 (U2/MLK  fans may be interested to know it was early morning, 
April 4 by complete coincidence) an unconfigurable (means it can't be 
turned off) step was added to the CocoonServlet at the end of the 
request processing which automatically removes the temporary files saved 
during the upload process when autosave-uploads is set to true.  Until 
that point, it was possible to set the upload directory to the final 
desired location of the uploads.  By design, this is no longer possible. 
  Either from flow script or an Action, the application programmer must 
move the file if they desire it to persist past the end of the request.

I've just now added a brief debugging statement to the servlet 
mentioning the multipart cleanup.

HTH,
Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Geoff Howard <co...@leverageweb.com>.
Stephen Ramsay wrote:
> On Sun, Sep 14, 2003 at 10:01:05PM -0400, Geoff Howard wrote:
> 
>>Stephen Ramsay wrote:
>>
>>>On Sun, Sep 14, 2003 at 08:33:01AM -0400, Geoff Howard wrote:
>>>
>>>>Aha!  That wiki example has a problem I just noticed -- you shouldn't 
>>>>return null here (I just corrected the wiki).  Use the corrected version 
>>>>above - I'll explain below.
> 
> Well, Geoff, I just can't get it to work.  I'm no longer getting
> 404s, but it's still not uploading the file.

How do you know?  By default, the servlet cleans up the file at the end 
of the request (I think -- it didn't used to be this way, but I think 
this was done when this was refactored to address some security 
concerns).  So, unless you are reading your debug statements (which it 
seems you're not getting) you wouldn't know.

> If you can stand it any longer, here's the rundown on what I've got.
> 
> First, the necessary switches have been turned on in web.xml:
> upload-enabled is true, and the upload directory has been created (and enabled) with write permission for all.

What is autosave-uploads set to?  I'm assuming it's true, or you'd be 
getting a class cast exception.

...

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

This is the reason I'm asking.  The way this is written, it is hardcoded 
to assume PartOnDisk, which is only going to be the case when 
autosave-uploads is true.  When false, you will get a PartInMemory. 
It'd be better there to cast to Part and rely on polymorphism or to 
check which you have first if you want to get a java.io.File when 
available from PartOnDisk.

> 				getLogger().debug("Uploaded file = " + filePart.getFileName());
> 
> 			} else {
> 
> 				getLogger().debug("File not found");

...

> I'm making some kind of progress; when I hit upload it fires off the
> success page.  However, there's still no file, and more crucially,
> no log.

As I mentioned before, you need to check what log level is set in 
logkit.xconf for the sitemap target - it's probably ignoring DEBUG by 
default.

> I'm probably going to hack away at it for another session or so
> (using some ideas from the code you sent), but it's really not
> looking good . . .

Trust me, file uploads work all the time.  I am using them regularly in 
a live deployed project.

...

> One last thing, though.  I am runnning tomcat (on Linux) using the
> mod_jk module for Apache.  Would this make any difference?  I can't
> think of why it would (mod_jk is a pretty straightforward pass-it-on
> type thing, and it works fine for the rest of my cocoon stuff), but
> I thought I'd mention it . . .

No, don't think this has any relation.  For the record, the project I 
just mentioned is using mod_jk.

Geoff



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Stephen Ramsay <sr...@uga.edu>.
On Sun, Sep 14, 2003 at 10:01:05PM -0400, Geoff Howard wrote:
> Stephen Ramsay wrote:
> >On Sun, Sep 14, 2003 at 08:33:01AM -0400, Geoff Howard wrote:
> >
> >>Aha!  That wiki example has a problem I just noticed -- you shouldn't 
> >>return null here (I just corrected the wiki).  Use the corrected version 
> >>above - I'll explain below.

Well, Geoff, I just can't get it to work.  I'm no longer getting
404s, but it's still not uploading the file.

If you can stand it any longer, here's the rundown on what I've got.

First, the necessary switches have been turned on in web.xml:
upload-enabled is true, and the upload directory has been created (and enabled) with write permission for all.

The HTML file looks like this:

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Start Page</title>
</head>

<body bgcolor="white">
	<p>
	<form action="upload" method="POST" enctype="multipart/form-data">
		File: <input type="file" name="uploadfile" size="50"/><br/><br/>
		<input type="submit" name="action" value="Upload"/>
	</form>
  </p>
</body>
</html>

The action looks like this:

package edu.uga.english.cantor;

import java.io.File;
import java.io.FileInputStream;

import java.util.Map;

import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.servlet.multipart.Part;
import org.apache.cocoon.servlet.multipart.PartOnDisk;

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);

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

			if (filePart != null) {
		
				getLogger().debug("Uploaded file = " + filePart.getFileName());

			} else {

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

			}

		return java.util.Collections.EMPTY_MAP;

	}	

}

(it resides in
cocoon/WEB-INF/classes/edu/uga/cantor/english/SGUpload.java)

And, finally, the sitemap contains these two directives:

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

And:

<map:match pattern="upload">
	<map:act type="sg-upload">
		<map:read src="static/success.html" mime-type="text/html"/>
	</map:act>
</map:match>

I'm making some kind of progress; when I hit upload it fires off the
success page.  However, there's still no file, and more crucially,
no log.

I'm probably going to hack away at it for another session or so
(using some ideas from the code you sent), but it's really not
looking good . . .

You've already gone way above and beyond the bounds of hackerly
helpfulness, but if you get a chance to draw your eye over the
above, I'd be much obliged.

One last thing, though.  I am runnning tomcat (on Linux) using the
mod_jk module for Apache.  Would this make any difference?  I can't
think of why it would (mod_jk is a pretty straightforward pass-it-on
type thing, and it works fine for the rest of my cocoon stuff), but
I thought I'd mention it . . .

Steve

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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Geoff Howard <co...@leverageweb.com>.
Stephen Ramsay wrote:
> On Sun, Sep 14, 2003 at 08:33:01AM -0400, Geoff Howard wrote:
> 
>>Aha!  That wiki example has a problem I just noticed -- you shouldn't 
>>return null here (I just corrected the wiki).  Use the corrected version 
>>above - I'll explain below.

...

> I'm not sure "return new Map()" will work in the revised Wiki
> example.  Map is just an interface, so you can't actually return an
> instantiated object.

DOH!  Sorry, typing between commercials of the football game.  I was 
undecided between two alternatives and took halfway between.  Use this:

return java.util.Collections.EMPTY_MAP;

> On the other hand, I'm not sure if returning some random object
> (say, HashMap) is going to work.  I'm going to give it a try,
> though, and see what happens.

Yes, that would work too.  Well, not a random object but any instanceof 
Map obviously.  As long as it's not null.

> If I get this going, I'll try to put together an wikified example
> that uses the Cocoon 2.1 API.

That'd be great.  Actually, I have had a written but not tested version 
of a MultiPartFileAction on my hard drive for months which was meant to 
be committed into CVS but I haven't had the time or interest to finish 
up.  If you're motivated to test it etc., it's attached.  I was just 
finishing converting an original which merely saved to disk to now use 
ModifiableSource which would provide automatic support for other Source 
implementations, such as webdav repositories, cvs, etc. as they become 
available.

Geoff

Re: File upload with flow (Wiki examples)

Posted by Stephen Ramsay <sr...@uga.edu>.
On Sun, Sep 14, 2003 at 08:33:01AM -0400, Geoff Howard wrote:
> Aha!  That wiki example has a problem I just noticed -- you shouldn't 
> return null here (I just corrected the wiki).  Use the corrected version 
> above - I'll explain below.

Thanks again, Greg.

I'm not sure "return new Map()" will work in the revised Wiki
example.  Map is just an interface, so you can't actually return an
instantiated object.

On the other hand, I'm not sure if returning some random object
(say, HashMap) is going to work.  I'm going to give it a try,
though, and see what happens.

If I get this going, I'll try to put together an wikified example
that uses the Cocoon 2.1 API.

Steve

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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Geoff Howard <co...@leverageweb.com>.
Stephen Ramsay wrote:

> 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>

Ok...

> 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());

				return new Map();

> 			} else {
> 
> 				getLogger().debug("File not found");

				return null;

> 			}
> 

  		//return null;

> 	}
> 
> }

Aha!  That wiki example has a problem I just noticed -- you shouldn't 
return null here (I just corrected the wiki).  Use the corrected version 
above - I'll explain below.

As written your action (and the wiki example) always signals failure. 
This means that depending on how your pipeline is written you may be 
forcing a 404 because no complete pipeline is constructed.

> 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>

Right

> 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?

I think what you outline above is about as simple as it can get.  I'd
try:

<map:match pattern="upload">
   <map:act type="sg-upload">
     <map:read src="static/success.html" mime-type="text/html"/>
   </map:act> <!-- If act returns a map, processing stops here -->
   <map:read src="static/failure.html" mime-type="text/html"/>
</map:match>

> 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).

All cocoon logging goes to WEB-INF/logs/*.log (in this case, should be
sitemap.log)

Note though that there is a logging config in WEB-INF/logkit.xconf which 
sets the threshhold for different log topics.  By default, this may not 
be getting your debugs.  (to really simplify this during "pull your hair 
out" phase, you can always just use System.out.println() which will go 
to the console.  Be sure to either get rid of that or turn it into 
proper logging statements after you've moved into some more sanity.

> 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.  

I just looked again and could find no lucid explanation of Actions (and 
I can't remember where I read about them when I first started).  While 
simple, actions do have a dark side.  They can start to make a sitemap 
pretty convoluted as complexity grows.  Flow is seen as a much more 
advanced successor.  I believe that actions may always have their place 
for simple uses but I wouldn't build a whole application in 2.1+ without 
using flow.  I'd love to hear your thoughts in a separate thread after 
you've had a chance to take flow for a spin.

So, here's a starter at the basics of actions:

The basic contract:
1) Actions (like Matchers, and Selectors) are executed before pipeline 
setup, and so can affect which pipeline elements are executed.
2) Actions signal success or failure by returning a Map (success) or 
null (failure).
3) Sitemap elements nested inside <map:act></map:act> are only executed 
  if the action signals success.  Elements outside may or may not be
executed depending on whether a full pipeline (a reader, or up to a 
serializer) is found inside.
4) If desired, the map can be used to return values to the sitemap
which can be referenced by their key.

Example:
(action snippet)
   returnValue = new Map();
   returnValue.put("someKey","someValue");
   return returnValue;

(sitemap snippet)
   <map:act type="myAction">
     <map:generate src="{someKey}.xml"/> <!-- "someValue.xml" -->
         ...
   </map:act>
   <!-- {someKey} will not be defined here -->

Does that make things any clearer?  (Could someone wiki this?)

Now, you also need to check to make sure your web.xml settings for 
uploads are set to create a PartOnDisk (autosave-uploads -> true, 
allow-uploads -> true IIRC).

Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Stephen Ramsay <sr...@uga.edu>.
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: sramsay@uga.edu
web: http://cantor.english.uga.edu/
PGP Public Key ID: 0xA38D7B11

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Stephen Ramsay <sr...@uga.edu>.
On Thu, Sep 11, 2003 at 11:09:41PM -0400, Geoff Howard wrote:
> Yikes.  Hopefully most of this time is getting used to Cocoon internals,
> not just uploads.  They're quite easy really.  Unfortunately, the
> docs are as you've found still pretty poor.

Geoff,

Thanks for this wonderful post.  I'm going to try several of the
things you suggest, but I just wanted to drop a quick note to offer
my thanks.  I hope I'll eventually be able to return the favor (by,
perhaps, sending another football player your way).

I'm only passively familiar with the Avalon framework, but it seems
quite elegant and impressive.  I'm going to try to dive in a lot
deeper in the next few ways.

I really hope I can eventually get good enough at this system to
join in the development.  It's really a very smart piece.

Thanks,

Steve



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

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: File upload with flow (Wiki examples)

Posted by Geoff Howard <co...@leverageweb.com>.
Stephen Ramsay wrote:
> I've spent the last couple of weeks beating my head against the wall
> trying to get file uploading to work in Cocoon 2.1.  I've read the
> "File Uploads with Flow" howto on the Wiki (as well as the other
> upload howtos, the docs, the update guide, and the list archives),
> but I'm still confused about a few points.  Any help would be greatly
> appreciated.

Yikes.  Hopefully most of this time is getting used to Cocoon internals,
not just uploads.  They're quite easy really.  Unfortunately, the
docs are as you've found still pretty poor.

> 1.  The javascript example sets the following variable
> 
> var role = Packages.org.mystuff.UploadManager.ROLE;
> 
> and then passes it in like so:
> 
> var uploader = cocoon.componentManager.getComponent(role);
> 
> What is the ROLE attribute and how (or where) do I call it?  I
> gather that I need to call some class that implements some kind of
> component interface, but I can't figure out which one.

The reality is that to just get this working, you wouldn't even need
to mess with a component lookup.  If you have an upload handler you've 
written you should just be able to get an instance of your class, call 
your methods passing in whatever you need from the flow to save your 
file elsewhere, or do whatever you want.  If you try this and get stuck, 
write back with what went wrong.  Actually, to just get this working 
quickly, you could reference java.io classes directly from flow and
probably implement this in a few lines of flowscript.

But,

Brief interlude on avalon components because you asked and it's great
knowledge for working with Cocoon beyond the surface level and can help 
make up for missing docs in places.
----------------

The ROLE is a standard Avalon construct.  If you haven't already,
you should read up on the wiki, in the cocoon docs, and possibly
at the avalon.apache.org site (see especially the "Developing with 
Avalon" paper).  At least glance over those things if not really read 
deeply.

The short answer to your question:
The base Component is very simple -- you implement 
org.apache.avalon.framework.Component (maybe not exact) where you define
some ROLE -- a string which by convention would be the fully qualified 
class name of whatever class or interface defines this component.  In 
the simplest case, you would have something like:

package org.mystuff

public class UploadManager implements 
org.apache.avalon.framework.Component {

   String ROLE = Generator.class.getName();

   // Whatever other classes you implement are up to you.

}

In order for ComponentManager to find this role, you'd need to define it
in cocoon.xconf with a <component> tag (you used to have to define the 
role in cocoon.roles first, but that's no longer necessary).  There 
should be some other components defined this way you can see for examples.
------------------------------------

> 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.

> 3.  The Wiki howto shows you to how call a flow script from the
> sitemap (and the Cocoon docs show you how to set up the scripting
> environment for flows, and so forth), but I'm not sure what I'm
> supposed to do in the sitemap if I want to do a file upload with an
> action.  Most of the explanations out there seem deprecated.

The only things that have changed since the action related items were
written are:
- The FilePart, FilePartFile, and FilePartArray classes have moved 
packages and changed names to Part, PartOnDisk, and PartInMemory as
mentioned on the wiki.
- An alternative to actions exists now that flow is released.

Nothing else has changed.  Actions still work the same way and in this 
case may be easier to get up and running with since you're struggling 
under the learning curve right now.

> I'm sorry if these questions seem really dense.   

The material is dense, not the questions.  Besides, UGA did my home team 
a favor with Champ Bailey, so I owe you one!

Geoff


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org