1 16 package org.outerj.daisy.books.publisher.impl.cocooncomponents; 17 18 import org.apache.cocoon.serialization.Serializer; 19 import org.outerj.daisy.xmlutil.XmlSerializer; 20 import org.xml.sax.SAXException ; 21 import org.xml.sax.Locator ; 22 import org.xml.sax.Attributes ; 23 import xslfo.FODocument; 24 25 import java.io.OutputStream ; 26 import java.io.IOException ; 27 import java.io.ByteArrayOutputStream ; 28 import java.io.ByteArrayInputStream ; 29 30 import xmlpdf.logging.Logger; 31 import xmlpdf.logging.Level; 32 33 41 public class IbexPdfSerializer implements Serializer { 42 private OutputStream outputStream; 43 private ByteArrayOutputStream buffer; 44 private XmlSerializer xmlSerializer; 45 46 public void setOutputStream(OutputStream outputStream) throws IOException { 47 Logger.getLogger().setLevel(Level.INFO); 48 this.outputStream = outputStream; 49 this.buffer = new ByteArrayOutputStream (30000); 50 try { 51 this.xmlSerializer = new XmlSerializer(buffer); 52 } catch (Exception e) { 53 throw new IOException ("Error initialiasing xml serializer: " + e.toString()); 54 } 55 } 56 57 public String getMimeType() { 58 return null; 59 } 60 61 public boolean shouldSetContentLength() { 62 return true; 63 } 64 65 private void generatePdf() { 66 FODocument foDocument = new FODocument(); 67 try { 68 foDocument.generate(new ByteArrayInputStream (buffer.toByteArray()), outputStream, true); 69 } catch (Throwable e) { 70 e.printStackTrace(); 71 throw new RuntimeException ("Error calling ibex", e); 72 } 73 } 74 75 public void endDocument() throws SAXException { 76 xmlSerializer.endDocument(); 77 generatePdf(); 78 } 79 80 public void startDocument() throws SAXException { 81 xmlSerializer.startDocument(); 82 } 83 84 public void characters(char ch[], int start, int length) throws SAXException { 85 xmlSerializer.characters(ch, start, length); 86 } 87 88 public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { 89 xmlSerializer.ignorableWhitespace(ch, start, length); 90 } 91 92 public void endPrefixMapping(String prefix) throws SAXException { 93 xmlSerializer.endPrefixMapping(prefix); 94 } 95 96 public void skippedEntity(String name) throws SAXException { 97 xmlSerializer.skippedEntity(name); 98 } 99 100 public void setDocumentLocator(Locator locator) { 101 } 103 104 public void processingInstruction(String target, String data) throws SAXException { 105 xmlSerializer.processingInstruction(target, data); 106 } 107 108 public void startPrefixMapping(String prefix, String uri) throws SAXException { 109 xmlSerializer.startPrefixMapping(prefix, uri); 110 } 111 112 public void endElement(String namespaceURI, String localName, String qName) throws SAXException { 113 xmlSerializer.endElement(namespaceURI, localName, qName); 114 } 115 116 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { 117 xmlSerializer.startElement(namespaceURI, localName, qName, atts); 118 } 119 120 public void endCDATA() throws SAXException { 121 } 123 124 public void endDTD() throws SAXException { 125 } 127 128 public void startCDATA() throws SAXException { 129 } 131 132 public void comment(char ch[], int start, int length) throws SAXException { 133 } 135 136 public void endEntity(String name) throws SAXException { 137 } 139 140 public void startEntity(String name) throws SAXException { 141 } 143 144 public void startDTD(String name, String publicId, String systemId) throws SAXException { 145 } 147 } 148 | Popular Tags |