1 package com.icl.saxon.fop; 2 import com.icl.saxon.output.ContentHandlerProxy; 3 import org.xml.sax.Attributes ; 4 import org.xml.sax.ContentHandler ; 5 import javax.xml.transform.TransformerException ; 6 import org.apache.fop.apps.Driver; 7 import org.apache.fop.apps.Options; 8 import org.apache.fop.apps.FOPException; 9 import java.util.Properties ; 10 import java.io.File ; 11 12 20 21 public class FOPEmitter extends ContentHandlerProxy 22 { 23 public static String FOP_RENDERER = "{http://icl.com/saxon/fop}renderer"; 24 public static String FOP_CONFIGURATION = "{http://icl.com/saxon/fop}configuration"; 25 26 private Driver fop; 27 28 32 33 public boolean usesWriter() { 34 return false; 35 } 36 37 40 41 public void startDocument() throws TransformerException { 42 fop = new Driver(); 43 44 ContentHandler ch = fop.getContentHandler(); 45 46 Properties props = getOutputProperties(); 47 String renderer = props.getProperty(FOP_RENDERER); 48 if (renderer == null) { 49 fop.setRenderer(Driver.RENDER_PDF); 50 } else { 51 fop.setRenderer(renderer); 52 } 53 ((org.apache.fop.fo.FOTreeBuilder)ch).setStreamRenderer( 55 new org.apache.fop.apps.StreamRenderer(outputStream, fop.getRenderer())); 56 57 String options = props.getProperty(FOP_CONFIGURATION); 58 if (options != null) { 59 try { 60 System.setProperty("org.xml.sax.parser", "com.icl.saxon.aelfred.SAXDriver"); 61 Options fopOptions = new Options(new File (options)); 62 } catch (org.apache.fop.apps.FOPException err) { 64 throw new TransformerException (err); 65 } 66 } 67 68 setUnderlyingContentHandler(ch); 69 super.startDocument(); 70 } 71 72 75 76 public void endDocument() throws TransformerException { 77 super.endDocument(); 78 } 91 92 } 93 94 | Popular Tags |