Class Driver
- java.lang.Object
-
- com.xmlmind.fo.converter.Driver
-
- All Implemented Interfaces:
ErrorHandler
public final class Driver extends Object implements ErrorHandler
A driver for the conversion process.The
Driverclass provides a high-level interface to set up and perform a conversion. A typical use is as follows:- Set conversion options using the
setPropertiesorloadPropertyFilemethod. - Specify the conversion input source using one of the
setInputmethods. The input source may be specified as a character stream, a byte stream, a file name or a URL. It is represented internally by an instance of theInputSourceobject of the SAX API. - Specify the conversion output destination using one of the
setOutputmethods. The output destination may be specified as a character stream, a byte stream, or a file name. It is represented internally by an instance of theOutputDestinationobject. - Perform the conversion using the
convert()method.
Alternatively, an application may create and initialize an
InputSourceobject, create and initialize anOutputDestinationobject, and call theconvert(InputSource, OutputDestination)method.
-
-
Constructor Summary
Constructors Constructor Description Driver()Creates a newDriverinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconvert()Performs conversion.voidconvert(InputSource input, OutputDestination output)Performs conversion.voiderror(Exception exception)Not for public use: implementation of ErrorHandler.UriResolvergetUriResolver()Returns the registered URI resolver.XMLReadergetXMLReader()Returns the registered external XML reader.static String[]listEncodings(String format)Returns the list of available encodings for the specified output format.voidloadPropertyFile(File file)Reads conversion options from a file.voidloadPropertyFile(String fileName)Equivalent toloadPropertyFile(new File(fileName)).voidloadUserConfiguration()Reads conversion options from the user configuration file.static voidmain(String[] args)Not for public use: implementation of thefo2XXXcommand-line utilities.voidsetErrorHandler(ErrorHandler handler)Registers a conversion error handler.voidsetInput(InputStream byteStream)Sets the input source for the next conversion.voidsetInput(Reader characterStream)Sets the input source for the next conversion.voidsetInput(String fileName)Sets the input source for the next conversion.voidsetInput(URL url)Sets the input source for the next conversion.voidsetInput(InputSource input)Sets the input source for the next conversion.voidsetOutput(OutputDestination output)Sets the output destination for the next conversion.voidsetOutput(OutputStream byteStream)Sets the output destination for the next conversion.voidsetOutput(Writer characterStream)Sets the output destination for the next conversion.voidsetOutput(String fileName)Sets the output destination for the next conversion.voidsetProperties(Properties properties)Sets conversion options.voidsetProperty(String key, String value)Sets a conversion option.voidsetUriResolver(UriResolver resolver)Registers a URI resolver.voidsetXMLReader(XMLReader reader)Registers an external XML reader.voidwarning(Exception exception)Not for public use: implementation of ErrorHandler.
-
-
-
Method Detail
-
listEncodings
public static String[] listEncodings(String format) throws IllegalArgumentException
Returns the list of available encodings for the specified output format.- Parameters:
format- the output format (rtf,wml,docxorodt)- Returns:
- the list of available encodings
- Throws:
IllegalArgumentException- if theformatargument is invalid- See Also:
setProperty
-
setInput
public void setInput(InputSource input)
Sets the input source for the next conversion.- Parameters:
input- the input source, specified as anInputSourceobject- See Also:
setInput(String),setInput(URL),setInput(InputStream),setInput(Reader)
-
setInput
public void setInput(String fileName)
Sets the input source for the next conversion.- Parameters:
fileName- the input source, specified as a file name- See Also:
setInput(InputSource),setInput(URL),setInput(InputStream),setInput(Reader)
-
setInput
public void setInput(URL url)
Sets the input source for the next conversion.- Parameters:
url- the input source, specified as a URL- See Also:
setInput(InputSource),setInput(String),setInput(InputStream),setInput(Reader)
-
setInput
public void setInput(InputStream byteStream)
Sets the input source for the next conversion.- Parameters:
byteStream- the input source, specified as a byte stream- See Also:
setInput(InputSource),setInput(String),setInput(URL),setInput(Reader)
-
setInput
public void setInput(Reader characterStream)
Sets the input source for the next conversion.- Parameters:
characterStream- the input source, specified as a character stream- See Also:
setInput(InputSource),setInput(String),setInput(URL),setInput(InputStream)
-
setOutput
public void setOutput(OutputDestination output)
Sets the output destination for the next conversion.- Parameters:
output- the output destination, specified as anOutputDestinationobject- See Also:
setOutput(String),setOutput(OutputStream),setOutput(Writer)
-
setOutput
public void setOutput(String fileName)
Sets the output destination for the next conversion.- Parameters:
fileName- the output destination, specified as a file name- See Also:
setOutput(OutputDestination),setOutput(OutputStream),setOutput(Writer)
-
setOutput
public void setOutput(OutputStream byteStream)
Sets the output destination for the next conversion.- Parameters:
byteStream- the output destination, specified as a byteStream- See Also:
setOutput(OutputDestination),setOutput(String),setOutput(Writer)
-
setOutput
public void setOutput(Writer characterStream)
Sets the output destination for the next conversion.Note: this method is not suitable for OpenDocument output.
- Parameters:
characterStream- the output destination, specified as a character stream- See Also:
setOutput(OutputDestination),setOutput(String),setOutput(OutputStream)
-
setProperty
public void setProperty(String key, String value)
Sets a conversion option.All conversion options are specified as standard Java properties. Property names and values are summarized in the table below.
Conversion parameters Name Value Description Default alwaysSaveAsPNGtrue,false,jpegorsvgIf jpegortrue, do not attempt to save JPEG images as JPEG files in the output file. Instead always convert JPEG images to PNG.If
svgortrue, do not attempt to save SVG images as SVG files in the output file. Instead always convert SVG images to PNG.falsefor the ODT output format (which supports SVG);svgfor 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) detectListstrueorfalseCreate proper lists by inferring the numbering style of the list from the label of its first item. truedocx.keepSVGtrueorfalseIf false, discard input SVG graphics after converting them to PNG. Only keep the converted PNG graphics in the DOCX output file. Iftrue, keep both input SVG graphics and the converted PNG graphics in the DOCX output file. Ignored ifdocx.useVML=true.truedocx.useVMLtrueorfalseUse VML -deprecated- elements rather than DrawingML elements to represent images falsedocx.variantMS-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
15suppresses the "[Compatibility Mode]" text appearing in the title bar of MS-Word 2013 AND 2016.Moreover suffix
strict(only whenMS-Word_version>= 15; example15strict) may be used to generate a DOCX file marked as being "Strict Open XML".None. Generated DOCX file is not marked as being compatible with a specific version of MS-Word. eastAsiaFontFamiliesA 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=CalibriArial Unicode MS=Arial(for compatibility with previous versions of XFC)genericFontFamiliesA 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 NewimageResolutionPositive 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 imageRendererResolutionPositive 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.
outputEncodingSee below output encoding See below outputFormatrtf,wml,docxorodtoutput format rtfprescaleImagestrueorfalseimage scaling policy (2) falseprotectionA 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_nameThe value of the metadata Specifies a metadata to be added to the document information section of the generated document. N/A rtf.targetMSWordtarget RTF viewer None (no specified target) screenResolutionPositive integer screen resolution in DPI. Used to convert pxlengths to other units.96 set.graphic_factory_name.parameter_nameDepends 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
set.XXX.YYYimmediately configures once for all specified graphic factory and have no direct effect on this converter. Example: invoking something like:Converter conv = new Converter(); conv.setProperty("set.SVG.resolution", "300"); // DPIwithout actually using converterconvis a simple way to configure graphic factorySVG.Depends on the parameter singleSidedLayouttrueorfalsesingle-sided page layout (3) falsestylesAn 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. unprotectPasswordA 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
outputEncodingproperty possible values depend on the target output format:- For RTF output supported values are
ASCII,Cp1250(Windows Eastern European),Cp1251(Windows Cyrillic) andCp1252(Windows Latin-1). The default value isCp1252. - For WML output all encodings available in the current JVM are
supported. The property value may be either the encoding name (e.g.
ISO8859_1) or the charset name (e.g.ISO-8859-1). The complete list of supported encodings is returned by thelistEncodingsmethod. The default value isCp1252. - For Open XML output the
outputEncodingproperty specifies the encoding of XML content in the output document. Supported values areUTF-8andUTF-16. The default value isUTF-8. - For OpenDocument output the
outputEncodingproperty specifies the encoding of XML content (filesstyles.xmlandcontent.xml) in the output document. All encodings available in the current JVM are supported. The property value may be either the encoding name (e.g.ISO8859_1) or the charset name (e.g.ISO-8859-1). The complete list of supported encodings is returned by thelistEncodingsmethod. The default value isUTF8.
(1) Use of the
baseURLproperty is deprecated. Applications should register their ownURI resolverto 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
prescaleImagesproperty totrueif 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
singleSidedLayoutproperty must be set totrue.- Parameters:
key- the property namevalue- the property value- See Also:
setProperties,loadPropertyFile
- For RTF output supported values are
-
setProperties
public void setProperties(Properties properties)
Sets conversion options.All conversion options are specified as standard Java properties. See the
setPropertymethod for an option summary.- Parameters:
properties- a property set- See Also:
setProperty,loadPropertyFile
-
loadPropertyFile
public void loadPropertyFile(String fileName) throws IOException
Equivalent toloadPropertyFile(new File(fileName)).- Throws:
IOException
-
loadPropertyFile
public void loadPropertyFile(File file) throws IOException
Reads conversion options from a file.All conversion options are specified as standard Java properties. See the
setPropertymethod for an option summary.- Parameters:
file- the property file- Throws:
IOException- if an I/O error occurs- See Also:
loadUserConfiguration
-
loadUserConfiguration
public void loadUserConfiguration() throws IOExceptionReads conversion options from the user configuration file.The user configuration file is a standard Java property file located at
user_preferences_directory/xfc.properties, where user_preferences_directory is:- $HOME/.xfc/ on Linux, Unix, etc.
- $HOME/Library/Application Support/XMLmind/FOConverter/ on Mac OS X.
- %APPDATA%\XMLmind\FOConverter\ on Windows 2000, XP, Vista.
- Throws:
IOException- if an I/O error occurs- See Also:
loadPropertyFile
-
setErrorHandler
public void setErrorHandler(ErrorHandler handler)
Registers a conversion error handler.If no error handler is registered by an application, a default implementation will be used. The
errormethod of this default handler throws an exception, while thewarningmethod prints a warning message to the standard error output stream.- Parameters:
handler- the error handler
-
setUriResolver
public void setUriResolver(UriResolver resolver)
Registers a URI 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- Parameters:
resolver- the URI resolver- See Also:
getUriResolver
-
getUriResolver
public UriResolver getUriResolver()
Returns the registered URI resolver.- Returns:
- the URI resolver, or
nullif none has been specified - See Also:
setUriResolver
-
setXMLReader
public void setXMLReader(XMLReader reader)
Registers an external XML reader.An application may use this method to specify an external XML reader (
org.xml.sax.XMLReaderobject) to be used for the conversion. If no XML reader is specified one is created internally.- Parameters:
reader- the XML reader- See Also:
getXMLReader
-
getXMLReader
public XMLReader getXMLReader()
Returns the registered external XML reader.- Returns:
- the external XML reader, or
nullif none has been specified - See Also:
setXMLReader
-
convert
public void convert() throws ExceptionPerforms conversion.The input source and output destination must have been specified first, using the
setInputandsetOutputmethods.- Throws:
Exception- if an error occurs- See Also:
convert(InputSource, OutputDestination)
-
convert
public void convert(InputSource input, OutputDestination output) throws Exception
Performs conversion.
-
error
public void error(Exception exception) throws Exception
Not for public use: implementation of ErrorHandler.- Specified by:
errorin interfaceErrorHandler- Parameters:
exception- the error information, encapsulated in an exception- Throws:
Exception- if an error occurs
-
warning
public void warning(Exception exception) throws Exception
Not for public use: implementation of ErrorHandler.- Specified by:
warningin interfaceErrorHandler- Parameters:
exception- the warning information, encapsulated in an exception- Throws:
Exception- if an error occurs
-
main
public static void main(String[] args)
Not for public use: implementation of thefo2XXXcommand-line utilities.
-
-