|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ru.novosoft.dc.core.NSDCContext
The core context for a converter of rtf-file. It provides logging and management of options. The following options must be specified while instaniation of this class:
config-path
options-file-extension
plugin-path
plugin-file-extension
data-path
log-path
All above mensioned options are frozen while instaniation and will be never changed later.
Field Summary | |
static byte |
FULL_LOG
This log level means logging of all messages to files and to the system log (debug messages and messages on unknown rtf-commands are logged to files only). |
static byte |
FULL_SILENT_LOG
This log level means logging of all messages to files. |
static byte |
INFO_LOG
This log level means logging of information messages to the system log. |
static byte |
NO_LOG
This log level means no logging at all. |
static byte |
NORMAL_LOG
This log level means logging of all except debug messages to a file and to the system log. |
static java.lang.String |
NSDC_PROPERTIES
The default path of the file of converter's properties. |
static byte |
SILENT_LOG
This log level means logging of all except debug messages to a file. |
Constructor Summary | |
protected |
NSDCContext(java.lang.String homePath,
java.util.Properties properties,
java.io.PrintStream systemLog,
java.lang.String[] names)
Construct an instance of the context, create a default logger of the INFO_LOG logging level, and register the specified properties. |
Method Summary | |
java.lang.String |
configPath()
Return the canonical path to the converter's configuration directory. |
java.lang.String |
dataPath()
Return the canonical path to the converter's data directory. |
java.lang.String |
findConfigFile(java.lang.String filename,
java.lang.String extension)
Find a file with the specified filename and return its canonical path. |
protected void |
freezeCoreOptions()
Freeze core options against changes. |
CommonLogger |
getDefaultLogger()
Return the default logger. |
double |
getDouble(java.lang.String name,
double defaultValue)
Return a double value of the option with the specified name or the default value if this option undefined or contains non-double value. |
java.lang.String |
getFileExtension(java.lang.String name,
java.lang.String defaultExtension)
Get an option value and test it to be a valid file extension, which starts from the decimal point and contains alphanumeric symbols after it (ASCII only). |
float |
getFloat(java.lang.String name,
float defaultValue)
Return a float value of the option with the specified name or the default value if this option undefined or contains non-float value. |
int |
getInt(java.lang.String name,
int defaultValue)
Return an integer value of the option with the specified name or the default value if this option undefined or contains non-integer value. |
java.lang.String |
getNonemptyOption(java.lang.String name)
Return an option value if it is specified and is a nonempty string. |
java.lang.String |
getOption(java.lang.String name)
Return a value of option with the specified name or null if this option undefined. |
java.lang.String |
getOption(java.lang.String name,
java.lang.String defaultValue)
Return a value of option with the specified name or the default value if this option undefined. |
java.lang.String |
getOptionAsPath(java.lang.String name)
Get a value of option with the specified name and find the path using the IOService.findFile
method with the home path and the value of this option passed in parameters. |
java.lang.String |
getSpecifiedOption(java.lang.String name)
Get an option value and ensure that it is not null, i.e. the option is specified. |
abstract java.lang.String |
getUserPreferencesPath()
Return a name of file of user preferences. |
java.lang.String |
homePath()
Return the canonical path to the converter's home directory. |
void |
info(java.lang.String message)
Send the message to the default logger. |
boolean |
isTrue(java.lang.String name)
Return true if and only if the option with specified name is defined and its value is equal to "true". |
static java.util.Properties |
loadConfiguration(java.lang.String homePath,
java.lang.String filename)
Load configuration properties from the specified file and return them. |
void |
loadOptions(java.lang.String filename)
Load options from file. |
boolean |
loadUserPreferences()
Load user preference options from the file of user preferences (returned by getUserPreferencesPath() ).
|
void |
loadUserPreferences(java.util.Properties properties)
Load user preference options from a specified set of properties. |
protected boolean |
logOption(CommonLogger logger,
java.lang.String name)
Log an option to the logger if it is specified. |
protected static boolean |
logOption(CommonLogger logger,
java.lang.String name,
java.lang.String value)
Log an option to the logger if it has a non-null value. |
protected boolean |
logOptionIfNonempty(CommonLogger logger,
java.lang.String name)
Log an option to the logger if its value is nonempty string. |
protected boolean |
logOptionIfTrue(CommonLogger logger,
java.lang.String name)
Log an option to the logger if its value is equal to "true". |
void |
logOptions(CommonLogger logger)
The method is designed for logging options to the specified logger just before a conversion. |
java.lang.String |
logPath(java.lang.String logDirectoryPath)
Return the log path specified by the logDirectoryPath
and the "log-name" option. |
abstract CommonLogger |
newLogger(java.lang.String path,
int level)
Construct a new logger of the specified log-level and return it. |
abstract PicturePool |
newPicturePool(java.lang.String path,
boolean relative)
Construct a new picture pool using the specified path as a parent name for pictures. |
java.util.Properties |
options()
Return all options specified. |
boolean |
parseOption(java.lang.String option)
Parse a string having the form "key:value" and call the setOption(key, value) method. |
java.lang.String |
pluginExtension()
Return the extension for plugin configuration files. |
java.lang.String |
pluginPath()
Return the canonical path to the plugin's directory. |
void |
setDefaultLogger(CommonLogger logger)
Set the default logger. |
void |
setOption(java.lang.String name,
java.lang.String value)
Set an individual converter's option. |
void |
setOptionProcessor(java.lang.String name,
OptionProcessor processor)
Set a processor for the specified option name. |
void |
setOptions(java.util.Properties properties,
java.lang.String namePrefix)
Set options using only those properties of the passed properties' table which start from the specified prefix. |
java.io.PrintStream |
systemLog()
Return a system log specified for this context. |
boolean |
validateOptions()
Validate setting of options and return true if the validation is successful. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final byte NO_LOG
public static final byte INFO_LOG
public static final byte SILENT_LOG
public static final byte NORMAL_LOG
public static final byte FULL_SILENT_LOG
public static final byte FULL_LOG
public static final java.lang.String NSDC_PROPERTIES
Constructor Detail |
protected NSDCContext(java.lang.String homePath, java.util.Properties properties, java.io.PrintStream systemLog, java.lang.String[] names)
homePath
- a canonical path to converter's home directoryproperties
- configuration properties of the convertersystemLog
- a print stream used as the system log in all loggersnames
- an array of convertor-specific names of optionsMethod Detail |
protected final void freezeCoreOptions()
public void setOptions(java.util.Properties properties, java.lang.String namePrefix)
public final void setOption(java.lang.String name, java.lang.String value)
public final void setOptionProcessor(java.lang.String name, OptionProcessor processor)
public boolean parseOption(java.lang.String option)
public final java.util.Properties options()
public final java.lang.String getOption(java.lang.String name)
public final java.lang.String getOption(java.lang.String name, java.lang.String defaultValue)
public final int getInt(java.lang.String name, int defaultValue)
public final float getFloat(java.lang.String name, float defaultValue)
public final double getDouble(java.lang.String name, double defaultValue)
public final java.lang.String getFileExtension(java.lang.String name, java.lang.String defaultExtension)
defaultExtension
is returned. The returned result is converted
to lower case.public final java.lang.String getSpecifiedOption(java.lang.String name)
NSDCException
is thrown.public final java.lang.String getNonemptyOption(java.lang.String name)
public final java.lang.String getOptionAsPath(java.lang.String name)
IOService.findFile
method with the home path and the value of this option passed in parameters.public final boolean isTrue(java.lang.String name)
public final void setDefaultLogger(CommonLogger logger)
public final CommonLogger getDefaultLogger()
public final void info(java.lang.String message)
public final java.io.PrintStream systemLog()
public final java.lang.String homePath()
public final java.lang.String configPath()
public final java.lang.String dataPath()
public java.lang.String logPath(java.lang.String logDirectoryPath)
logDirectoryPath
and the "log-name" option. If "log-name" value starts with "file:",
the file specified after is used as a template name for log files
and the logDirectoryPath
value is ignored.
If the logDirectoryPath
is null,
the value of "log-path" option is used instead.public final java.lang.String pluginPath()
public final java.lang.String pluginExtension()
public java.lang.String findConfigFile(java.lang.String filename, java.lang.String extension)
NSDCException
is thrown. The null value of the extension parameter
reduces the search algorithm to the executing of first two steps only.public void loadOptions(java.lang.String filename)
findConfigFile
method with
extension specified in the "options-file-extension" option.public boolean loadUserPreferences()
getUserPreferencesPath()
).
While loading, only known options are selected.
Other options are ignored.public void loadUserPreferences(java.util.Properties properties)
public static java.util.Properties loadConfiguration(java.lang.String homePath, java.lang.String filename) throws java.io.IOException
homePath
- a converter's home directory pathfilename
- a name of configuration filepublic boolean validateOptions()
public void logOptions(CommonLogger logger)
protected final boolean logOption(CommonLogger logger, java.lang.String name)
protected final boolean logOptionIfNonempty(CommonLogger logger, java.lang.String name)
protected final boolean logOptionIfTrue(CommonLogger logger, java.lang.String name)
protected static final boolean logOption(CommonLogger logger, java.lang.String name, java.lang.String value)
public abstract java.lang.String getUserPreferencesPath()
public abstract CommonLogger newLogger(java.lang.String path, int level)
public abstract PicturePool newPicturePool(java.lang.String path, boolean relative)
path
- a path used for preparing of picture directory namerelative
- if true, the URL of a picture in the FO file will contain
the path relative to the directory of this path.
Otherwise, the canonical path will be stored in the URL.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |