aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/apps/Fop.java
diff options
context:
space:
mode:
authorGlen Mazza <gmazza@apache.org>2004-07-24 05:47:45 +0000
committerGlen Mazza <gmazza@apache.org>2004-07-24 05:47:45 +0000
commit3bcfed2d9b7e68e4bfcf6738bf5c9a28063d59d5 (patch)
tree9b75a0917ed78fffc5ee848e06ab5bba3315d0b1 /src/java/org/apache/fop/apps/Fop.java
parent7796f1b60829f28d3173b658871cd0fa46d4c258 (diff)
downloadxmlgraphics-fop-3bcfed2d9b7e68e4bfcf6738bf5c9a28063d59d5.tar.gz
xmlgraphics-fop-3bcfed2d9b7e68e4bfcf6738bf5c9a28063d59d5.zip
Combined the apps.Driver class into apps.Fop. (195 LOC total.) Primary
benefit is to make Fop self-documenting in external code, also none of the API ideas called for retention of the Driver class (even if there were different ideas for its replacement). Let's try this for a few weeks, if it confuses people too much (or when the API starts to grow again) we can bring back Driver, possibly under a different name, apps.FopProcess, perhaps. See also: http://marc.theaimsgroup.com/?l=fop-dev&m=108947697611032&w=2 http://marc.theaimsgroup.com/?l=fop-dev&m=108966015504506&w=2 http://marc.theaimsgroup.com/?l=fop-dev&m=108942673103344&w=2 http://marc.theaimsgroup.com/?l=fop-dev&m=108958756030147&w=2 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197827 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/apps/Fop.java')
-rw-r--r--src/java/org/apache/fop/apps/Fop.java112
1 files changed, 104 insertions, 8 deletions
diff --git a/src/java/org/apache/fop/apps/Fop.java b/src/java/org/apache/fop/apps/Fop.java
index dfdf2e6fb..a80647f0d 100644
--- a/src/java/org/apache/fop/apps/Fop.java
+++ b/src/java/org/apache/fop/apps/Fop.java
@@ -21,15 +21,112 @@ package org.apache.fop.apps;
// Java
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
+import java.io.OutputStream;
-// FOP
-import org.apache.fop.render.awt.AWTRenderer;
+// XML
+import org.xml.sax.helpers.DefaultHandler;
+// FOP
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.FOTreeBuilder;
/**
- * The main application class for the FOP command line interface (CLI).
+ * Primary class that activates the FOP process for both command line
+ * and embedded usage.
+ * <P>
+ * JAXP is the standard method of embedding FOP in Java programs.
+ * Please check our embedding page (http://xml.apache.org/fop/embedding.html)
+ * for samples (these are also available within the distribution in
+ * FOP_DIR\examples\embedding)
+ * <P>
+ * Methods within FOUserAgent are available to customize portions of the
+ * process. For example, a specific Renderer object can be specified,
+ * also ElementMappings which determine elements in the FO that can be
+ * processed) can be added.
*/
-public class Fop {
+public class Fop implements Constants {
+
+ // desired output type: RENDER_PDF, RENDER_PS, etc.
+ private int renderType = NOT_SET;
+
+ // output stream to send results to
+ private OutputStream stream = null;
+
+ // FOUserAgent object to set processing options
+ private FOUserAgent foUserAgent = null;
+
+ /**
+ * Constructor for use with already-created FOUserAgents
+ * @param renderType the type of renderer to use. Must be one of
+ * <ul>
+ * <li>Fop.RENDER_PDF</li>
+ * <li>Fop.RENDER_AWT</li>
+ * <li>Fop.RENDER_PRINT</li>
+ * <li>Fop.RENDER_MIF</li>
+ * <li>Fop.RENDER_XML</li>
+ * <li>Fop.RENDER_PCL</li>
+ * <li>Fop.RENDER_PS</li>
+ * <li>Fop.RENDER_TXT</li>
+ * <li>Fop.RENDER_SVG</li>
+ * <li>Fop.RENDER_RTF</li>
+ * </ul>
+ * @param ua FOUserAgent object
+ * @throws IllegalArgumentException if an unsupported renderer type was requested.
+ */
+ public Fop(int renderType, FOUserAgent ua) {
+ if (renderType < Constants.RENDER_MIN_CONST
+ || renderType > Constants.RENDER_MAX_CONST) {
+ throw new IllegalArgumentException(
+ "Invalid render type #" + renderType);
+ }
+
+ this.renderType = renderType;
+
+ foUserAgent = ua;
+ if (foUserAgent == null) {
+ foUserAgent = new FOUserAgent();
+ }
+ }
+
+ /**
+ * Constructor that creates a default FOUserAgent
+ * @see org.apache.fop.apps.Fop#(int, FOUserAgent)
+ */
+ public Fop(int renderType) {
+ this(renderType, new FOUserAgent());
+ }
+
+ /**
+ * Get the FOUserAgent instance for this process
+ * @return the user agent
+ */
+ public FOUserAgent getUserAgent() {
+ return foUserAgent;
+ }
+
+ /**
+ * Set the OutputStream to use to output the result of the Render
+ * (if applicable)
+ * @param stream the stream to output the result of rendering to
+ */
+ public void setOutputStream(OutputStream stream) {
+ this.stream = stream;
+ }
+
+ /**
+ * Returns a DefaultHandler object used to generate the document.
+ * Note this object implements the ContentHandler interface.
+ * For processing with a Transformer object, this DefaultHandler object
+ * can be used in the SAXResult constructor.
+ * Alternatively, for processing with a SAXParser, this object can be
+ * used as the DefaultHandler argument to its parse() methods.
+ *
+ * @return a SAX DefaultHandler for handling the SAX events.
+ * @throws FOPException if setting up the DefaultHandler fails
+ */
+ public DefaultHandler getDefaultHandler() throws FOPException {
+ return new FOTreeBuilder(renderType, foUserAgent, stream);
+ }
/**
* The main routine for the command line interface
@@ -44,15 +141,15 @@ public class Fop {
options = new CommandLineOptions(args);
foUserAgent = options.getFOUserAgent();
- Driver driver = new Driver(options.getRenderer(), foUserAgent);
+ Fop fop = new Fop(options.getRenderer(), foUserAgent);
try {
if (options.getOutputFile() != null) {
bos = new BufferedOutputStream(new FileOutputStream(
options.getOutputFile()));
- driver.setOutputStream(bos);
+ fop.setOutputStream(bos);
}
- foUserAgent.getInputHandler().render(driver);
+ foUserAgent.getInputHandler().render(fop);
} finally {
if (bos != null) {
bos.close();
@@ -96,4 +193,3 @@ public class Fop {
return "1.0dev";
}
}
-