aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/apps
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/apache/fop/apps')
-rw-r--r--src/org/apache/fop/apps/AWTStarter.java8
-rw-r--r--src/org/apache/fop/apps/CommandLineStarter.java2
-rw-r--r--src/org/apache/fop/apps/Driver.java48
-rw-r--r--src/org/apache/fop/apps/PrintStarter.java60
-rw-r--r--src/org/apache/fop/apps/StreamRenderer.java470
5 files changed, 288 insertions, 300 deletions
diff --git a/src/org/apache/fop/apps/AWTStarter.java b/src/org/apache/fop/apps/AWTStarter.java
index 1bf2b4c86..c956da97f 100644
--- a/src/org/apache/fop/apps/AWTStarter.java
+++ b/src/org/apache/fop/apps/AWTStarter.java
@@ -57,7 +57,7 @@ public class AWTStarter extends CommandLineStarter {
private Translator resource;
public AWTStarter(CommandLineOptions commandLineOptions)
- throws FOPException {
+ throws FOPException {
super(commandLineOptions);
init();
}
@@ -78,8 +78,8 @@ public class AWTStarter extends CommandLineStarter {
+ language);
UserMessage.setTranslator(getResourceBundle(TRANSLATION_PATH
- + "messages."
- + language));
+ + "messages."
+ + language));
resource.setMissingEmphasized(false);
renderer = new AWTRenderer(resource);
@@ -127,7 +127,7 @@ public class AWTStarter extends CommandLineStarter {
}
protected PreviewDialog createPreviewDialog(AWTRenderer renderer,
- Translator res) {
+ Translator res) {
PreviewDialog frame = new PreviewDialog(renderer, res);
frame.validate();
diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java
index 1f56c738e..556be58ce 100644
--- a/src/org/apache/fop/apps/CommandLineStarter.java
+++ b/src/org/apache/fop/apps/CommandLineStarter.java
@@ -34,7 +34,7 @@ public class CommandLineStarter extends Starter {
boolean errorDump;
public CommandLineStarter(CommandLineOptions commandLineOptions)
- throws FOPException {
+ throws FOPException {
this.commandLineOptions = commandLineOptions;
options.setCommandLineOptions(commandLineOptions);
errorDump = Configuration.getBooleanValue("debugMode").booleanValue();
diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java
index 4af65b07e..0b593a56c 100644
--- a/src/org/apache/fop/apps/Driver.java
+++ b/src/org/apache/fop/apps/Driver.java
@@ -171,6 +171,7 @@ public class Driver {
try {
parserClassName = System.getProperty("org.xml.sax.parser");
} catch (SecurityException se) {}
+
if (parserClassName == null) {
parserClassName = "org.apache.xerces.parsers.SAXParser";
}
@@ -261,6 +262,7 @@ public class Driver {
try {
addElementMapping(str);
} catch (IllegalArgumentException e) {}
+
}
}
}
@@ -338,7 +340,7 @@ public class Driver {
* @see #setRenderer(int)
*/
public void setRenderer(String rendererClassName)
- throws IllegalArgumentException {
+ throws IllegalArgumentException {
try {
_renderer =
(Renderer)Class.forName(rendererClassName).newInstance();
@@ -346,13 +348,16 @@ public class Driver {
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ rendererClassName);
- } catch (InstantiationException e) {
+ }
+ catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ rendererClassName);
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ rendererClassName);
- } catch (ClassCastException e) {
+ }
+ catch (ClassCastException e) {
throw new IllegalArgumentException(rendererClassName
+ " is not a renderer");
}
@@ -372,7 +377,7 @@ public class Driver {
* add the element mapping with the given class name
*/
public void addElementMapping(String mappingClassName)
- throws IllegalArgumentException {
+ throws IllegalArgumentException {
try {
ElementMapping mapping =
(ElementMapping)Class.forName(mappingClassName).newInstance();
@@ -380,13 +385,16 @@ public class Driver {
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ mappingClassName);
- } catch (InstantiationException e) {
+ }
+ catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ mappingClassName);
- } catch (IllegalAccessException e) {
+ }
+ catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ mappingClassName);
- } catch (ClassCastException e) {
+ }
+ catch (ClassCastException e) {
throw new IllegalArgumentException(mappingClassName
+ " is not an ElementMapping");
}
@@ -408,7 +416,7 @@ public class Driver {
* SAX InputSource
*/
public synchronized void render(XMLReader parser, InputSource source)
- throws FOPException {
+ throws FOPException {
StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer);
_treeBuilder.setStreamRenderer(streamRenderer);
parser.setContentHandler(_treeBuilder);
@@ -420,7 +428,8 @@ public class Driver {
} else {
throw new FOPException(e);
}
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new FOPException(e);
}
}
@@ -429,10 +438,10 @@ public class Driver {
* Build the formatting object tree using the given DOM Document
*/
public synchronized void render(Document document)
- throws FOPException {
+ throws FOPException {
StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer);
_treeBuilder.setStreamRenderer(streamRenderer);
-
+
try {
DocumentInputSource source = new DocumentInputSource(document);
DocumentReader reader = new DocumentReader();
@@ -440,7 +449,8 @@ public class Driver {
reader.parse(source);
} catch (SAXException e) {
throw new FOPException(e);
- } catch (IOException e) {
+ }
+ catch (IOException e) {
throw new FOPException(e);
}
@@ -473,7 +483,7 @@ public class Driver {
this._bufferManager.addBufferFile(bufferFile);
}
- /**
+ /**
* Runs the formatting and renderering process using the previously set
* inputsource and outputstream
*/
@@ -481,17 +491,17 @@ public class Driver {
if (_renderer == null) {
setRenderer(RENDER_PDF);
}
-
+
if (_source == null) {
throw new FOPException("InputSource is not set.");
}
-
+
if (_reader == null) {
if (!(_source instanceof DocumentInputSource)) {
_reader = ConfigurationReader.createParser();
}
}
-
+
if (_source instanceof DocumentInputSource) {
render(((DocumentInputSource)_source).getDocument());
} else {
@@ -549,7 +559,7 @@ class Service {
if (idx != -1)
line = line.substring(0, idx);
- // Trim whitespace.
+ // Trim whitespace.
line = line.trim();
// If nothing left then loop around...
@@ -566,11 +576,13 @@ class Service {
} catch (Exception ex) {
// Just try the next line
}
+
line = br.readLine();
}
} catch (Exception ex) {
// Just try the next file...
}
+
}
return v.elements();
}
diff --git a/src/org/apache/fop/apps/PrintStarter.java b/src/org/apache/fop/apps/PrintStarter.java
index 7cf2636e2..f3c039f64 100644
--- a/src/org/apache/fop/apps/PrintStarter.java
+++ b/src/org/apache/fop/apps/PrintStarter.java
@@ -68,15 +68,15 @@ public class PrintStarter extends CommandLineStarter {
PrinterJob pj = PrinterJob.getPrinterJob();
if(System.getProperty("dialog") != null)
- if(!pj.printDialog())
- throw new FOPException("Printing cancelled by operator");
-
+ if(!pj.printDialog())
+ throw new FOPException("Printing cancelled by operator");
+
PrintRenderer renderer = new PrintRenderer(pj);
int copies = getIntProperty("copies", 1);
pj.setCopies(copies);
-
+
//renderer.setCopies(copies);
-
+
try {
driver.setRenderer(renderer);
driver.render(parser, inputHandler.getInputSource());
@@ -88,16 +88,16 @@ public class PrintStarter extends CommandLineStarter {
}
System.exit(0);
- }
- int getIntProperty(String name, int def) {
- String propValue = System.getProperty(name);
- if(propValue != null) {
+ }
+ int getIntProperty(String name, int def) {
+ String propValue = System.getProperty(name);
+ if(propValue != null) {
try {
- return Integer.parseInt(propValue);
+ return Integer.parseInt(propValue);
} catch (Exception e) {
- return def;
+ return def;
}
- } else {
+ } else {
return def;
}
}
@@ -113,7 +113,7 @@ public class PrintStarter extends CommandLineStarter {
private int mode = EVEN_AND_ALL;
private int copies = 1;
private PrinterJob printerJob;
-
+
PrintRenderer(PrinterJob printerJob) {
super(null);
@@ -129,33 +129,31 @@ public class PrintStarter extends CommandLineStarter {
try {
mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD;
} catch (Exception e) {}
+
}
}
- public void stopRenderer(OutputStream outputStream)
- throws IOException
- {
- super.stopRenderer(outputStream);
-
- if(endNumber == -1)
- endNumber = getPageCount();
-
+ public void stopRenderer(OutputStream outputStream)
+ throws IOException {
+ super.stopRenderer(outputStream);
+
+ if(endNumber == -1)
+ endNumber = getPageCount();
+
Vector numbers = getInvalidPageNumbers();
for (int i = numbers.size() - 1; i > -1; i--)
removePage(Integer.parseInt((String)numbers.elementAt(i)));
try {
- printerJob.print();
- }
- catch (PrinterException e)
- {
- e.printStackTrace();
- throw new IOException(
- "Unable to print: " + e.getClass().getName() +
- ": " + e.getMessage());
+ printerJob.print();
+ } catch (PrinterException e) {
+ e.printStackTrace();
+ throw new IOException(
+ "Unable to print: " + e.getClass().getName() +
+ ": " + e.getMessage());
}
}
@@ -197,8 +195,8 @@ public class PrintStarter extends CommandLineStarter {
tree.getPages().addAll(copie);
}
- }
- */
+ }
+ */
} // class PrintRenderer
} // class PrintCommandLine
diff --git a/src/org/apache/fop/apps/StreamRenderer.java b/src/org/apache/fop/apps/StreamRenderer.java
index e36b6e599..899e874b8 100644
--- a/src/org/apache/fop/apps/StreamRenderer.java
+++ b/src/org/apache/fop/apps/StreamRenderer.java
@@ -22,275 +22,253 @@ import org.apache.fop.messaging.MessageHandler;
PageSequences up until all the IDs required by them
are satisfied, at which time it will render the
pages.<P>
-
+
StreamRenderer is created by Driver and called from
FOTreeBuilder when a PageSequence is created,
and AreaTree when a Page is formatted.<P>
*/
-public class StreamRenderer extends Object
-{
- private static final boolean MEM_PROFILE_WITH_GC = false;
-
- /**
- Somewhere to get our stats from.
- */
- private Runtime runtime = Runtime.getRuntime();
-
- /**
- Keep track of the number of pages rendered.
- */
- int pageCount = 0;
-
- /**
- Keep track of heap memory allocated,
- for statistical purposes.
- */
- private long initialMemory;
-
- /**
- Keep track of time used by renderer.
- */
- private long startTime;
-
- /**
- The stream to which this rendering is to be
- written to. <B>Note</B> that some renderers
- do not render to a stream, and that this
- member can therefore be null.
- */
- private OutputStream outputStream;
-
- /**
- The renderer being used.
- */
- private Renderer renderer;
-
- /**
- The FontInfo for this renderer.
- */
- private FontInfo fontInfo = new FontInfo();
-
- /**
- The list of pages waiting to be renderered.
- */
- private Vector renderQueue = new Vector();
-
- /**
- The current set of IDReferences, passed to the
- areatrees and pages. This is used by the AreaTree
- as a single map of all IDs.
- */
- private IDReferences idReferences = new IDReferences();
-
- public StreamRenderer(OutputStream outputStream, Renderer renderer)
- {
- this.outputStream = outputStream;
- this.renderer = renderer;
- }
-
- public IDReferences getIDReferences()
- {
- return idReferences;
- }
-
- public void startRenderer()
- throws SAXException
- {
- pageCount = 0;
-
- if (MEM_PROFILE_WITH_GC)
- System.gc(); // This takes time but gives better results
-
- initialMemory = runtime.totalMemory() - runtime.freeMemory();
- startTime = System.currentTimeMillis();
-
- try {
- renderer.setupFontInfo(fontInfo);
- renderer.startRenderer(outputStream);
- }
- catch (IOException e)
- {
- throw new SAXException(e);
- }
- }
-
- public void stopRenderer()
- throws SAXException
- {
- /*
- Force the processing of any more queue elements,
- even if they are not resolved.
+public class StreamRenderer extends Object {
+ private static final boolean MEM_PROFILE_WITH_GC = false;
+
+ /**
+ Somewhere to get our stats from.
*/
- try {
- processQueue(true);
- renderer.stopRenderer(outputStream);
- }
- catch (FOPException e)
- {
- throw new SAXException(e);
- }
- catch (IOException e)
- {
- throw new SAXException(e);
- }
+ private Runtime runtime = Runtime.getRuntime();
+
+ /**
+ Keep track of the number of pages rendered.
+ */
+ int pageCount = 0;
+
+ /**
+ Keep track of heap memory allocated,
+ for statistical purposes.
+ */
+ private long initialMemory;
+
+ /**
+ Keep track of time used by renderer.
+ */
+ private long startTime;
+
+ /**
+ The stream to which this rendering is to be
+ written to. <B>Note</B> that some renderers
+ do not render to a stream, and that this
+ member can therefore be null.
+ */
+ private OutputStream outputStream;
+
+ /**
+ The renderer being used.
+ */
+ private Renderer renderer;
- if (MEM_PROFILE_WITH_GC)
- System.gc(); // This takes time but gives better results
+ /**
+ The FontInfo for this renderer.
+ */
+ private FontInfo fontInfo = new FontInfo();
- long memoryNow = runtime.totalMemory() - runtime.freeMemory();
- long memoryUsed = (memoryNow - initialMemory) / 1024L;
+ /**
+ The list of pages waiting to be renderered.
+ */
+ private Vector renderQueue = new Vector();
- MessageHandler.logln("Initial heap size: " + (initialMemory/1024L) + "Kb");
- MessageHandler.logln("Current heap size: " + (memoryNow/1024L) + "Kb");
- MessageHandler.logln("Total memory used: " + memoryUsed + "Kb");
+ /**
+ The current set of IDReferences, passed to the
+ areatrees and pages. This is used by the AreaTree
+ as a single map of all IDs.
+ */
+ private IDReferences idReferences = new IDReferences();
- if (!MEM_PROFILE_WITH_GC)
- {
- MessageHandler.logln(" Memory use is indicative; no GC was performed");
- MessageHandler.logln(" These figures should not be used comparatively");
+ public StreamRenderer(OutputStream outputStream, Renderer renderer) {
+ this.outputStream = outputStream;
+ this.renderer = renderer;
}
- long timeUsed = System.currentTimeMillis() - startTime;
-
- MessageHandler.logln("Total time used: " + timeUsed + "ms");
- MessageHandler.logln("Pages rendererd: " + pageCount);
- MessageHandler.logln("Avg render time: " + (timeUsed / pageCount) + "ms/page");
- }
-
- /**
- Format the PageSequence. The PageSequence
- formats Pages and adds them to the AreaTree,
- which subsequently calls the StreamRenderer
- instance (this) again to render the page.
- At this time the page might be printed
- or it might be queued. A page might not
- be renderable immediately if the IDReferences
- are not all valid. In this case we defer
- the rendering until they are all valid.
- */
- public void render(PageSequence pageSequence)
- throws SAXException
- {
- AreaTree a = new AreaTree(this);
- a.setFontInfo(fontInfo);
-
- try {
- pageSequence.format(a);
+ public IDReferences getIDReferences() {
+ return idReferences;
}
- catch (FOPException e)
- {
- throw new SAXException(e);
+
+ public void startRenderer()
+ throws SAXException {
+ pageCount = 0;
+
+ if (MEM_PROFILE_WITH_GC)
+ System.gc(); // This takes time but gives better results
+
+ initialMemory = runtime.totalMemory() - runtime.freeMemory();
+ startTime = System.currentTimeMillis();
+
+ try {
+ renderer.setupFontInfo(fontInfo);
+ renderer.startRenderer(outputStream);
+ } catch (IOException e) {
+ throw new SAXException(e);
+ }
}
- }
-
- public synchronized void queuePage(Page page)
- throws FOPException, IOException
- {
- /*
- Try to optimise on the common case that there are
- no pages pending and that all ID references are
- valid on the current pages. This short-cuts the
- pipeline and renders the area immediately.
- */
- if ((renderQueue.size() == 0) && idReferences.isEveryIdValid())
- renderer.render(page, outputStream);
- else
- addToRenderQueue(page);
-
- pageCount++;
- }
-
- private synchronized void addToRenderQueue(Page page)
- throws FOPException, IOException
- {
- RenderQueueEntry entry = new RenderQueueEntry(page);
- renderQueue.addElement(entry);
-
- /*
- The just-added entry could (possibly) resolve the
- waiting entries, so we try to process the queue
- now to see.
- */
- processQueue(false);
- }
-
- /**
- Try to process the queue from the first entry forward.
- If an entry can't be processed, then the queue can't
- move forward, so return.
- */
- private synchronized void processQueue(boolean force)
- throws FOPException, IOException
- {
- while (renderQueue.size() > 0)
- {
- RenderQueueEntry entry = (RenderQueueEntry) renderQueue.elementAt(0);
- if ((!force) && (!entry.isResolved()))
- break;
-
- renderer.render(entry.getPage(), outputStream);
-
- /* TODO
- Enumeration rootEnumeration =
- entry.getAreaTree().getExtensions().elements();
- while (rootEnumeration.hasMoreElements())
- renderTree.addExtension((ExtensionObj) rootEnumeration.nextElement());
- */
-
- renderQueue.removeElementAt(0);
+
+ public void stopRenderer()
+ throws SAXException {
+ /*
+ Force the processing of any more queue elements,
+ even if they are not resolved.
+ */
+ try {
+ processQueue(true);
+ renderer.stopRenderer(outputStream);
+ } catch (FOPException e) {
+ throw new SAXException(e);
+ }
+ catch (IOException e) {
+ throw new SAXException(e);
+ }
+
+ if (MEM_PROFILE_WITH_GC)
+ System.gc(); // This takes time but gives better results
+
+ long memoryNow = runtime.totalMemory() - runtime.freeMemory();
+ long memoryUsed = (memoryNow - initialMemory) / 1024L;
+
+ MessageHandler.logln("Initial heap size: " + (initialMemory/1024L) + "Kb");
+ MessageHandler.logln("Current heap size: " + (memoryNow/1024L) + "Kb");
+ MessageHandler.logln("Total memory used: " + memoryUsed + "Kb");
+
+ if (!MEM_PROFILE_WITH_GC) {
+ MessageHandler.logln(" Memory use is indicative; no GC was performed");
+ MessageHandler.logln(" These figures should not be used comparatively");
+ }
+
+ long timeUsed = System.currentTimeMillis() - startTime;
+
+ MessageHandler.logln("Total time used: " + timeUsed + "ms");
+ MessageHandler.logln("Pages rendererd: " + pageCount);
+ MessageHandler.logln("Avg render time: " + (timeUsed / pageCount) + "ms/page");
}
- }
-
- /**
- A RenderQueueEntry consists of the Page to be queued,
- plus a list of outstanding ID references that need to be
- resolved before the Page can be renderered.<P>
- */
- class RenderQueueEntry extends Object
- {
- /*
- The Page that has outstanding ID references.
- */
- private Page page;
- /*
- A list of ID references (names).
+ /**
+ Format the PageSequence. The PageSequence
+ formats Pages and adds them to the AreaTree,
+ which subsequently calls the StreamRenderer
+ instance (this) again to render the page.
+ At this time the page might be printed
+ or it might be queued. A page might not
+ be renderable immediately if the IDReferences
+ are not all valid. In this case we defer
+ the rendering until they are all valid.
*/
- private Vector unresolvedIdReferences = new Vector();
+ public void render(PageSequence pageSequence)
+ throws SAXException {
+ AreaTree a = new AreaTree(this);
+ a.setFontInfo(fontInfo);
+
+ try {
+ pageSequence.format(a);
+ } catch (FOPException e) {
+ throw new SAXException(e);
+ }
+ }
- public RenderQueueEntry(Page page)
- {
- this.page = page;
+ public synchronized void queuePage(Page page)
+ throws FOPException, IOException {
+ /*
+ Try to optimise on the common case that there are
+ no pages pending and that all ID references are
+ valid on the current pages. This short-cuts the
+ pipeline and renders the area immediately.
+ */
+ if ((renderQueue.size() == 0) && idReferences.isEveryIdValid())
+ renderer.render(page, outputStream);
+ else
+ addToRenderQueue(page);
+
+ pageCount++;
+ }
- Enumeration e = idReferences.getInvalidElements();
- while (e.hasMoreElements())
- unresolvedIdReferences.addElement(e.nextElement());
+ private synchronized void addToRenderQueue(Page page)
+ throws FOPException, IOException {
+ RenderQueueEntry entry = new RenderQueueEntry(page);
+ renderQueue.addElement(entry);
+
+ /*
+ The just-added entry could (possibly) resolve the
+ waiting entries, so we try to process the queue
+ now to see.
+ */
+ processQueue(false);
}
- public Page getPage()
- {
- return page;
+ /**
+ Try to process the queue from the first entry forward.
+ If an entry can't be processed, then the queue can't
+ move forward, so return.
+ */
+ private synchronized void processQueue(boolean force)
+ throws FOPException, IOException {
+ while (renderQueue.size() > 0) {
+ RenderQueueEntry entry = (RenderQueueEntry) renderQueue.elementAt(0);
+ if ((!force) && (!entry.isResolved()))
+ break;
+
+ renderer.render(entry.getPage(), outputStream);
+
+ /* TODO
+ Enumeration rootEnumeration =
+ entry.getAreaTree().getExtensions().elements();
+ while (rootEnumeration.hasMoreElements())
+ renderTree.addExtension((ExtensionObj) rootEnumeration.nextElement());
+ */
+
+ renderQueue.removeElementAt(0);
+ }
}
/**
- See if the outstanding references are resolved
- in the current copy of IDReferences.
+ A RenderQueueEntry consists of the Page to be queued,
+ plus a list of outstanding ID references that need to be
+ resolved before the Page can be renderered.<P>
*/
- public boolean isResolved()
- {
- if ((unresolvedIdReferences.size() == 0) || idReferences.isEveryIdValid())
- return true;
-
- //
- // See if any of the unresolved references are still unresolved.
- //
- Enumeration e = unresolvedIdReferences.elements();
- while (e.hasMoreElements())
- if (!idReferences.doesIDExist((String) e.nextElement()))
- return false;
-
- unresolvedIdReferences.removeAllElements();
- return true;
+ class RenderQueueEntry extends Object {
+ /*
+ The Page that has outstanding ID references.
+ */
+ private Page page;
+
+ /*
+ A list of ID references (names).
+ */
+ private Vector unresolvedIdReferences = new Vector();
+
+ public RenderQueueEntry(Page page) {
+ this.page = page;
+
+ Enumeration e = idReferences.getInvalidElements();
+ while (e.hasMoreElements())
+ unresolvedIdReferences.addElement(e.nextElement());
+ }
+
+ public Page getPage() {
+ return page;
+ }
+
+ /**
+ See if the outstanding references are resolved
+ in the current copy of IDReferences.
+ */
+ public boolean isResolved() {
+ if ((unresolvedIdReferences.size() == 0) || idReferences.isEveryIdValid())
+ return true;
+
+ //
+ // See if any of the unresolved references are still unresolved.
+ //
+ Enumeration e = unresolvedIdReferences.elements();
+ while (e.hasMoreElements())
+ if (!idReferences.doesIDExist((String) e.nextElement()))
+ return false;
+
+ unresolvedIdReferences.removeAllElements();
+ return true;
+ }
}
- }
}