KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > publisher > impl > cocooncomponents > IbexPdfSerializer


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

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 JavaDoc;
21 import org.xml.sax.Locator JavaDoc;
22 import org.xml.sax.Attributes JavaDoc;
23 import xslfo.FODocument;
24
25 import java.io.OutputStream JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.io.ByteArrayOutputStream JavaDoc;
28 import java.io.ByteArrayInputStream JavaDoc;
29
30 import xmlpdf.logging.Logger;
31 import xmlpdf.logging.Level;
32
33 /**
34  * An XSL-FO to PDF serializer for Cocoon that uses the commerical IBEX xslfo engine
35  * from <a HREF="http://www.xmlpdf.com">http://www.xmlpdf.com</a>.
36  *
37  * <p><b>IMPORTANT: DO NOT USE THIS SERIALIZER in the Daisy Wiki because it would interfere
38  * with the {@link org.outerj.daisy.books.publisher.impl.publicationprocess.MakePdfTask}
39  * which assumes exclusive use of Ibex.</b>
40  */

41 public class IbexPdfSerializer implements Serializer {
42     private OutputStream JavaDoc outputStream;
43     private ByteArrayOutputStream JavaDoc buffer;
44     private XmlSerializer xmlSerializer;
45
46     public void setOutputStream(OutputStream JavaDoc outputStream) throws IOException JavaDoc {
47         Logger.getLogger().setLevel(Level.INFO);
48         this.outputStream = outputStream;
49         this.buffer = new ByteArrayOutputStream JavaDoc(30000);
50         try {
51             this.xmlSerializer = new XmlSerializer(buffer);
52         } catch (Exception JavaDoc e) {
53             throw new IOException JavaDoc("Error initialiasing xml serializer: " + e.toString());
54         }
55     }
56
57     public String JavaDoc 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 JavaDoc(buffer.toByteArray()), outputStream, true);
69         } catch (Throwable JavaDoc e) {
70             e.printStackTrace();
71             throw new RuntimeException JavaDoc("Error calling ibex", e);
72         }
73     }
74
75     public void endDocument() throws SAXException JavaDoc {
76         xmlSerializer.endDocument();
77         generatePdf();
78     }
79
80     public void startDocument() throws SAXException JavaDoc {
81         xmlSerializer.startDocument();
82     }
83
84     public void characters(char ch[], int start, int length) throws SAXException JavaDoc {
85         xmlSerializer.characters(ch, start, length);
86     }
87
88     public void ignorableWhitespace(char ch[], int start, int length) throws SAXException JavaDoc {
89         xmlSerializer.ignorableWhitespace(ch, start, length);
90     }
91
92     public void endPrefixMapping(String JavaDoc prefix) throws SAXException JavaDoc {
93         xmlSerializer.endPrefixMapping(prefix);
94     }
95
96     public void skippedEntity(String JavaDoc name) throws SAXException JavaDoc {
97         xmlSerializer.skippedEntity(name);
98     }
99
100     public void setDocumentLocator(Locator JavaDoc locator) {
101         // ignore
102
}
103
104     public void processingInstruction(String JavaDoc target, String JavaDoc data) throws SAXException JavaDoc {
105         xmlSerializer.processingInstruction(target, data);
106     }
107
108     public void startPrefixMapping(String JavaDoc prefix, String JavaDoc uri) throws SAXException JavaDoc {
109         xmlSerializer.startPrefixMapping(prefix, uri);
110     }
111
112     public void endElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName) throws SAXException JavaDoc {
113         xmlSerializer.endElement(namespaceURI, localName, qName);
114     }
115
116     public void startElement(String JavaDoc namespaceURI, String JavaDoc localName, String JavaDoc qName, Attributes JavaDoc atts) throws SAXException JavaDoc {
117         xmlSerializer.startElement(namespaceURI, localName, qName, atts);
118     }
119
120     public void endCDATA() throws SAXException JavaDoc {
121         // ignore
122
}
123
124     public void endDTD() throws SAXException JavaDoc {
125         // ignore
126
}
127
128     public void startCDATA() throws SAXException JavaDoc {
129         // ignore
130
}
131
132     public void comment(char ch[], int start, int length) throws SAXException JavaDoc {
133         // ignore
134
}
135
136     public void endEntity(String JavaDoc name) throws SAXException JavaDoc {
137         // ignore
138
}
139
140     public void startEntity(String JavaDoc name) throws SAXException JavaDoc {
141         // ignore
142
}
143
144     public void startDTD(String JavaDoc name, String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc {
145         // ignore
146
}
147 }
148
Popular Tags