Browse Source

Created a new overloaded method Driver.render(InputHandler), simplifies internal calls to the Driver class by centralizing parser initialization and InputSource extraction.


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196746 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Glen Mazza 21 years ago
parent
commit
ed4a40351c

+ 1
- 10
src/java/org/apache/fop/apps/AWTStarter.java View File

@@ -62,9 +62,6 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Locale;

// SAX
import org.xml.sax.XMLReader;

/**
* AWT Viewer starter.
* Originally contributed by:
@@ -77,7 +74,6 @@ public class AWTStarter extends CommandLineStarter {
private PreviewDialog frame;
private Translator translator;
private Driver driver;
private XMLReader parser;

/**
* Construct an AWTStarter
@@ -103,11 +99,6 @@ public class AWTStarter extends CommandLineStarter {
renderer.setComponent(frame);
driver = new Driver();
driver.setRenderer(renderer);
parser = inputHandler.getParser();
if (parser == null) {
throw new FOPException("Unable to create SAX parser");
}
setParserFeatures(parser);
}

/**
@@ -118,7 +109,7 @@ public class AWTStarter extends CommandLineStarter {
driver.reset();
try {
frame.setStatus(translator.getString("Status.Build.FO.tree"));
driver.render(parser, inputHandler.getInputSource());
driver.render(inputHandler);
frame.setStatus(translator.getString("Status.Show"));
frame.showPage();
} catch (Exception e) {

+ 1
- 1
src/java/org/apache/fop/apps/CommandLineOptions.java View File

@@ -678,7 +678,7 @@ public class CommandLineOptions {
+ " see options with \"-print help\" \n\n"
+ " [Examples]\n" + " Fop foo.fo foo.pdf \n"
+ " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
+ " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n"
+ " Fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf\n"
+ " Fop foo.fo -mif foo.mif\n"
+ " Fop foo.fo -rtf foo.rtf\n"
+ " Fop foo.fo -print or Fop -print foo.fo \n"

+ 1
- 10
src/java/org/apache/fop/apps/CommandLineStarter.java View File

@@ -50,9 +50,6 @@
*/
package org.apache.fop.apps;

// SAX
import org.xml.sax.XMLReader;

// Java
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
@@ -85,15 +82,9 @@ public class CommandLineStarter extends Starter {
*/
public void run() throws FOPException {
String version = Version.getVersion();

getLogger().info(version);

XMLReader parser = inputHandler.getParser();
setParserFeatures(parser);

Driver driver = new Driver();
setupLogger(driver);
driver.initialize();

try {
driver.setRenderer(commandLineOptions.getRenderer());
@@ -105,7 +96,7 @@ public class CommandLineStarter extends Starter {
driver.getRenderer().setOptions(
commandLineOptions.getRendererOptions());
}
driver.render(parser, inputHandler.getInputSource());
driver.render(inputHandler);
} finally {
bos.close();
}

+ 13
- 0
src/java/org/apache/fop/apps/Driver.java View File

@@ -552,6 +552,19 @@ public class Driver implements LogEnabled {
return treeBuilder;
}

/**
* Render the FO document read by a SAX Parser from an InputHandler
* @param InputHandler the input handler containing the source and
* parser information.
* @throws FOPException if anything goes wrong.
*/
public synchronized void render(InputHandler inputHandler)
throws FOPException {
XMLReader parser = inputHandler.getParser();
inputHandler.setParserFeatures(parser);
render(parser, inputHandler.getInputSource());
}

/**
* Render the FO document read by a SAX Parser from an InputSource.
* @param parser the SAX parser.

+ 17
- 1
src/java/org/apache/fop/apps/InputHandler.java View File

@@ -136,6 +136,22 @@ public abstract class InputHandler {
* @throws FOPException if processing this InputHandler fails
*/
public abstract void run(Driver driver) throws FOPException;

/**
* Sets the parser features on an XMLReader
* @param parser XMLReader to set features on
* @throws FOPException if the XMLReader doesn't support the feature that
* need to be set
*/
public static void setParserFeatures(XMLReader parser) throws FOPException {
try {
parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
} catch (SAXException e) {
throw new FOPException("Error: You need a parser which allows the"
+ " http://xml.org/sax/features/namespace-prefixes"
+ " feature to be set to true to support namespaces", e);
}
}
}


+ 1
- 9
src/java/org/apache/fop/apps/PrintStarter.java View File

@@ -59,7 +59,6 @@ package org.apache.fop.apps;
* (apparently) redundant copies code, generally cleaned up, and
* added interfaces to the new Render API.
*/
import org.xml.sax.XMLReader;
import java.awt.print.PrinterJob;
import org.apache.fop.render.awt.AWTPrintRenderer;

@@ -88,13 +87,6 @@ public class PrintStarter extends CommandLineStarter {
public void run() throws FOPException {
Driver driver = new Driver();

String version = Version.getVersion();
//log.debug(version);

XMLReader parser = inputHandler.getParser();

setParserFeatures(parser);

PrinterJob pj = PrinterJob.getPrinterJob();
if (System.getProperty("dialog") != null) {
if (!pj.printDialog()) {
@@ -110,7 +102,7 @@ public class PrintStarter extends CommandLineStarter {

try {
driver.setRenderer(renderer);
driver.render(parser, inputHandler.getInputSource());
driver.render(inputHandler);
} catch (Exception e) {
if (e instanceof FOPException) {
throw (FOPException)e;

+ 0
- 21
src/java/org/apache/fop/apps/Starter.java View File

@@ -53,10 +53,6 @@ package org.apache.fop.apps;
// Avalon
import org.apache.avalon.framework.logger.AbstractLogEnabled;

// SAX
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;

/**
* Abstract super class.
* Creates a SAX Parser (defaulting to Xerces).
@@ -87,21 +83,4 @@ public abstract class Starter extends AbstractLogEnabled {
*/
public abstract void run() throws FOPException;

/**
* Sets the parser features on an XMLReader
* @param parser XMLReader to set features on
* @throws FOPException if the XMLReader doesn't support the feature that
* need to be set
*/
public void setParserFeatures(XMLReader parser) throws FOPException {
try {
parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
} catch (SAXException e) {
throw new FOPException("Error: You need a parser which allows the"
+ " http://xml.org/sax/features/namespace-prefixes"
+ " feature to be set to true to support namespaces", e);
}
}

}

+ 1
- 17
src/java/org/apache/fop/tools/TestConverter.java View File

@@ -70,8 +70,6 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;

/**
* TestConverter is used to process a set of tests specified in
@@ -287,12 +285,8 @@ public class TestConverter extends AbstractLogEnabled {
+ xsl));
}

XMLReader parser = inputHandler.getParser();
setParserFeatures(parser);

Driver driver = new Driver();
setupLogger(driver, "fop");
driver.initialize();
FOUserAgent userAgent = new FOUserAgent();
userAgent.setBaseURL(baseURL);
driver.setUserAgent(userAgent);
@@ -316,7 +310,7 @@ public class TestConverter extends AbstractLogEnabled {
new java.io.FileOutputStream(new File(destdir,
outname + (outputPDF ? ".pdf" : ".at.xml")))));
getLogger().debug("ddir:" + destdir + " on:" + outname + ".pdf");
driver.render(parser, inputHandler.getInputSource());
driver.render(inputHandler);

// check difference
if (compare != null) {
@@ -362,16 +356,6 @@ public class TestConverter extends AbstractLogEnabled {
return false;
}

private void setParserFeatures(XMLReader parser) throws FOPException {
try {
parser.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
} catch (SAXException e) {
throw new FOPException("Error in setting up parser feature namespace-prefixes\n"
+ "You need a parser which supports SAX version 2", e);
}
}

private Node locateResult(Node testcase, String id) {
NodeList cases = testcase.getChildNodes();
for (int count = 0; count < cases.getLength(); count++) {

+ 1
- 7
src/java/org/apache/fop/tools/anttasks/Fop.java View File

@@ -58,9 +58,6 @@ import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.util.GlobPatternMapper;

// SAX
import org.xml.sax.XMLReader;

// Java
import java.io.File;
import java.io.IOException;
@@ -463,8 +460,6 @@ class FOPTaskStarter extends Starter {
private void render(File foFile, File outFile,
int renderer) throws FOPException {
InputHandler inputHandler = new FOInputHandler(foFile);
XMLReader parser = inputHandler.getParser();
setParserFeatures(parser);

OutputStream out = null;
try {
@@ -480,14 +475,13 @@ class FOPTaskStarter extends Starter {
try {
Driver driver = new Driver();
setupLogger(driver);
driver.initialize();
FOUserAgent userAgent = new FOUserAgent();
userAgent.setBaseURL(this.baseURL);
userAgent.enableLogging(getLogger());
driver.setUserAgent(userAgent);
driver.setRenderer(renderer);
driver.setOutputStream(out);
driver.render(parser, inputHandler.getInputSource());
driver.render(inputHandler);
} catch (Exception ex) {
throw new BuildException(ex);
} finally {

Loading…
Cancel
Save