this.stream = stream;
}
+ private boolean isInitialized() {
+ return (treeBuilder != null);
+ }
+
/**
* Initializes the Driver object.
*/
public void initialize() {
- stream = null;
+ if (isInitialized()) {
+ throw new IllegalStateException("Driver already initialized");
+ }
treeBuilder = new FOTreeBuilder();
treeBuilder.setUserAgent(getUserAgent());
setupDefaultMappings();
}
}
+ /**
+ * Provide the Driver instance with a logger.
+ * @param log the logger. Must not be <code>null</code>.
+ * @deprecated Use #enableLogging(Logger) instead.
+ */
+ public void setLogger(Logger log) {
+ enableLogging(log);
+ }
+
/**
* Returns the logger for use by FOP.
this.stream = stream;
}
+ private void validateOutputStream() {
+ if (this.stream == null) {
+ throw new IllegalStateException("OutputStream has not been set");
+ }
+ }
+
/**
* Set the source for the FO document. This can be a normal SAX
* InputSource, or an DocumentInputSource containing a DOM document.
* @return a content handler for handling the SAX events.
*/
public ContentHandler getContentHandler() {
- if (treeBuilder == null) {
- throw new NullPointerException("Driver isn't initialized. "
- + "You may have to call initialize() first.");
+ if (!isInitialized()) {
+ initialize();
}
+ validateOutputStream();
// TODO: - do this stuff in a better way
// PIJ: I guess the structure handler should be created by the renderer.
*/
public synchronized void render(XMLReader parser, InputSource source)
throws FOPException {
+ if (!isInitialized()) {
+ initialize();
+ }
parser.setContentHandler(getContentHandler());
try {
parser.parse(source);
*/
public synchronized void render(Document document)
throws FOPException {
+ if (!isInitialized()) {
+ initialize();
+ }
try {
DocumentInputSource source = new DocumentInputSource(document);
DocumentReader reader = new DocumentReader();
* @throws FOPException if anything else goes wrong.
*/
public synchronized void run() throws IOException, FOPException {
+ if (!isInitialized()) {
+ initialize();
+ }
if (renderer == null) {
setRenderer(RENDER_PDF);
}