ru.novosoft.dc.rtf2fo
Class RTF2FOContext

java.lang.Object
  |
  +--ru.novosoft.dc.core.NSDCContext
        |
        +--ru.novosoft.dc.rtf2fo.RTF2FOContext

public class RTF2FOContext
extends NSDCContext

An extension of the NSDCContext is intended for the management of RTF2FO conversion. The following additional options can be specified in this context:

define-options
Specifies a name of XML file containing description of internal RTF2FO parameters and compatibility models. The file is searched relative to the location specified in the data-path option. The default options definition file is options.xml;

define-override
Specifies a name of XML file containing user-defined models and overrides for parameters of models specified in the options.xml file. The file is searched relative to the location specified in the data-path option. The default file is override.xml;

model
A compatibility model used in the conversion. Its possible values are specified in the options definition file. Using the model you can set the compatibility with popular fo-renderers and their versions. The default compatibility model is "w3c";

output-plugin
A name of plug-in to be applied in the ConversionTask after converting an rtf-file;

define-preferences
Specifies a name of XML file containing groups of custom fo-attributes to be added to fo:root. This file is customized by user and allows specify global attributes to be added to the root of every fo-output tree. The file is searched relative to the location specified in the data-path option. The default file is preferences.xml;

preference
A name of preference group to be selected from file of user preferences. Empty value of this option means no preference;

parse-ignore-case
If "true", the RTF commands are recognized ignoring case. Otherwise, the parser recognizes command names using exact match;

parse-by-specification
If "true", cell padding commands are interpreted in compliance with RTF Specification. Otherwise, cell padding commands are interpreted in compliance with MS Word;

parse-with-old-margins
If "true", the default document margins are set in compliance with RTF Specification. Otherwise, default document margins are set in compliance with MS Word 2000;

conversion-density
A convertion density in dots per inch used in picture conversion plug-ins. The default is 100.

hide-track-change
If "true", the track-changes information will be removed while parsing an rtf input;

show-rtfdom
If "true", every generated RTF document is serialized to a file with the name of parsed file and the ".dom.xml" extension;

fo-file-extension
An extension of XML FO file produced when a template is not prepared;

fo-template-extension
An extension of XSLT file produced when a template is prepared;

fo-data-extension
An extension of XML file with data produced when a template is prepared;

prepare-template
A flag ("true"/"false") of the preparing template mode. In prepare mode two files are prepared from every rtf-file: a template-file and a data-file;

extract-data
A flag ("true"/"false") of data extraction. If the preparing template mode is on and this flag is true, all text data will be extracted from rtf-input;

extract-data-with-style
If the preparing template mode is on and this option is specified, the value of this option specifies an XML file describing styles to be extracted. While processing an rtf-input, the text data with required RTF styles will be extracted. The value of the "extract-data" flag is ignored in this case;

extract-fields
A flag ("true"/"false") of fields extraction. If the preparing template mode is on and this flag is true, fields of the type DOCPROPERTY "name" will be extracted;

create-cycles-at
Specifies a marker to be recognized as a cycle point in tables, lists, and paragraphs. Works if the preparing template mode is on. A table row will be cycled if it has no vertically merged cells and the content of the first cell is equal to the marker. A list item will be cycled if its content is equal to the marker. Surrounding spaces are ignored while comparing with the marker. An empty marker or unspecified option mean no cycles;

show-data-location
If "true", the "nsdc:text" elements will have optional attributes stecifying style and location information for extracted text elements;

show-doc-info
If "true", the "nsdc:doc-info" elements are added to data file in template preparing mode. They will contain values of nonempty standard document properties of converted rtf-file;

data-attributes-with-namespace
If "true", all attributes of elements from "nsdc" namespaces will have "nsdc:" prefix. Otherwise the attributes will be unprefixed;

font-substitution
Specifies a name of XML file containing font substitutions to be used in conversion. Substitutions from a new font substitution file are added to the font substitution table and override substitutions with the same template name specified before;

batch-logging
If "true", a unique log file is created in batch conversion. Otherwise, an individual log is created for every converted RTF file and is stored near the conversion results;

log-name
A template name for the log file. It is used in the batch logging mode. A name of log file is composed from this template and the ".log" extention. The log file is stored in the destination directory if it is specified or in the directory of the "log-path" option otherwise;

use-absolute-refs
If "true", the absolute URIs are used as picture paths in fo-file. Otherwise, relative URIs are used;

clip-headers
If "true", the overlapping of header region on body region in XSL FO is forbidden;

allow-watermarks
If "true", the first background image in header or footer can be placed at the background of page-body region;

no-picture-conversion
If "true", a conversion of pictures with plug-ins is suppressed;

strict-small-caps
If "true", small capital letters are converted to capitals of smaller font in correspondence with Word rules (3/4 of font size);

rtf-info
If "true", an information on positioned paragraphs not imbedded into a table is stored in corresponding fo:block elements with attributes of "rfo" namespace;

xml-indent
A numeric value of the indent used for the serialization of documents in the indent mode. The default value is 4;

xml-line-width
A numeric value of the approximate line width used for the serialization of documents in the indent mode. The default value is 72; and

encoding
If this option is specified, its value is used as an output encoding. The default output encoding is "UTF-8".


Fields inherited from class ru.novosoft.dc.core.NSDCContext
FULL_LOG, FULL_SILENT_LOG, INFO_LOG, NO_LOG, NORMAL_LOG, NSDC_PROPERTIES, SILENT_LOG
 
Constructor Summary
RTF2FOContext(java.lang.String homePath, java.io.PrintStream systemLog)
          Construct an instance of the context and create a default logger of the logging level INFO_LOG.
 
Method Summary
 boolean activateOutputPlugin(boolean batchMode)
          Try to activate the output plug-in and return true if the activation successful.
 RTFDocument applyFilter(RTFDocument document, CommonLogger logger)
          Applies the current filter to an rtf document.
 boolean applyOutputPlugin(java.lang.String template, CommonLogger logger)
          Try to apply the output plug-in to the fo-output and return true if the plug-in was successfully applied.
 java.lang.String conversionRules()
          Return picture conversion rules or empty string if no active picture plug-in found.
 java.lang.String defaultModel()
          Return the name of default model or empty string if the default model is undefined.
 java.lang.String getUserPreferences()
          Return a name of user preferences file.
 boolean loadOutputPlugin()
          Try to load the output plug-in specified in the "output-plugin" option and return true if the plug-in was successfully loaded.
 void logOptions(CommonLogger logger)
          Logging of user-defined options to the specified logger.
 java.lang.Object[] models()
          Return an array of valid models sorted alphabetically except the default model stored as the last model in the array.
 CommonLogger newLogger(java.lang.String path, int level)
          Construct a new logger of the specified log-level and return it.
protected  PictureConverter newPictureConverter()
          Return null or a new picture converter to be attached to this instance.
 PicturePool newPicturePool(java.lang.String path, boolean relative)
          Construct a new picture pool using the specified path as a parent name for pictures: all pictures will be stored in the subdirectory created from the path and the extension ".images".
 java.lang.Object[] preferences()
          Return an array of valid preference groups sorted alphabetically.
static RTF2FOContext prepareContext(java.io.PrintStream systemLog)
          Prepare an RTF2FO context loading its properties from the file specified in the "rtf2fo.configuration" system property.
protected  void register(java.util.Properties properties)
          Register RTF2FO properties.
 void setFilter(RTFFilter filter)
          Set a filter to be applied to an rtf document.
 boolean validateOptions()
          Validate the correctness of the "model" selection and return true if the validation is successful.
 
Methods inherited from class ru.novosoft.dc.core.NSDCContext
configPath, correctOption, dataPath, getDefaultLogger, getDouble, getFileExtension, getFilePath, getFloat, getInt, getNonemptyOption, getOption, getOption, getOptionAsPath, getResourceAsStream, getSpecifiedOption, getUserPreferencesPath, getUserPreferencesStream, homePath, info, isTrue, loadConfigurationFrom, loadConfigurationFrom, loadOptions, loadUserPreferences, loadUserPreferences, logOption, logOption, logOptionIfNonempty, logOptionIfTrue, logPath, openDataResource, options, parseOption, pluginExtension, pluginPath, setDefaultLogger, setOption, setOptionProcessor, setOptions, systemLog
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RTF2FOContext

public RTF2FOContext(java.lang.String homePath,
                     java.io.PrintStream systemLog)
Construct an instance of the context and create a default logger of the logging level INFO_LOG.
Parameters:
homePath - a canonical path to converter's home directory
systemLog - a print stream used as the system log in all loggers
Method Detail

register

protected void register(java.util.Properties properties)
Register RTF2FO properties. Properties with the following prefixes are considered: starting from the "system." are registered as system properties (this action is provided in the superclass); starting from the "nsdc." are registered as options of this context (this action is also provided in the superclass); starting from the "rtf2fo." are also registered as options of this context (while registration, values of "nsdc." options can be overlapped with values of "rtf2fo." options); and starting from the "encoding." are registered in the input encoding registry of rtf parser. Other properties are ignored. Prefixes are trimmed while registration.
Overrides:
register in class NSDCContext
Tags copied from class: NSDCContext
Parameters:
properties - configuration properties of the converter

newPictureConverter

protected PictureConverter newPictureConverter()
Return null or a new picture converter to be attached to this instance. The method is used in subclasses to override the default creation method.

conversionRules

public final java.lang.String conversionRules()
Return picture conversion rules or empty string if no active picture plug-in found.

newLogger

public final CommonLogger newLogger(java.lang.String path,
                                    int level)
Construct a new logger of the specified log-level and return it. The path is used as a template name for log files. Files with the same name and ".log" and ".log0" extensions will be used for logging. The ".log" file is used if the log mode is not equal to the INFO_LOG and NO_LOG. The ".log0" file is used if the log mode is equal to the FULL_SILENT_LOG or FULL_LOG.
Overrides:
newLogger in class NSDCContext

validateOptions

public boolean validateOptions()
Validate the correctness of the "model" selection and return true if the validation is successful. Additionally, provides autocorrection of "conversion-density" option, if this option has nonnumeric value.
Overrides:
validateOptions in class NSDCContext

loadOutputPlugin

public boolean loadOutputPlugin()
Try to load the output plug-in specified in the "output-plugin" option and return true if the plug-in was successfully loaded.

activateOutputPlugin

public boolean activateOutputPlugin(boolean batchMode)
Try to activate the output plug-in and return true if the activation successful. If the plug-in was not loaded yet, it is loaded at first. After that the "prepare-template" mode is tested. If this mode is turned on, the plugin activation is forbidden. After that the batch mode is tested. If the batchMode is true and the use of plug-in is forbidden in batch mode, the plug-in is not activated.

applyOutputPlugin

public boolean applyOutputPlugin(java.lang.String template,
                                 CommonLogger logger)
Try to apply the output plug-in to the fo-output and return true if the plug-in was successfully applied. If the plug-in was not activated yet, try to activate it in single file processing mode before apply.
Parameters:
template - a name of template to generate the name of fo-output file (the extension is replaced to the "fo-file-extension" value)
logger - a logger to put the output plug-in log

logOptions

public void logOptions(CommonLogger logger)
Logging of user-defined options to the specified logger.
Overrides:
logOptions in class NSDCContext

getUserPreferences

public final java.lang.String getUserPreferences()
Return a name of user preferences file. It is either a value of "rtf2fo.user-preferences" system property or the "rtf2fo-user.properties" file in the RTF2FO configuration directory if the system property is undefined.
Overrides:
getUserPreferences in class NSDCContext

newPicturePool

public final PicturePool newPicturePool(java.lang.String path,
                                        boolean relative)
Construct a new picture pool using the specified path as a parent name for pictures: all pictures will be stored in the subdirectory created from the path and the extension ".images".
Overrides:
newPicturePool in class NSDCContext
Parameters:
path - a path used for preparing of picture directory name
relative - if true, the URL of a picture in FO files will contain the path relative to the directory of this path. Otherwise, the canonical path will be stored in the URL.
Returns:
a new picture pool

defaultModel

public final java.lang.String defaultModel()
Return the name of default model or empty string if the default model is undefined.

models

public java.lang.Object[] models()
Return an array of valid models sorted alphabetically except the default model stored as the last model in the array. Model names in the returned array can be accessed with the toString() method.

preferences

public java.lang.Object[] preferences()
Return an array of valid preference groups sorted alphabetically. The first group in the array is empty string.

setFilter

public final void setFilter(RTFFilter filter)
Set a filter to be applied to an rtf document.

applyFilter

public final RTFDocument applyFilter(RTFDocument document,
                                     CommonLogger logger)
Applies the current filter to an rtf document.

prepareContext

public static RTF2FOContext prepareContext(java.io.PrintStream systemLog)
Prepare an RTF2FO context loading its properties from the file specified in the "rtf2fo.configuration" system property. If this property does not specified, the method loads the configuration from the default location "conf/nsdc.properties" relative to the RTF2FO home directory or relative to the path of the RTF2FO package in Java resources.

The RTF2FO home directory is specified by the "rtf2fo.home" system property. If this property undefined, the home directory is set to the first directory in the Java classpath list. If Java classpath list contains no directories at all, the home path will be undefined and using of GUI or plug-ins will be forbidden.

A context is created with a default logger of the logging level INFO_LOG.