Re: InflatedFileGenerator

2003-11-19 Thread Tony Edwards
Hi Jean,
We use the OpenOffice format a fair bit here for other projects. I did 
write a simple generator to extract the 'content.xml' from the .sxw file 
but it was a bit of a kludgey hack as my java skills are still a bit 
infantile!
I'd be interested in utilising your offering if that's possible.

Thanks,
tony
Jean-Christophe Kermagoret wrote:

Hi List,
I wrote a very simple InflatedFileGenerator that takes a zip file and 
extract one item to use it as source for
FileGenerator.

It's useful if you want to use, for example, standart OpenOffice.org 
format .sxw instead of flat xml.
Of course you can use it with .zip format.

Usage example :
...
   map:match pattern=process-ooo
   map:generate type=inflated src=ooo/presentation.sxw
   map:parameter name=directory value=ooo/
   map:parameter name=file value=content.xml/
   /map:generate
   map:transform src=test/ooo-content2sdbk.xsl/
   map:serialize type=xml/
   /map:match
...
where :
* directory is the dir where the file is going to be inflated
* file is the name of the file you want to get
Is there anybody interested ?
Where do I put it ?
Regards,

 



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


RE: InflatedFileGenerator

2003-11-19 Thread Conal Tuohy
You can read zipped content with the regular FileGenerator, using the jar:
protocol.
See http://wiki.cocoondev.org/Wiki.jsp?page=JarProtocolExample

 -Original Message-
 From: Tony Edwards [mailto:[EMAIL PROTECTED]
 Sent: Thursday, 20 November 2003 12:36
 To: [EMAIL PROTECTED]
 Subject: Re: InflatedFileGenerator


 Hi Jean,
 We use the OpenOffice format a fair bit here for other
 projects. I did
 write a simple generator to extract the 'content.xml' from
 the .sxw file
 but it was a bit of a kludgey hack as my java skills are still a bit
 infantile!
 I'd be interested in utilising your offering if that's possible.

 Thanks,
 tony

 Jean-Christophe Kermagoret wrote:

 Hi List,
 I wrote a very simple InflatedFileGenerator that takes a zip
 file and
 extract one item to use it as source for
 FileGenerator.
 
 It's useful if you want to use, for example, standart OpenOffice.org
 format .sxw instead of flat xml.
 Of course you can use it with .zip format.
 
 Usage example :
 ...
 map:match pattern=process-ooo
 map:generate type=inflated src=ooo/presentation.sxw
 map:parameter name=directory value=ooo/
 map:parameter name=file value=content.xml/
 /map:generate
 map:transform src=test/ooo-content2sdbk.xsl/
 map:serialize type=xml/
 /map:match
 ...
 
 where :
 * directory is the dir where the file is going to be inflated
 * file is the name of the file you want to get
 
 Is there anybody interested ?
 Where do I put it ?
 
 Regards,
 
 
 


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



Re: InflatedFileGenerator

2003-11-19 Thread Jean-Christophe Kermagoret
I didn't know the FileGenerator zipped capabilities ...
Here it is my source. It's pretty simple. It inherits from the 
FileGenerator.

You have to give 4 parameters :
* src : src archive path
* directory : dir where you want to store the unzipped content
* file : file to extract
* newfile : new filename
pipeline
   map:match pattern=process-training-ooo-*
   map:generate type=inflated src=training/{1}.sxw
   map:parameter name=directory value=ooo/
   map:parameter name=file value=content.xml/
   map:parameter name=newfile value={1}.xml/
   /map:generate
   map:transform src=stylesheets/tranform.xsl/
   map:serialize type=xml/
   /map:match
/pipeline
Of course, don't forget :
map:generators
...
   map:generator label=content logger=sitemap.generator.inflated 
name=inflated pool-grow=4 pool-max=32 pool-min=8 
src=org.apache.cocoon.generation.InflatedFileGenerator/
...
/map:generators

Hope that helps.

/*
* $Id$
*
* Copyright @ 2003 BABEL OBJECTS SARL. All Rights Reserved.
*
* This software is the proprietary information of BABEL OBJECTS SARL. 
* Use is subject to license terms.
*
*/
package org.apache.cocoon.generation;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.environment.http.HttpEnvironment;
import org.apache.cocoon.environment.wrapper.MutableEnvironmentFacade;
import org.xml.sax.SAXException;
import java.io.IOException;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
/**
* $Id$
*
* @author Jean-Christophe Kermagoret
*/
public class InflatedFileGenerator extends FileGenerator {
   /**
* Setup the file generator.
* Try to get the last modification date of the source for caching.
*/
   public void setup(SourceResolver resolver, Map objectModel, String 
src, Parameters par)
   throws ProcessingException, SAXException, IOException {
  
   String contextUrl = null;
  
   if (resolver instanceof HttpEnvironment) {
   contextUrl = ((HttpEnvironment) resolver).getContext();
   } else if (resolver instanceof MutableEnvironmentFacade) {   
   contextUrl = ((MutableEnvironmentFacade) resolver).getContext();
   }
   // We cut the first 6 characters corresponding to file:/
   String contextDir = 
contextUrl.substring(6,contextUrl.length());   
   super.setup(resolver, objectModel, retrieveFile(contextDir, src, 
par), par);
   }
  
   /*
* Always retrieves the file, even :
* if there is none
* or if there is already one and its date is older than the archive
* @TODO: cache implementation for extracted file
*/
   public String retrieveFile(String contextDir, String src, Parameters 
par) {
   String tmpDir = null;
   String fileToRetrieve = null;
   String newFileName = null;
   try {
   tmpDir = par.getParameter(directory);
   fileToRetrieve = par.getParameter(file);
   newFileName = par.getParameter(newfile);
   } catch (Exception ex) {
   }

   try {
   // Open the ZIP file
   String inFilename = contextDir + src;
  
   ZipInputStream in = new ZipInputStream(new 
FileInputStream(inFilename));

   // Lookup the right entry
   ZipEntry entry;
   do {
   entry = in.getNextEntry();
   } while (! fileToRetrieve.equals(entry.getName()));
   // Open the output file
   String outFilename = contextDir + tmpDir + / + newFileName;
   OutputStream out = new FileOutputStream(outFilename);
   // Transfer bytes from the ZIP file to the output file
   byte[] buf = new byte[1024];
   int len;
   while ((len = in.read(buf))  0) {
   out.write(buf, 0, len);
   }
   // Close the streams
   out.close();
   in.close();
  
   return outFilename;
  
   } catch (IOException e) {
   }
  
   return null;
   }
}

Tony Edwards wrote:

Hi Jean,
We use the OpenOffice format a fair bit here for other projects. I did 
write a simple generator to extract the 'content.xml' from the .sxw 
file but it was a bit of a kludgey hack as my java skills are still a 
bit infantile!
I'd be interested in utilising your offering if that's possible.

Thanks,
tony
Jean-Christophe Kermagoret wrote:

Hi List,
I wrote a very simple InflatedFileGenerator that takes a zip file and 
extract one item to use it as source for
FileGenerator.

It's useful if you want to use, for example, standart OpenOffice.org 
format .sxw instead of flat xml.
Of course you can use it with .zip format.

Usage example :
...
   map:match pattern=process-ooo
   map:generate 

Re: InflatedFileGenerator

2003-11-19 Thread Jean-Christophe Kermagoret
Is extracted file of zipped content cached ?

Conal Tuohy wrote:

You can read zipped content with the regular FileGenerator, using the jar:
protocol.
See http://wiki.cocoondev.org/Wiki.jsp?page=JarProtocolExample
 

-Original Message-
From: Tony Edwards [mailto:[EMAIL PROTECTED]
Sent: Thursday, 20 November 2003 12:36
To: [EMAIL PROTECTED]
Subject: Re: InflatedFileGenerator
Hi Jean,
We use the OpenOffice format a fair bit here for other
projects. I did
write a simple generator to extract the 'content.xml' from
the .sxw file
but it was a bit of a kludgey hack as my java skills are still a bit
infantile!
I'd be interested in utilising your offering if that's possible.
Thanks,
tony
Jean-Christophe Kermagoret wrote:

   

Hi List,
I wrote a very simple InflatedFileGenerator that takes a zip
 

file and
   

extract one item to use it as source for
FileGenerator.
It's useful if you want to use, for example, standart OpenOffice.org
format .sxw instead of flat xml.
Of course you can use it with .zip format.
Usage example :
...
  map:match pattern=process-ooo
  map:generate type=inflated src=ooo/presentation.sxw
  map:parameter name=directory value=ooo/
  map:parameter name=file value=content.xml/
  /map:generate
  map:transform src=test/ooo-content2sdbk.xsl/
  map:serialize type=xml/
  /map:match
...
where :
* directory is the dir where the file is going to be inflated
* file is the name of the file you want to get
Is there anybody interested ?
Where do I put it ?
Regards,



 

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



--

Jean-Christophe Kermagoret
[EMAIL PROTECTED]


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