cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steven D. Majewski" <sd...@virginia.edu>
Subject Re: FileUploadManager
Date Fri, 06 Oct 2006 17:34:39 GMT


I also found the examples on the Wiki both helpful and confusing.

I started with trying the upload: pseudo protocol, and I'm combining  
that with
using flowscript, because I need to add a bunch of conditional  
processing to
decide whether to accept the upload file ( and where to put it. )

I'm in the middle of that right now -- I'll try to post a recipe when  
I'm finished,
but since this topic has come up now, I'll post what I have so far:


In my sitemap I have:


     <!-- upload form  -->
     <map:pipeline>
       <map:match pattern="xml-upload">
         <map:generate type="jx" src="scripts/upload.jx"></map:generate>
         <map:serialize type="html" />
       </map:match>
     </map:pipeline>

     <!-- display upload as xml -->
     <map:pipeline>
       <map:match pattern="xml-upload-xml">
         <map:generate src="upload://pubxml" />
         <map:serialize type="xml" />
       </map:match>
     </map:pipeline>

     <!--  display upload styled as html  -->
     <map:pipeline>
       <map:match pattern="xml-upload-doc">
       <map:generate src="upload://pubxml" />
       <map:transform src="xsl/document.xsl" />
       <map:serialize type="html" />
       </map:match>
     </map:pipeline>

     <!-- upload flowscript processing -->
     <map:pipeline>
       <map:match pattern="xml-upload-process">
         <map:call function="upload" >
           <!-- <map:parameter name="temp_dir" value="{contextpath:./ 
work}" /> -->
           <!--  better keep files in /tmp for now : I can't clean  
files on tc0 -->
           <map:parameter name="temp_dir" value="/tmp" />
         </map:call>
       </map:match>
     </map:pipeline>



The upload form in upload.jx has (among other things):

<form action="xml-upload-process" method="post" enctype="multipart/ 
form-data"
	id="UPLOAD_FORM" name="UPLOAD_FORM" >

	<input type="file" name="pubxml" />
	<input id="submit1" name="submit1" type="submit" value="Submit" />

</form>


On my first attempt, the action was directed to the xml-upload-doc pipe.
Now it's directed to the flowscript, which at the moment, just   
copies the
file from the upload directory to another temp directory so that it  
will still
exist after the pipeline completes, and calls the xml-upload-doc page
to display styled output.



importClass( Packages.org.apache.commons.transaction.util.FileHelper );

function upload() {
     var docsrc = cocoon.request.getParameter( "pubxml");
     // make a copy of uploaded file to tmp ...
     if ( FileHelper.fileExists( docsrc ) ) {
         var doc = java.io.File( docsrc );
         FileHelper.copy( doc, java.io.File 
( cocoon.parameters.temp_dir, doc.getName() ));
     }

     cocoon.sendPage( 'xml-upload-doc' , {} );

}


What I need to add is to:
    protect the upload form with auth-manager;
    add some session logic to figure out where the file goes;
    display the page first -- ask if it's OK to publish
          if OK, move to where it belongs and display again, giving  
the final published URL for doc.



( I know the document is removed from the upload directory when the  
pipeline is complete.
I'm not quite sure, in the presence of flowscript continuations w/  
sendPageAndWait, how
long the file will remain. I'm guessing it will be safer to move it  
to my own temp space first. )

[ This is with Cocoon 2.1.9 BTW ]


-- Steve Majewski / UVA Alderman Library



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


Mime
View raw message