| Method from org.apache.fop.apps.Driver Detail: |
public void addElementMapping(ElementMapping mapping) {
mapping.addToBuilder(_treeBuilder);
}
Add the given element mapping.
An element mapping maps element names to Java classes. |
public void addElementMapping(String mappingClassName) throws IllegalArgumentException {
try {
ElementMapping mapping =
(ElementMapping)Class.forName(mappingClassName).newInstance();
addElementMapping(mapping);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ mappingClassName);
}
catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ mappingClassName);
}
catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ mappingClassName);
}
catch (ClassCastException e) {
throw new IllegalArgumentException(mappingClassName
+ " is not an ElementMapping");
}
}
add the element mapping with the given class name |
public void dumpError(Exception e) {
if (_errorDump) {
Logger log = getLogger();
if (e instanceof SAXException) {
log.error("", e);
if (((SAXException)e).getException() != null) {
log.error("", ((SAXException)e).getException());
}
} else if (e instanceof FOPException) {
e.printStackTrace();
if (((FOPException)e).getException() != null) {
log.error("", ((FOPException)e).getException());
}
} else {
log.error("", e);
}
}
}
|
public ContentHandler getContentHandler() {
if (!(_renderer instanceof org.apache.fop.render.awt.AWTRenderer
|| _renderer instanceof org.apache.fop.render.PrintRenderer)) {
if (_stream == null) throw new NullPointerException("OutputStream has not been set. Set before getting the ContentHandler");
}
if (_renderer == null) throw new NullPointerException("The renderer has not been set. Set before getting the ContentHandler");
StreamRenderer streamRenderer = new StreamRenderer(_stream, _renderer);
streamRenderer.setLogger(getLogger());
_treeBuilder.setLogger(getLogger());
_treeBuilder.setStreamRenderer(streamRenderer);
return _treeBuilder;
}
Returns the tree builder (a SAX ContentHandler).
Used in situations where SAX is used but not via a FOP-invoked
SAX parser. A good example is an XSLT engine that fires SAX
events but isn't a SAX Parser itself. |
public static final String getParserClassName() {
try {
return javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().getXMLReader().getClass().getName();
} catch (javax.xml.parsers.ParserConfigurationException e) {
return null;
} catch (org.xml.sax.SAXException e) {
return null;
}
}
|
public Renderer getRenderer() {
return _renderer;
}
|
public FormattingResults getResults() {
try {
return _treeBuilder.getStreamRenderer().getResults();
} catch (NullPointerException e) {
return null;
}
}
Returns the results of the last rendering process. Information includes
the total number of pages generated and the number of pages per
page-sequence. |
public boolean hasData() {
return (_treeBuilder.hasData());
}
|
public synchronized void render(Document document) throws FOPException {
DocumentInputSource source = new DocumentInputSource(document);
DocumentReader reader = new DocumentReader();
render(reader, source);
}
Build the formatting object tree using the given DOM Document |
public synchronized void render(XMLReader parser,
InputSource source) throws FOPException {
parser.setContentHandler(getContentHandler());
try {
parser.parse(source);
} catch (SAXException e) {
if (e.getException() instanceof FOPException) {
throw (FOPException)e.getException();
} else {
throw new FOPException(e);
}
}
catch (IOException e) {
throw new FOPException(e);
}
}
Build the formatting object tree using the given SAX Parser and
SAX InputSource |
public synchronized void reset() {
_source = null;
_stream = null;
_reader = null;
_treeBuilder.reset();
}
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. |
public synchronized void run() throws IOException, FOPException {
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 {
render(_reader, _source);
}
}
Runs the formatting and renderering process using the previously set
inputsource and outputstream |
public void setErrorDump(boolean dump) {
_errorDump = dump;
}
Set the error dump option |
public void setInputSource(InputSource source) {
_source = source;
}
Set the source for the FO document. This can be a normal SAX
InputSource, or an DocumentInputSource containing a DOM document. |
public void setLogger(Logger logger) {
log = logger;
}
|
public void setOutputStream(OutputStream stream) {
_stream = stream;
}
Set the OutputStream to use to output the result of the Renderer
(if applicable) |
public void setRenderer(int renderer) throws IllegalArgumentException {
switch (renderer) {
case RENDER_PDF:
setRenderer(new org.apache.fop.render.pdf.PDFRenderer());
break;
case RENDER_AWT:
throw new IllegalArgumentException("Use renderer form of setRenderer() for AWT");
case RENDER_PRINT:
throw new IllegalArgumentException("Use renderer form of setRenderer() for PRINT");
case RENDER_PCL:
setRenderer(new org.apache.fop.render.pcl.PCLRenderer());
break;
case RENDER_PS:
setRenderer(new org.apache.fop.render.ps.PSRenderer());
break;
case RENDER_TXT:
setRenderer(new org.apache.fop.render.txt.TXTRenderer());
break;
case RENDER_MIF:
setRenderer(new org.apache.fop.render.mif.MIFRenderer());
break;
case RENDER_XML:
setRenderer(new org.apache.fop.render.xml.XMLRenderer());
break;
case RENDER_SVG:
setRenderer(new org.apache.fop.render.svg.SVGRenderer());
break;
default:
throw new IllegalArgumentException("Unknown renderer type");
}
}
Set the rendering type to use. Must be one of
- RENDER_PDF
- RENDER_AWT
- RENDER_MIF
- RENDER_XML
- RENDER_PCL
- RENDER_PS
- RENDER_TXT
- RENDER_SVG
|
public void setRenderer(Renderer renderer) {
renderer.setLogger(getLogger());
_renderer = renderer;
}
|
public void setRenderer(String rendererClassName) throws IllegalArgumentException {
try {
_renderer =
(Renderer)Class.forName(rendererClassName).newInstance();
_renderer.setProducer(Version.getVersion());
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ rendererClassName);
}
catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ rendererClassName);
}
catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ rendererClassName);
}
catch (ClassCastException e) {
throw new IllegalArgumentException(rendererClassName
+ " is not a renderer");
}
}
Set the class name of the Renderer to use as well as the
producer string for those renderers that can make use of it. |
public void setRenderer(String rendererClassName,
String version) {
setRenderer(rendererClassName);
} Deprecated! use - renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) which will use the default producer string.
|
public void setXMLReader(XMLReader reader) {
_reader = reader;
}
Sets the reader used when reading in the source. If not set,
this defaults to a basic SAX parser. |
public void setupDefaultMappings() {
addElementMapping("org.apache.fop.fo.StandardElementMapping");
addElementMapping("org.apache.fop.svg.SVGElementMapping");
addElementMapping("org.apache.fop.extensions.ExtensionElementMapping");
// add mappings from available services
Enumeration providers =
Service.providers(org.apache.fop.fo.ElementMapping.class);
if (providers != null) {
while (providers.hasMoreElements()) {
String str = (String)providers.nextElement();
try {
addElementMapping(str);
} catch (IllegalArgumentException e) {}
}
}
}
Sets all the element and property list mappings to their default values. |