RE: Free for use: SaveFilesTransformer

2006-09-21 Thread Geert Josten
> > And the rollback() at endDocument() as well (if necessary :). 
> >   
> Hum ...
> In fact the transaction id is the file url.
> IMHO endDocument is not called if an exeption occure in pipeline.

You are right, point taken! :-P

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

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



Re: Free for use: SaveFilesTransformer

2006-09-21 Thread Olivier

Geert Josten wrote:
Really an intersting idea. But I'd not begin the transaction 
in setup(). 
What about startDocument()?



And the rollback() at endDocument() as well (if necessary :). Though I
guess I would like to manage the transactions independantly altogether.
In actions fired with separate urls perhaps?

;-)
   
  

Hum ...
In fact the transaction id is the file url.
IMHO endDocument is not called if an exeption occure in pipeline.

See the transformer in attachment.

Comment are very welcome ...

/*
 * Created on 3 sept. 2005
 *
 */
package net.orcades.cocoon.transformation;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

import net.orcades.cocoon.InvalidResourceException;
import net.orcades.cocoon.transaction.FileManagerPool;
import net.orcades.cocoon.transaction.ResourceManagerProcessingException;

import org.apache.avalon.framework.parameters.ParameterException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.AbstractSAXTransformer;
import org.apache.commons.transaction.file.FileResourceManager;
import org.apache.commons.transaction.file.ResourceManagerException;
import org.apache.excalibur.source.Source;
import org.apache.xml.serialize.OutputFormat;
import org.apache.xml.serialize.XMLSerializer;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;

/**
 * @author olivier nouguier
 * 
 */
public class TransactionalFileWriterTransformer extends AbstractSAXTransformer {
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.cocoon.transformation.AbstractSAXTransformer#configure(org.apache.avalon.framework.configuration.Configuration)
	 */
	private FileResourceManager fileManager;

	private XMLSerializer serializer;

	private Object txId;

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.cocoon.transformation.AbstractSAXTransformer#setup(org.apache.cocoon.environment.SourceResolver,
	 *  java.util.Map, java.lang.String,
	 *  org.apache.avalon.framework.parameters.Parameters)
	 */
	public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException {
		super.setup(resolver, objectModel, src, par);
		try {
			
			Source source = null;
			
			try {
source = resolver.resolveURI(par.getParameter("dest-dir"));
String destDir = new URI(source.getURI()).getPath();


fileManager = FileManagerPool.getInstance().getFileResourceManager(destDir, getLogger(), par.getParameterAsBoolean("debug-fine", true));
if(par.getParameterAsBoolean("reset", false)){
	fileManager.recover();
}
if(fileManager.resourceExists(src)){
	File file = new File(fileManager.getStoreDir() + File.separator + src);
	if(file.isDirectory()){
		fileManager=null;
		txId=null;
		
		throw new InvalidResourceException("IS_A_DIRECTORY");
	}
}





fileManager.startTransaction(src);

txId = src;

OutputStream outputStream = fileManager.writeResource(txId, src);

serializer = new XMLSerializer();

OutputFormat outputFormat = new OutputFormat();
outputFormat.setMethod(par.getParameter("method", "xml"));
outputFormat.setEncoding(par.getParameter("encoding", "ISO-8859-1"));
outputFormat.setIndent(par.getParameterAsInteger("indenting", 1));
serializer.setOutputFormat(outputFormat);

serializer.setOutputByteStream(outputStream);
			} finally {
if(source!=null)
	resolver.release(source);
			}

		} catch (ParameterException e) {
			throw new ProcessingException(e);
		} catch (ResourceManagerException e) {
			throw new ResourceManagerProcessingException(src, e);
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.cocoon.transformation.AbstractSAXTransformer#startDocument()
	 */
	public void startDocument() throws SAXException {
		super.startDocument();
		serializer.startDocument();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.cocoon.transformation.AbstractSAXTransformer#startElement(java.lang.String,
	 *  java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 */
	public void startElement(String uri, String name, String raw, Attributes attr) throws SAXException {
		super.startElement(uri, name, raw, attr);
		serializer.startElement(uri, name, raw, attr);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.cocoon.transformation.AbstractSAXTransformer#startCDATA()
	 */
	public void startCDATA() throws SAXException {
		super.startCDATA();
		serializer.startCDATA();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.cocoon.transformation.AbstractSAXTransformer#ch

Re: Free for use: SaveFilesTransformer

2006-09-21 Thread Olivier


Joerg Heinicke wrote:
Really an intersting idea. But I'd not begin the transaction in 
setup(). What about startDocument()?



right :-)

Jörg

On 20.09.2006 18:53, Olivier wrote:


 
  
 

The transaction
* begins on setUp
* commit on endDocument
* roll back on recycle (if needed!)


Geert Josten wrote:

How does it work?

Kind regards,
Geert
 

-Oorspronkelijk bericht-
Van: Olivier [mailto:[EMAIL PROTECTED] Verzonden: woensdag 20 
september 2006 10:07

Aan: users@cocoon.apache.org
Onderwerp: Re: Free for use: SaveFilesTransformer

Hi all,
 I've build a transactionnal write transformer on top of :
http://jakarta.apache.org/commons/transaction/
Works fine in production.


-
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: Free for use: SaveFilesTransformer

2006-09-20 Thread Geert Josten
> Really an intersting idea. But I'd not begin the transaction 
> in setup(). 
> What about startDocument()?

And the rollback() at endDocument() as well (if necessary :). Though I
guess I would like to manage the transactions independantly altogether.
In actions fired with separate urls perhaps?

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

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



Re: Free for use: SaveFilesTransformer

2006-09-20 Thread Joerg Heinicke
Really an intersting idea. But I'd not begin the transaction in setup(). 
What about startDocument()?


Jörg

On 20.09.2006 18:53, Olivier wrote:


 
  
 

The transaction
* begins on setUp
* commit on endDocument
* roll back on recycle (if needed!)


Geert Josten wrote:

How does it work?

Kind regards,
Geert
 

-Oorspronkelijk bericht-
Van: Olivier [mailto:[EMAIL PROTECTED] Verzonden: woensdag 20 
september 2006 10:07

Aan: users@cocoon.apache.org
Onderwerp: Re: Free for use: SaveFilesTransformer

Hi all,
 I've build a transactionnal write transformer on top of :
http://jakarta.apache.org/commons/transaction/
Works fine in production.


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



Re: Free for use: SaveFilesTransformer

2006-09-20 Thread Olivier


 
  
 

The transaction
* begins on setUp
* commit on endDocument
* roll back on recycle (if needed!)


Geert Josten wrote:

How does it work?

Kind regards,
Geert 

  

-Oorspronkelijk bericht-
Van: Olivier [mailto:[EMAIL PROTECTED] 
Verzonden: woensdag 20 september 2006 10:07

Aan: users@cocoon.apache.org
Onderwerp: Re: Free for use: SaveFilesTransformer

Hi all,
 I've build a transactionnal write transformer on top of :
http://jakarta.apache.org/commons/transaction/
Works fine in production.

Geert Josten wrote:


Hi all,

Available on wiki:

http://wiki.apache.org/cocoon/SaveFilesTransformer

It might be that someone else already wrote a Transformer 
  

like this one.

It is derived from the SourceWritingTransformer (yet 
  
simplified) and 

has one important benefit over it: it can take a src attribute that 
can be used to capture also binary streams and save them to disk.


Comments are welcome..

Kind regards,
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.

  

-


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]



RE: Free for use: SaveFilesTransformer

2006-09-20 Thread Geert Josten
How does it work?

Kind regards,
Geert 

> -Oorspronkelijk bericht-
> Van: Olivier [mailto:[EMAIL PROTECTED] 
> Verzonden: woensdag 20 september 2006 10:07
> Aan: users@cocoon.apache.org
> Onderwerp: Re: Free for use: SaveFilesTransformer
> 
> Hi all,
>  I've build a transactionnal write transformer on top of :
> http://jakarta.apache.org/commons/transaction/
> Works fine in production.
> 
> Geert Josten wrote:
> > Hi all,
> >
> > Available on wiki:
> >
> > http://wiki.apache.org/cocoon/SaveFilesTransformer
> >
> > It might be that someone else already wrote a Transformer 
> like this one.
> > It is derived from the SourceWritingTransformer (yet 
> simplified) and 
> > has one important benefit over it: it can take a src attribute that 
> > can be used to capture also binary streams and save them to disk.
> >
> > Comments are welcome..
> >
> > Kind regards,
> > 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.
> >
> > 
> -
> > 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]



Re: Free for use: SaveFilesTransformer

2006-09-20 Thread Olivier

Hi all,
I've build a transactionnal write transformer on top of :
http://jakarta.apache.org/commons/transaction/
Works fine in production.

Geert Josten wrote:

Hi all,

Available on wiki:

http://wiki.apache.org/cocoon/SaveFilesTransformer

It might be that someone else already wrote a Transformer like this one.
It is derived from the SourceWritingTransformer (yet simplified) and has
one important benefit over it: it can take a src attribute that can be
used to capture also binary streams and save them to disk.

Comments are welcome..

Kind regards,
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.

-
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: Free for use: SaveFilesTransformer

2006-09-19 Thread Geert Josten
> Can I ask why we need a simplified SourceWritingTransformer?

Ofcourse you can: you just did.. :-)

No, I don't think a simplified one is needed, but it is the second use
case that is most interesting.

Perhaps I should have said that it is *another*
SourceWritingTransformer.. :-P

Kind regards,
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.

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



Re: Free for use: SaveFilesTransformer

2006-09-19 Thread Leszek Gawron

Geert Josten wrote:

Hi all,

Available on wiki:

http://wiki.apache.org/cocoon/SaveFilesTransformer

It might be that someone else already wrote a Transformer like this one.
It is derived from the SourceWritingTransformer (yet simplified) and has
one important benefit over it: it can take a src attribute that can be
used to capture also binary streams and save them to disk.

Comments are welcome..

Can I ask why we need a simplified SourceWritingTransformer?

--
Leszek Gawron, IT Manager  MobileBox sp. z o.o.
+48 (61) 855 06 67  http://www.mobilebox.pl
mobile: +48 (501) 720 812   fax: +48 (61) 853 29 65

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