// FOP
import org.apache.fop.fo.Constants;
import org.apache.fop.fo.FOTreeBuilder;
-import org.apache.fop.render.awt.AWTRenderer;
/**
* Primary class that drives the overall FOP process.
* use and the OutputStream to use to output the results of the
* rendering (where applicable).
* <P>
- * Once the Driver is set up, the render method
- * is called. The invocation of the method is
- * render(Parser, InputSource).
- * <P>
* Here is an example use of Driver which outputs to AWT:
*
* <PRE>
/**
* the stream to use to output the results of the renderer
*/
- private OutputStream stream;
+ private OutputStream stream = null;
/**
* The system resources that FOP will use
*/
public Driver() {
foUserAgent = new FOUserAgent();
- stream = null;
- }
-
- /**
- * Constructor for AWTRenderer, which reuses the
- * same renderer instance for document reloading
- */
- public Driver(AWTRenderer render) {
- this();
- renderType = RENDER_AWT;
- foUserAgent = render.getUserAgent();
}
/**
}
/**
- * Resets the Driver so it can be reused. Property and element
- * mappings are reset to defaults.
- * The output stream is cleared. The renderer is cleared.
+ * Constructor with FOUserAgent
+ * Used by CLI, AWTRenderer
*/
- public synchronized void reset() {
- stream = null;
+ public Driver(FOUserAgent ua) {
+ foUserAgent = ua;
}
/**
this.stream = stream;
}
- private void validateOutputStream() {
- if (this.stream == null) {
- throw new IllegalStateException("OutputStream has not been set");
- }
- }
-
/**
* Method to set the rendering type desired. Must be one of
* <ul>
* @throws FOPException if setting up the ContentHandler fails
*/
public ContentHandler getContentHandler() throws FOPException {
-
- if (renderType != RENDER_PRINT && renderType != RENDER_AWT) {
- validateOutputStream();
- }
-
return new FOTreeBuilder(renderType, foUserAgent, stream);
}
BufferedOutputStream bos = null;
try {
- Driver driver = new Driver();
options = new CommandLineOptions(args);
-
foUserAgent = options.getFOUserAgent();
- driver.setUserAgent(foUserAgent);
+
+ Driver driver = new Driver(foUserAgent);
driver.setRenderer(options.getRenderer());
try {
*/
public FOTreeBuilder(int renderType, FOUserAgent foUserAgent,
OutputStream stream) throws FOPException {
+
+ if (renderType != Constants.RENDER_PRINT &&
+ renderType != Constants.RENDER_AWT) {
+ if (stream == null) {
+ throw new IllegalStateException(
+ "OutputStream has not been set");
+ }
+ }
+
if (renderType == Constants.RENDER_MIF) {
foInputHandler = new MIFHandler(foUserAgent, stream);
} else if (renderType == Constants.RENDER_RTF) {
public void setUserAgent(FOUserAgent foUserAgent) {
super.setUserAgent(foUserAgent);
- createPreviewDialog(foUserAgent.getInputHandler());
+ userAgent.setRendererOverride(this); // for document regeneration
+ createPreviewDialog();
}
public FOUserAgent getUserAgent() {
return 0;
}
- private PreviewDialog createPreviewDialog(InputHandler handler) {
- frame = new PreviewDialog(this, handler);
+ private PreviewDialog createPreviewDialog() {
+ frame = new PreviewDialog(userAgent);
frame.addWindowListener(new WindowAdapter() {
public void windowClosed(WindowEvent we) {
System.exit(0);
//FOP
import org.apache.fop.apps.Driver;
-import org.apache.fop.apps.InputHandler;
+import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.Constants;
import org.apache.fop.render.awt.AWTRenderer;
/**
protected Translator translator;
/** The AWT renderer */
protected AWTRenderer renderer;
- /** The InputHandler associated with this window */
- protected InputHandler inputHandler;
+ /** The FOUserAgent associated with this window */
+ protected FOUserAgent foUserAgent;
/** The Driver used for refreshing/reloading the view */
protected Driver driver;
* Creates a new PreviewDialog that uses the given renderer.
* @param aRenderer the to use renderer
*/
- public PreviewDialog(AWTRenderer aRenderer, InputHandler handler) {
- renderer = aRenderer;
- inputHandler = handler;
+ public PreviewDialog(FOUserAgent foUserAgent) {
+ renderer = (AWTRenderer) foUserAgent.getRendererOverride();
+ this.foUserAgent = foUserAgent;
translator = renderer.getTranslator();
//Commands aka Actions
}
});
// inputHandler must be set to allow reloading
- if (inputHandler != null) {
+ if (foUserAgent.getInputHandler() != null) {
menu.add(new Command(translator.getString("Menu.Reload")) {
public void doit() {
reload();
private class Reloader extends Thread {
public void run() {
if (driver == null) {
- driver = new Driver(renderer);
- } else {
- driver.reset();
+ driver = new Driver(foUserAgent);
+ driver.setRenderer(Constants.RENDER_AWT);
}
pageLabel.setIcon(null);
try {
setStatus(translator.getString("Status.Build.FO.tree"));
- driver.render(inputHandler);
+ driver.render(foUserAgent.getInputHandler());
setStatus(translator.getString("Status.Show"));
} catch (FOPException e) {
reportException(e);
} else {
inputHandler = new XSLTInputHandler(xmlFile,
new File(baseDir + "/"
- + xsl), null);
+ + xsl));
}
Driver driver = new Driver();