You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cocoon.apache.org by Alexander Lochschmied <Al...@Vishay.com> on 2006/03/07 19:52:28 UTC

FOP 0.91 Serializer

Hello everybody,

to get Apache FOP 0.91 beta working with Cocoon, a new Serializer is
necessary (the FOP API changed considerably). I wrote a very simple but
working Serializer and hope that helps a little for future releases of
Cocoon. The Serializer doesn't accept any configuration except 'mime-type'
yet.

Best regards,
Alexander

-------- snip ------------------------------------------------
package org.apache.cocoon.serialization;

import org.apache.fop.apps.Fop;
import java.io.OutputStream;
import java.io.Serializable;
import javax.xml.parsers.SAXParserFactory;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
import org.apache.cocoon.caching.CacheableProcessingComponent;
import org.apache.excalibur.source.SourceValidity;
import org.apache.fop.apps.FOUserAgent;
import org.xml.sax.helpers.DefaultHandler;

public class FOP091Serializer
extends AbstractSerializer
implements
Configurable, CacheableProcessingComponent, Serviceable/*, Disposable */ {
	protected Logger          logger;
	protected String          mimetype;
	protected boolean         setContentLength  = true;
	protected FOUserAgent     userAgent         = null;
	protected Fop             fop               = null;
	protected ServiceManager  manager;
	protected javax.xml.transform.stream.StreamResult res = null;
	
	public void service( ServiceManager manager )
	throws ServiceException {
		this.manager = manager;
	}
	
	public void configure( Configuration conf )
	throws ConfigurationException {		
		this.logger = getLogger().getChildLogger( "fop" );
		
		this.setContentLength =
			conf.getChild( "set-content-length"
).getValueAsBoolean( true );
		
		String configUrl = 
			conf.getChild( "user-config" ).getValue( null );
		
		
		this.mimetype = conf.getAttribute( "mime-type" );
		
		// TODO get and use user configuration
		// TODO get and use user's renderer definition, ...

	}
	
	public String getMimeType() {
		return this.mimetype;
	}	
	
	public void setOutputStream( OutputStream o ) {
		DefaultHandler dh = null;
		
		fop = new Fop( this.mimetype );
		
		fop.setOutputStream( o );
		
		SAXParserFactory factory = SAXParserFactory.newInstance();
		factory.setNamespaceAware( true );
		
		try {
			dh = fop.getDefaultHandler();
			setContentHandler( dh );
		} catch( Exception ex) {
			; // TODO FIXME
		}
	}
	
	public Serializable getKey() {
		return "0";
	}
	
	public SourceValidity getValidity() {
		return null; //NOPValidity.SHARED_INSTANCE;
	}
	
	public void recycle() {
		super.recycle();
		this.userAgent = null;
		this.fop = null;
	}
	
	public boolean shouldSetContentLength() {
		return this.setContentLength;
	}
}
-------- snip ------------------------------------------------


Re: FOP 0.91 Serializer

Posted by Jean-Baptiste Quenot <jb...@apache.org>.
* Alexander Lochschmied:
> I would if I knew how..

Dear Alexander,

Your contribution is very interesting and we are likely to commit
it for the next release.

In order to file this contribution, you have first to create an
account on JIRA:

https://issues.apache.org/jira/secure/Signup!default.jspa

Once you have done that, submit the issue by going here:
https://issues.apache.org/jira/browse/COCOON
And click on CREATE NEW ISSUE

And don't forget to grant Apache the right to include your work by
checking the appropriate option when you attach the new file.

Thanks in advance,
-- 
Jean-Baptiste Quenot
http://caraldi.com/jbq/

RE: FOP 0.91 Serializer

Posted by Alexander Lochschmied <Al...@Vishay.com>.
I would if I knew how..

--Alexander

-----Original Message-----
From: Joerg Heinicke [mailto:joerg.heinicke@gmx.de] 
Sent: Dienstag, 7. März 2006 20:19
To: dev@cocoon.apache.org
Subject: Re: FOP 0.91 Serializer

Please add it to our issue tracker Jira at 
https://issues.apache.org/jira/browse/COCOON for organizational and 
especially legal reasons.

Thanks.

Jörg

On 07.03.2006 19:52, Alexander Lochschmied wrote:
> Hello everybody,
> 
> to get Apache FOP 0.91 beta working with Cocoon, a new Serializer is
> necessary (the FOP API changed considerably). I wrote a very simple but
> working Serializer and hope that helps a little for future releases of
> Cocoon. The Serializer doesn't accept any configuration except 'mime-type'
> yet.
> 
> Best regards,
> Alexander



Re: FOP 0.91 Serializer

Posted by Joerg Heinicke <jo...@gmx.de>.
Please add it to our issue tracker Jira at 
https://issues.apache.org/jira/browse/COCOON for organizational and 
especially legal reasons.

Thanks.

Jörg

On 07.03.2006 19:52, Alexander Lochschmied wrote:
> Hello everybody,
> 
> to get Apache FOP 0.91 beta working with Cocoon, a new Serializer is
> necessary (the FOP API changed considerably). I wrote a very simple but
> working Serializer and hope that helps a little for future releases of
> Cocoon. The Serializer doesn't accept any configuration except 'mime-type'
> yet.
> 
> Best regards,
> Alexander


Re: FOP 0.91 Serializer

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Just FYI, the FOP API will change slightly in the next release to
improve performance and reuse of reusable components. After the next
release the outer API will be considered stable. I was planning to write
a full FOP serializer (including all important features) for Cocoon when
the API is finalized. I assume this will happen within the next 4 to 5
weeks. However, I won't be unhappy if someone else writes the serializer.
Time constraints as usual. :-)

On 07.03.2006 19:52:28 Alexander Lochschmied wrote:
> Hello everybody,
> 
> to get Apache FOP 0.91 beta working with Cocoon, a new Serializer is
> necessary (the FOP API changed considerably). I wrote a very simple but
> working Serializer and hope that helps a little for future releases of
> Cocoon. The Serializer doesn't accept any configuration except 'mime-type'
> yet.
<snip/>


Jeremias Maerki