public class Converter extends DefaultHandler implements ErrorHandler, UriResolver, com.xmlmind.fo.converter.Translator.UriResolver
The Converter
class implements the Formatting Objects
conversion engine. A typical use is as follows:
setProperty
or
setProperties
method.
org.xml.sax.InputSource
and an OutputDestination
object respectively).
convert
method.
Alternatively, a properly initialized instance of this class may be
registered as a ContentHandler
with an external SAX parser.
Modifier and Type | Field and Description |
---|---|
protected com.xmlmind.fo.converter.Context |
context |
Constructor and Description |
---|
Converter()
Creates a new
Converter instance. |
Modifier and Type | Method and Description |
---|---|
protected void |
abort() |
protected void |
badPropertyWarning(String key,
String value,
String reason) |
void |
characters(char[] chars,
int start,
int length)
Not for public use: implementation of ContentHandler.
|
protected void |
clean() |
void |
convert(InputSource input,
OutputDestination output)
Performs conversion.
|
void |
endDocument()
Not for public use: implementation of ContentHandler.
|
void |
endElement(String namespace,
String localName,
String qualifiedName)
Not for public use: implementation of ContentHandler.
|
void |
endPrefixMapping(String prefix)
Not for public use: implementation of ContentHandler.
|
void |
error(Exception exception)
Not for public use: implementation of ErrorHandler.
|
void |
error(SAXParseException exception)
Not for public use: implementation of ErrorHandler.
|
protected void |
error(String message) |
void |
fatalError(SAXParseException exception)
Not for public use: implementation of ErrorHandler.
|
protected void |
finalize() |
UriResolver |
getUriResolver()
Returns the registered URI resolver.
|
UserStyles |
getUserStyles()
Returns the set of user styles specified using
setUserStyles(com.xmlmind.fo.converter.UserStyles) . |
XMLReader |
getXMLReader()
Returns the registered external XML reader.
|
void |
ignorableWhitespace(char[] chars,
int start,
int length)
Not for public use: implementation of ContentHandler.
|
protected void |
initFontSize(com.xmlmind.fo.properties.PropertyValues properties) |
static String[] |
listEncodings(String format)
Returns the list of available encodings for the specified output
format.
|
protected UserStyles |
loadUserStyles(URL url) |
static void |
main(String[] args)
Not for public use: a simple test.
|
void |
processingInstruction(String target,
String data)
Not for public use: implementation of ContentHandler.
|
String |
resolve(String uri)
Not for public use: implementation of Translator.UriResolver.
|
URL |
resolve(String spec,
URL base)
Not for public use: implementation of UriResolver.
|
protected void |
setDefaultValues(com.xmlmind.fo.properties.PropertyValues properties)
Set contextual default values.
|
void |
setDocumentLocator(Locator locator)
Not for public use: implementation of ContentHandler.
|
void |
setErrorHandler(ErrorHandler handler)
Registers a conversion error handler.
|
protected void |
setFont(com.xmlmind.fo.properties.PropertyValues properties,
String font) |
protected void |
setFontSize(com.xmlmind.fo.properties.PropertyValues properties,
String fontSize) |
protected void |
setOutput(OutputDestination output) |
void |
setProperties(Properties properties)
Sets conversion options.
|
protected void |
setProperties(com.xmlmind.fo.properties.PropertyValues properties,
Attributes attributes,
boolean computeLineHeight) |
void |
setProperty(String key,
String value)
Sets a conversion option.
|
void |
setUriResolver(UriResolver resolver)
Registers a URI resolver.
|
void |
setUserStyles(UserStyles styles)
Specifies the set of user styles during the conversion.
|
void |
setXMLReader(XMLReader reader)
Registers an external XML reader.
|
void |
skippedEntity(String name)
Not for public use: implementation of ContentHandler.
|
void |
startDocument()
Not for public use: implementation of ContentHandler.
|
void |
startElement(String namespace,
String localName,
String qualifiedName,
Attributes attributes)
Not for public use: implementation of ContentHandler.
|
void |
startPrefixMapping(String prefix,
String uri)
Not for public use: implementation of ContentHandler.
|
void |
warning(Exception exception)
Not for public use: implementation of ErrorHandler.
|
void |
warning(SAXParseException exception)
Not for public use: implementation of ErrorHandler.
|
protected void |
warning(String message) |
notationDecl, resolveEntity, unparsedEntityDecl
public static String[] listEncodings(String format) throws IllegalArgumentException
format
- the output format (rtf
, wml
,
docx
or odt
)IllegalArgumentException
- if the format
argument
is invalidsetProperty
public void setProperty(String key, String value)
All conversion options are specified as standard Java properties. Property names and values are summarized in the table below.
Name | Value | Description | Default |
---|---|---|---|
alwaysSaveAsPNG
| true , false ,
jpeg or svg
| If jpeg or true ,
do not attempt to save JPEG images as JPEG files in the output file.
Instead always convert JPEG images to PNG.
If | false for the ODT output format (which supports SVG);
svg for all the other output formats
(which do not support SVG).
|
baseURL (1)
| URL | base URL of relative paths in property values | None (paths are taken relative to the input source URL) |
detectLists
| true or false
| Create proper lists by inferring the numbering style of the list from the label of its first item. | true
|
docx.keepSVG
| true or false
| If false , discard input SVG graphics
after converting them to PNG. Only keep the converted PNG graphics
in the DOCX output file.
If true , keep both input SVG graphics and
the converted PNG graphics in the DOCX output file.
Ignored if docx.useVML=true .
| true
|
docx.useVML
| true or false
| Use VML -deprecated- elements rather than DrawingML elements to represent images | false
|
docx.variant
| MS-Word_version [strict ]?
| Marks generated DOCX file as being compatible with MS-Word
having specified major version. Any version other than 14
(MS-Word 2010), 15 (MS-Word 2013),
16 (MS-Word 2016) is currently ignored.
For example, specifying Moreover suffix | None. Generated DOCX file is not marked as being compatible with a specific version of MS-Word. |
eastAsiaFontFamilies
| A string having this syntax:
map = entry [',' entry]* entry = east_asian_family '=' western_family | May be used to map East Asian font families to Western font families. Such East Asian fonts are used to render mainly CJK text, possibly mixed with Western text. Example:MS Mincho=Cambria,Meiryo=Calibri | Arial Unicode MS=Arial (for compatibility with previous versions of XFC) |
genericFontFamilies
| A string having this syntax:
map = entry [',' entry]* entry = generic_family '=' actual_family generic_family = 'serif' | 'sans-serif' | 'monospace' | 'cursive' | 'fantasy' | May be used to map generic font families to actual font families. | Depends on the output format. Generally: serif=Times New Roman,sans-serif=Arial,monospace=Courier New |
imageResolution
| Positive integer | default image resolution in DPI.
Used to compute the intrinsic size of an image when an image file does not contain resolution or absolute size information. | 96 |
imageRendererResolution
| Positive integer | default image resolution in DPI.
Used to compute the intrinsic size of an image, according to the image renderer (that is, MS-Word or OpenOffice), when an image file does not contain resolution or absolute size information. | Depends on the output format. Generally 96.
It is strongly recommended to use this default value. |
outputEncoding
| See below | output encoding | See below |
outputFormat
| rtf , wml , docx or
odt
| output format | rtf
|
prescaleImages
| true or false
| image scaling policy (2) | false
|
protection
| A string having this syntax: 'limited-formatting' | ('read-only'|'comments-only'|'fill-forms-only'| 'tracked-changes-only' [ '+limited-formatting' ]?) | Specifies how the generated document is to be restricted in terms of editing and/or formatting. | None. The document is not protected. |
meta.metadata_name
| The value of the metadata | Specifies a metadata to be added to the document information section of the generated document. | N/A |
rtf.target
| MSWord
| target RTF viewer | None (no specified target) |
screenResolution
| Positive integer | screen resolution in DPI. Used to convert px lengths to other units. | 96 |
set.graphic_factory_name.parameter_name
| Depends on the parameter | Sets parameter parameter_name on graphic factory called
graphic_factory_name (case-insensitive).
graphic factory examples: ImageIO,
WMF, EMF, SVG, MathML.
Important: unlike all the other properties which only have
an effect on this converter, property
Converter conv = new Converter(); conv.setProperty("set.SVG.resolution", "300"); // DPIwithout actually using converter conv is a simple way to configure graphic factory SVG. | Depends on the parameter |
singleSidedLayout
| true or false
| single-sided page layout (3) | false
|
styles
| An URL in its string form (e.g. "file:///C:/My%20Folder/styles.xfc") or a filename (e.g. "C:\My Folder\styles.xfc"). A relative filename is relative to the current working directory. | Specifies the location of an XML file containing the set of user styles to be used during the conversion. | Do not use user styles; only use direct formatting/automatic styles. |
unprotectPassword
| A clear text password | This password lets the user remove the restrictions specified
by property protection .
| None. The document protection is not enforced using a password. |
The outputEncoding
property possible values depend on
the target output format:
ASCII
,
Cp1250
(Windows Eastern European), Cp1251
(Windows Cyrillic) and Cp1252
(Windows Latin-1). The
default value is Cp1252
.
The encoding specified in the OutputDestination
passed
to convert(org.xml.sax.InputSource, com.xmlmind.fo.converter.OutputDestination)
has priority over the encoding specified by
property outputEncoding.
ISO8859_1
) or the charset name (e.g.
ISO-8859-1
). The complete list of supported encodings is
returned by the listEncodings
method.
The default value is Cp1252
.
The encoding specified in the OutputDestination
passed
to convert(org.xml.sax.InputSource, com.xmlmind.fo.converter.OutputDestination)
has priority over the encoding specified by
property outputEncoding.
UTF-8
and UTF-16
. The default value is
UTF-8
.
The encoding specified in the OutputDestination
passed
to convert(org.xml.sax.InputSource, com.xmlmind.fo.converter.OutputDestination)
is ignored. Only the encoding possibly specified by
property outputEncoding is taken into account.
ISO8859_1
) or the charset name (e.g.
ISO-8859-1
). The complete list of supported encodings is
returned by the listEncodings
method.
The default value is UTF8
.
The encoding specified in the OutputDestination
passed
to convert(org.xml.sax.InputSource, com.xmlmind.fo.converter.OutputDestination)
is ignored. Only the encoding possibly specified by
property outputEncoding is taken into account.
(1) Use of the baseURL
property is
deprecated. Applications should register their own
URI resolver to handle URIs in property values.
(2) By default images are not prescaled.
Instead, the original size of images is preserved and scaling
directives are inserted in the output document.
Set the prescaleImages
property to true
if you prefer to minimize the size of the output document.
(3) By default RTF, WML and Open XML output documents are
given a double-sided page layout regardless of the input document
properties. To force a single-sided page layout the
singleSidedLayout
property must be set to
true
.
key
- the property namevalue
- the property value. Specify null
to remove
property key.setProperties
public void setProperties(Properties properties)
All conversion options are specified as standard Java properties.
See the setProperty
method for an
option summary.
properties
- a property setsetProperty
public void setUserStyles(UserStyles styles)
It's also possible to specify a set of user styles by its location
--an URL or absolute filename-- by the means of setProperty("styles", location)
.
However when setProperty
is used, the user styles
are parsed each time convert(org.xml.sax.InputSource, com.xmlmind.fo.converter.OutputDestination)
is invoked.
This means that for an application embedding XMLmind XSL-FO Converter,
a set of user styles may be parsed many times.
User styles using this method, of course, overrides those specified
using setProperty
.
styles
- a set of user styles; may be null
UserStyles.loadFrom(java.io.File)
,
getUserStyles()
public UserStyles getUserStyles()
setUserStyles(com.xmlmind.fo.converter.UserStyles)
.
May return null
.public void setErrorHandler(ErrorHandler handler)
If no error handler is registered by an application, a default
implementation will be used. The error
method of this default handler throws an exception, while the
warning
method prints a warning
message to the standard error output stream.
handler
- the error handlerpublic void setUriResolver(UriResolver resolver)
An application may use this method to specify a custom URI resolver
to be used for handling URIs in property values. By default URI
specifications that do not denote an absolute location are considered
relative to the input source URI, unless the
option is set.baseURL
resolver
- the URI resolvergetUriResolver
public UriResolver getUriResolver()
null
if none has been
specifiedsetUriResolver
public void setXMLReader(XMLReader reader)
An application may use this method to specify an external XML reader
(org.xml.sax.XMLReader
object) to be used for the
conversion. If no XML reader is specified one is created internally.
reader
- the XML readergetXMLReader
public XMLReader getXMLReader()
null
if none has been
specifiedsetXMLReader
protected void setOutput(OutputDestination output)
public void convert(InputSource input, OutputDestination output) throws Exception
input
- the input source.
Unless the input source has been specified simply as a systemId, the client code has the responsiblity to close the input stream/reader.
output
- the output destination.
Unless the output destination has been specified simply as a fileName, the client code has the responsiblity to close the output stream/writer.
Exception
- if an error occursprotected void abort()
protected void finalize() throws Throwable
public void startDocument() throws SAXException
startDocument
in interface ContentHandler
startDocument
in class DefaultHandler
SAXException
protected UserStyles loadUserStyles(URL url) throws Exception
Exception
public void endDocument() throws SAXException
endDocument
in interface ContentHandler
endDocument
in class DefaultHandler
SAXException
public void startElement(String namespace, String localName, String qualifiedName, Attributes attributes) throws SAXException
startElement
in interface ContentHandler
startElement
in class DefaultHandler
SAXException
public void endElement(String namespace, String localName, String qualifiedName) throws SAXException
endElement
in interface ContentHandler
endElement
in class DefaultHandler
SAXException
public void ignorableWhitespace(char[] chars, int start, int length) throws SAXException
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class DefaultHandler
SAXException
public void characters(char[] chars, int start, int length) throws SAXException
characters
in interface ContentHandler
characters
in class DefaultHandler
SAXException
public void processingInstruction(String target, String data) throws SAXException
processingInstruction
in interface ContentHandler
processingInstruction
in class DefaultHandler
SAXException
public void skippedEntity(String name) throws SAXException
skippedEntity
in interface ContentHandler
skippedEntity
in class DefaultHandler
SAXException
public void startPrefixMapping(String prefix, String uri) throws SAXException
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class DefaultHandler
SAXException
public void endPrefixMapping(String prefix) throws SAXException
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class DefaultHandler
SAXException
public void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
setDocumentLocator
in class DefaultHandler
protected void initFontSize(com.xmlmind.fo.properties.PropertyValues properties)
protected void setFont(com.xmlmind.fo.properties.PropertyValues properties, String font) throws SAXException
SAXException
protected void setFontSize(com.xmlmind.fo.properties.PropertyValues properties, String fontSize) throws SAXException
SAXException
protected void setProperties(com.xmlmind.fo.properties.PropertyValues properties, Attributes attributes, boolean computeLineHeight) throws SAXException
SAXException
protected void setDefaultValues(com.xmlmind.fo.properties.PropertyValues properties)
protected void warning(String message) throws SAXException
SAXException
protected void error(String message) throws SAXException
SAXException
public void error(Exception exception) throws Exception
exception
- the error information, encapsulated in an exceptionException
- if an error occurspublic void warning(Exception exception) throws Exception
exception
- the warning information, encapsulated in an exceptionException
- if an error occurspublic void fatalError(SAXParseException exception) throws SAXException
fatalError
in interface ErrorHandler
fatalError
in class DefaultHandler
SAXException
public void error(SAXParseException exception) throws SAXException
error
in interface ErrorHandler
error
in class DefaultHandler
SAXException
public void warning(SAXParseException exception) throws SAXException
warning
in interface ErrorHandler
warning
in class DefaultHandler
SAXException
public URL resolve(String spec, URL base) throws Exception
resolve
in interface UriResolver
spec
- the URI specificationbase
- the input source URI, or null
if unknownnull
if undefinedException
- if an error occurspublic String resolve(String uri) throws Exception
resolve
in interface com.xmlmind.fo.converter.Translator.UriResolver
Exception