Hi H.,

It is not as complex as it might look, but you must extend the ZipSource
component to make it work. I added the following code in the
getInputStream function:

                String xml = "<?xml version=\"1.0\"
encoding=\"utf-8\"?>\n<zip:archive xmlns:zip=\"" + ZIP_NAMESPACE + "\"
name=\"" + this.archive.getURI() + "\">\n";

            ZipEntry document = null;
                do {
                    document = zipStream.getNextEntry();
                    if (document != null) {
                        xml += "  <zip:entry name=\"" +
document.getName() + "\" />\n";
                        zipStream.closeEntry();
                    }
                } while (document != null);

                xml += "</zip:archive>\n";

                return new ByteArrayInputStream(xml.getBytes("utf-8"));

As you can see, this returns a list of socalled zip:entry elements with
the names WITH (sub)path of the documents inside the zip (zip entries)
as name attribute of these elements. Simple but effective. You will also
need to change the ZipSourceFactory to identify when to return a zip
entry listing and when to return actual file contents.

The fun thing is that you can use the zip protocol itself to get both
the zip entry listing and the actual file contents. What I usually do is
start a pipeline match with a generate to get the zip entry listing. I
then call an XSL to which I pass the URN that provided the zip entry
listing. The XSL changes each zip:entry into a save:file element and
takes as src attribute the URN for the zip, extended with the specific
name of the zip:entry. As target you can do as you like. I typically
have a global variable data-dir, to which I write. But you could write
to Temp as well, or to a path that is provided as request-param.

The SaveFilesTransformer simply uses the zip protocol to get access to
the contents of each zip entry, as you specified with your XSL. The
transformer does not care at all where contents is coming from, that is
the beauty.

The only bottleneck might be that empty directories might not come out.
Directories are not stored as zip entries if I am correct.

HTH,
Geert

> -----Original Message-----
> From: HGENTO [mailto:[EMAIL PROTECTED] 
> Sent: dinsdag 29 mei 2007 22:24
> To: users@cocoon.apache.org
> Subject: Re: unpack/unizp a complete zip file?
> 
> Hi Geert Jorsten,
> 
> thank you for your detailed explanation. But now I'm a little 
> but confused ;-) I'll try to set up an action but at the 
> moment struggling with some .tmp files issues. So therefore I 
> would also like to try your why as it sound very good but on 
> the other way a little bit confusing. Hopefully I can ask you 
> few questions to this to fully understand. I know how 
> transformer work ad at the end i only need and xml file 
> containing the information in the way the transformer needs 
> for writing. So far so good but: how can I receive the 
> directory and files as well as all subdirectory and subfiles 
> within the zip file I want to extract? And the second 
> question will be, how I have to set this instruction in the 
> xml file, that contains the save information. cocoon wiki 
> only tells me 
> 
> <save:file
>         src="mySourceUrl"
>         target="myTargetFileName"
>         xmlns:save="http://daidalos.nl/cocoon/save/1.0"; 
> <http://daidalos.nl/cocoon/save/1.0>  />
> 
> In what kind of why I have to set the src attribute, as at 
> the end it has to read the files and folder within the zip file?
> Perhaps you can give me another hint ;-) Hopefully, H.
> Geert Josten wrote: 
> 
>       Hi,
>       
>       It was a rather short and quick answer, but yes, 
> depending on the
>       component that extracts the files and writes them, it 
> is in principle
>       possible to extract all types of files. SourceWriting 
> component however
>       uses XML/DOM as intermediate, so that component is 
> unuseable as it is.
>       (At least how it was around versions 2.1.4 - 2.1.6..)
>       
>       The SaveFiles transformer however is exactly written 
> for this task. It
>       doesn't cache anything, it redirect an inputstream to 
> an outputstream
>       internally and is therefore capable of handling binary. 
> Only the outcome
>       (fail or success) is passed to cocoon as xml. More 
> about it on wiki:
>       http://wiki.apache.org/cocoon/SaveFilesTransformer
>       
>       My zipsource produces on long xml with the full 
> contents. One xsl pass
>       converts this to savefiles instruction sheet, just a 
> long list of
>       save:file elements with a src and a target attribute. 
> These can be
>       processed in a single pass with the transformer. The 
> end result of this
>       transform can be used to produce a fail/success report.
>       
>       One final note on Cocoon Actions, the alternative on which Joerg
>       Heinicke responded:
>       be aware of the moment on which actions are executed. 
> Regardless of
>       where they are called within a request-chain, they are 
> always executed
>       _before_ the actual processing in a pipeline. This is 
> only important if
>       you intend to process the files with the same request 
> that also extracts
>       the files. It might be very useful, but can be a 
> bottle-neck just as
>       easily.
>       
>       Kind regards,
>       Geert
>       
>         
> 
>               -----Original Message-----
>               From: HGENTO [mailto:[EMAIL PROTECTED] 
>               Sent: vrijdag 25 mei 2007 15:59
>               To: users@cocoon.apache.org
>               Subject: Re: unpack/unizp a complete zip file?
>               
>               Thank you for your answer ,
>               
>               but I'm a little bit confused, would this 
> methode also work, 
>               if the zip file contains not only xml-files but also 
>               pictures. For example ein Open Document Writer 
> file. I would 
>               like to have a methode where I can unpack the 
> full odt files.
>               
>               Best regards,
>               H.
>               
>               Geert Josten wrote:
>                   
> 
>                       Hi,
>                       
>                       I extended the ZipSource component to 
> accept zip-protocol patterns 
>                       without the addition of special files. 
> But the Source is 
>                             
> 
>               supposed to 
>                   
> 
>                       produce content and you cannot produce 
> the literal zip 
>                             
> 
>               contents, so I 
>                   
> 
>                       chose to produce a dir-listing of the 
> zip. I use that to 
>                             
> 
>               generate new 
>                   
> 
>                       zip-url's that exhaustingly point to 
> all files inside zip. 
>                             
> 
>               Processing 
>                   
> 
>                       that list with a component like 
> savefiles or writesource 
>                             
> 
>               should result 
>                   
> 
>                       in extraction of a complete zip.
>                       
>                       HTH,
>                       Geert
>                       
>                         
>                          
>                        
>                       Drs. G.P.H. Josten
>                       Consultant
>                        
>                        
>                       
>                       Daidalos BV
>                       Source of Innovation
>                       Hoekeindsehof 1-4
>                       2665  JZ  Bleiswijk
>                       Tel.: +31 (0) 10 850 1200
>                       Fax: +31 (0) 10 850 1199
>                       www.daidalos.nl
>                       KvK 27164984
>                       
>                       
>                       De informatie - verzonden in of met dit 
> emailbericht - is 
>                             
> 
>               afkomstig van Daidalos BV en is uitsluitend 
> bestemd voor de 
>               geadresseerde. Indien u dit bericht onbedoeld 
> hebt ontvangen, 
>               verzoeken wij u het te verwijderen. Aan dit 
> bericht kunnen 
>               geen rechten worden ontleend.
>                   
> 
>                        
>                       
>                         
>                             
> 
>                               From: HGENTO 
> [mailto:[EMAIL PROTECTED]
>                               Sent: vrijdag 25 mei 2007 13:52
>                               To: users@cocoon.apache.org
>                               Subject: unpack/unizp a 
> complete zip file?
>                               
>                               Hi,
>                               
>                               how can I unzip a zip file with 
> an sitemap instruction. I 
>                                       
> 
>               have access 
>                   
> 
>                               to a special file with 
> zip:/file.zip!/file.xml but I would like to 
>                               have an instruction to unzip 
> the complete file.zip. Is 
>                                       
> 
>               there a easy 
>                   
> 
>                               way to do so in Cocoon 2.1.? I 
> did't found a answer on 
>                                       
> 
>               wiki as well 
>                   
> 
>                               as apache cocoon homepage.
>                               
>                               Regards,
>                               Holger
>                               
>                               
>                                       
> 
>               
> ---------------------------------------------------------------------
>                   
> 
>                               To unsubscribe, e-mail: 
> [EMAIL PROTECTED]
>                               For additional commands, 
> e-mail: [EMAIL PROTECTED]
>                               
>                               
>                                   
>                                       
> 
>                       
>                             
> 
>               
> ---------------------------------------------------------------------
>                   
> 
>                       To unsubscribe, e-mail: 
> [EMAIL PROTECTED]
>                       For additional commands, e-mail: 
> [EMAIL PROTECTED]
>                       
>                       
>                       
>                         
>                             
> 
>               
>               
> ---------------------------------------------------------------------
>               To unsubscribe, e-mail: 
> [EMAIL PROTECTED]
>               For additional commands, e-mail: 
> [EMAIL PROTECTED]
>               
>               
>                   
> 
>       
>       
> ---------------------------------------------------------------------
>       To unsubscribe, e-mail: [EMAIL PROTECTED]
>       For additional commands, e-mail: [EMAIL PROTECTED]
>       
>       
>       
>         
> 
> 
> 

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

Reply via email to