Browse Source

Make more dummy-safe (more verbose error messages).

Reintroduce setLogger() method from maint-branch (deprecated, for backwards-compatibility)


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196489 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Jeremias Maerki 21 years ago
parent
commit
1dc451b8b4
1 changed files with 34 additions and 4 deletions
  1. 34
    4
      src/java/org/apache/fop/apps/Driver.java

+ 34
- 4
src/java/org/apache/fop/apps/Driver.java View File

@@ -261,11 +261,17 @@ public class Driver implements LogEnabled {
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();
@@ -305,6 +311,15 @@ public class Driver implements LogEnabled {
}
}

/**
* 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.
@@ -349,6 +364,12 @@ public class Driver implements LogEnabled {
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.
@@ -553,10 +574,10 @@ public class Driver implements LogEnabled {
* @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.
@@ -588,6 +609,9 @@ public class Driver implements LogEnabled {
*/
public synchronized void render(XMLReader parser, InputSource source)
throws FOPException {
if (!isInitialized()) {
initialize();
}
parser.setContentHandler(getContentHandler());
try {
parser.parse(source);
@@ -610,6 +634,9 @@ public class Driver implements LogEnabled {
*/
public synchronized void render(Document document)
throws FOPException {
if (!isInitialized()) {
initialize();
}
try {
DocumentInputSource source = new DocumentInputSource(document);
DocumentReader reader = new DocumentReader();
@@ -638,6 +665,9 @@ public class Driver implements LogEnabled {
* @throws FOPException if anything else goes wrong.
*/
public synchronized void run() throws IOException, FOPException {
if (!isInitialized()) {
initialize();
}
if (renderer == null) {
setRenderer(RENDER_PDF);
}

Loading…
Cancel
Save