You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Josep Riudavets <jr...@uoc.edu> on 2003/11/10 16:08:53 UTC

Is it possible to upload files with Cocoon 2.1???

Hi all...

I have posted some messages in order to learn about uploading files with Cocoon 2.1. via an action, but there's no clear solution to this problem.

What do you think about this mistery??? Anybody has achieved it?

Thanks a lot

Josep.



Re: Is it possible to upload files with Cocoon 2.1???

Posted by Sylvain Wallez <sy...@apache.org>.
Josep Riudavets wrote:

> Hi all...
>  
> I have posted some messages in order to learn about uploading files 
> with Cocoon 2.1. via an action, but there's no clear solution to this 
> problem.
>  
> What do you think about this mistery??? Anybody has achieved it?


Just set the "enable-uploads" parameter in web.xml to true, and then you 
can use the following:

Part part = request.get("upload-input");
InputStream stream = part.getInputStream();

The Part class is defined in org.apache.cocoon.servlet.multipart

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



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


'mergexml' in authentication context

Posted by julien bloit <Ju...@ircam.fr>.
Hi,
When trying to use the <session:mergexml> tag with the session transformer
in the authentication framework, I get the foolowing error :

"org.apache.cocoon.ProcessingException: This method is not supported by the
authenticaton session context."

Is this a known issue (I use a  2.1.1 dev version of cocoon) or is there
something I'm doing wrong?

Sitemap snippet :

<map:match pattern="ajout">
   <map:act type="auth-loggedIn">
       <map:parameter name="handler" value="accounthandler"/>
           <map:act type="auth-protect">
               <map:parameter name="handler" value="accounthandler"/>
               <map:generate src="docs/ajoutEspacePerso.xml"/>
               <map:transform type="session"/>
               <map:serialize type="xml"/>
         </map:act>
    </map:act>
</map:match>


where ajoutEspacePerso.xml is :

<session:resource xmlns:session="http://apache.org/cocoon/session/1.0">
  <session:mergexml context="authentication"
path="authentication/data/resource/cart">
   <item>test</item>
   </session:mergexml>
 </session:resource>


Thanks a lot for your insight!!


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


Re: Is it possible to upload files with Cocoon 2.1???

Posted by Sylvain Wallez <sy...@apache.org>.
Josep Riudavets wrote:

>Thanks for your soon answer ...
>
>I have tried all wiki examples, my web.xml is well configured. The problem is that there is not a exact code for Cocoon 2.1. Could you post the exact action code you're using?
>  
>

public Map act(... Map objectModel ...) {
  Request request = ObjectModelHelper.getRequest(objectModel);
  Part part = (Part)request.get("upload-input");
  InputStream stream = part.getInputStream();

  // use stream here...
}

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



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


Re: Is it possible to upload files with Cocoon 2.1???

Posted by Nicolas Maisonneuve <n....@hotpop.com>.
I coded a upload component to use with flowscript
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=24529
see the explanation
There is a error in the package name  , use  this :
<?xml version="1.0" encoding="UTF-8"?>
<role-list>
<role name="org.apache.cocoon.components.UploadManager"
    shorthand="upload_manager"
    default-class="org.apache.cocoon.components.UploadManagerImpl"/>
</role-list>

> Hi Sylvain ... I post the code I'm using... Tell me what you think about
it
> ...
>
> 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 FileUploadAction
>  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;
>
> }
>
> }
>
>
> In sitemap:
>
> <map:actions>
> <map:action name="fileupload" src="edu.uoc.riudavets.FileUploadAction"/>
> </map:actions>
>
> Pipeline:
>
> <map:pipeline>
> <map:match pattern="upload">
> <map:act type="fileupload">
> <map:generate src="XML/success.xml"/>
> <map:transform src="XSL/success.xsl"/>
> <map:serialize type="html"/>
> </map:act>
> <map:generate src="XML/fail.xml"/>
> <map:transform src="XSL/fail.xsl"/>
> <map:serialize type="html"/>
> </map:match>
> </map:pipeline>
>
> Form:
>
> <form name="f1" action="upload" method="post">
> <input type="file" name="uploadfile"/>
> <input type="submit" value="Upload"/>
> </form>
>
>
> I have been trying to make it works during some weeks .. I don't know what
> more I can do !!!!
>
> Please, some help !!!  <:-(
>
>
>
> ----- Original Message -----
> From: "Sylvain Wallez" <sy...@apache.org>
> To: <us...@cocoon.apache.org>
> Sent: Monday, November 10, 2003 5:34 PM
> Subject: Re: Is it possible to upload files with Cocoon 2.1???
>
>
> > Josep Riudavets wrote:
> >
> > >Thanks for your soon answer ...
> > >
> > >I have tried all wiki examples, my web.xml is well configured. The
> problem is that there is not a exact code for Cocoon 2.1. Could you post
the
> exact action code you're using?
> > >
> > >
> >
> > public Map act(... Map objectModel ...) {
> >   Request request = ObjectModelHelper.getRequest(objectModel);
> >   Part part = (Part)request.get("upload-input");
> >   InputStream stream = part.getInputStream();
> >
> >   // use stream here...
> > }
> >
> > Sylvain
> >
> > --
> > Sylvain Wallez                                  Anyware Technologies
> > http://www.apache.org/~sylvain           http://www.anyware-tech.com
> > { XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
> > Orixo, the opensource XML business alliance  -  http://www.orixo.com
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>



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


Re: Is it possible to upload files with Cocoon 2.1???

Posted by Sylvain Wallez <sy...@apache.org>.
Josep Riudavets wrote:

>Hi Sylvain ... I post the code I'm using... Tell me what you think about it
>...
>
>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 FileUploadAction
> 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;
>
>	}
>
>}
>
>
>In sitemap:
>
><map:actions>
>	<map:action name="fileupload" src="edu.uoc.riudavets.FileUploadAction"/>
></map:actions>
>
>Pipeline:
>
><map:pipeline>
><map:match pattern="upload">
><map:act type="fileupload">
><map:generate src="XML/success.xml"/>
><map:transform src="XSL/success.xsl"/>
><map:serialize type="html"/>
></map:act>
><map:generate src="XML/fail.xml"/>
><map:transform src="XSL/fail.xsl"/>
><map:serialize type="html"/>
></map:match>
></map:pipeline>
>
>Form:
>
><form name="f1" action="upload" method="post">
><input type="file" name="uploadfile"/>
><input type="submit" value="Upload"/>
></form>
>
>
>I have been trying to make it works during some weeks .. I don't know what
>more I can do !!!!
>
>Please, some help !!!  <:-(
>
>  
>

Please, read carefully my example: you have to do something with the 
uploaded content!!!

  InputStream stream = part.getInputStream();
  // use stream here...

The Part objects represents a temporary storage that is trashed when the 
request processing is finished. So you *must* move the uploaded data 
somewhere else in the action.

Sylvain

-- 
Sylvain Wallez                                  Anyware Technologies
http://www.apache.org/~sylvain           http://www.anyware-tech.com
{ XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
Orixo, the opensource XML business alliance  -  http://www.orixo.com



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


Re: Is it possible to upload files with Cocoon 2.1???

Posted by Josep Riudavets <jr...@uoc.edu>.
Hi Sylvain ... I post the code I'm using... Tell me what you think about it
...

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

	}

}


In sitemap:

<map:actions>
	<map:action name="fileupload" src="edu.uoc.riudavets.FileUploadAction"/>
</map:actions>

Pipeline:

<map:pipeline>
<map:match pattern="upload">
<map:act type="fileupload">
<map:generate src="XML/success.xml"/>
<map:transform src="XSL/success.xsl"/>
<map:serialize type="html"/>
</map:act>
<map:generate src="XML/fail.xml"/>
<map:transform src="XSL/fail.xsl"/>
<map:serialize type="html"/>
</map:match>
</map:pipeline>

Form:

<form name="f1" action="upload" method="post">
<input type="file" name="uploadfile"/>
<input type="submit" value="Upload"/>
</form>


I have been trying to make it works during some weeks .. I don't know what
more I can do !!!!

Please, some help !!!  <:-(



----- Original Message -----
From: "Sylvain Wallez" <sy...@apache.org>
To: <us...@cocoon.apache.org>
Sent: Monday, November 10, 2003 5:34 PM
Subject: Re: Is it possible to upload files with Cocoon 2.1???


> Josep Riudavets wrote:
>
> >Thanks for your soon answer ...
> >
> >I have tried all wiki examples, my web.xml is well configured. The
problem is that there is not a exact code for Cocoon 2.1. Could you post the
exact action code you're using?
> >
> >
>
> public Map act(... Map objectModel ...) {
>   Request request = ObjectModelHelper.getRequest(objectModel);
>   Part part = (Part)request.get("upload-input");
>   InputStream stream = part.getInputStream();
>
>   // use stream here...
> }
>
> Sylvain
>
> --
> Sylvain Wallez                                  Anyware Technologies
> http://www.apache.org/~sylvain           http://www.anyware-tech.com
> { XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
> Orixo, the opensource XML business alliance  -  http://www.orixo.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>



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


Re: Is it possible to upload files with Cocoon 2.1???

Posted by Josep Riudavets <jr...@uoc.edu>.
Thanks for your soon answer ...

I have tried all wiki examples, my web.xml is well configured. The problem
is that there is not a exact code for Cocoon 2.1. Could you post the exact
action code you're using?

Thanks....

----- Original Message -----
From: "Sylvain Wallez" <sy...@apache.org>
To: <us...@cocoon.apache.org>
Sent: Monday, November 10, 2003 5:03 PM
Subject: Re: Is it possible to upload files with Cocoon 2.1???


> Josep Riudavets wrote:
>
> > Hi all...
> >
> > I have posted some messages in order to learn about uploading files
> > with Cocoon 2.1. via an action, but there's no clear solution to this
> > problem.
> >
> > What do you think about this mistery??? Anybody has achieved it?
>
>
> Just set the "enable-uploads" parameter in web.xml to true, and then you
> can use the following:
>
> Part part = request.get("upload-input");
> InputStream stream = part.getInputStream();
>
> The Part class is defined in org.apache.cocoon.servlet.multipart
>
> Sylvain
>
> --
> Sylvain Wallez                                  Anyware Technologies
> http://www.apache.org/~sylvain           http://www.anyware-tech.com
> { XML, Java, Cocoon, OpenSource }*{ Training, Consulting, Projects }
> Orixo, the opensource XML business alliance  -  http://www.orixo.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>



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