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