|
||||||||
| 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-pathoptions-file-extensionplugin-pathplugin-file-extensiondata-pathlog-pathAll 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.io.PrintStream systemLog,
java.lang.String[] names)
Construct an instance of the context and create a default logger of the INFO_LOG logging level. |
| Method Summary | |
java.lang.String |
configPath()
Return the canonical path to the converter's configuration directory. |
protected void |
correctOption(java.lang.String name,
java.lang.String value)
Correction of option value to the given value. |
java.lang.String |
dataPath()
Return the canonical path to the converter's data directory. |
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). |
java.lang.String |
getFilePath(java.lang.String relPath,
java.lang.String path)
Try to get a resource path using the IOService.getFilePath
method with the homePath() as the base path. |
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 or unregistered. |
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 prepare the path composed from home path and the option value. |
java.io.InputStream |
getResourceAsStream(java.lang.String relPath,
java.lang.String path)
Try to get a resource using the IOService.getResourceAsStream
method with the homePath() as the base path and the class of this
object as a base class. |
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 |
getUserPreferences()
Return a name of user preferences file. |
java.lang.String |
getUserPreferencesPath()
Return a path to the user preferences file. |
java.io.InputStream |
getUserPreferencesStream()
Try to open an input stream to user preferences and return it or null. |
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". |
void |
loadConfigurationFrom(java.util.Properties properties)
Load configuration from the given properties and freeze core options after that. |
void |
loadConfigurationFrom(java.lang.String filename)
Load configuration properties from the specified resource, register them at this instance and freeze core options after that. |
void |
loadOptions(java.lang.String filename)
Load options from file. |
boolean |
loadUserPreferences()
Load user preference options from the file of user preferences (returned by getUserPreferences()).
|
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.io.InputStream |
openDataResource(java.lang.String path)
Get a resource using the getResourceAsStream method
with the value of "data-path" option as the relative path. |
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 or null. |
protected void |
register(java.util.Properties properties)
Register specified properties at the context. |
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.io.PrintStream systemLog,
java.lang.String[] names)
homePath - a canonical path to converter's home directory or null
if home path is unknownsystemLog - a print stream used as the system log in all loggersnames - an array of convertor-specific names of options| Method Detail |
public void loadConfigurationFrom(java.lang.String filename)
throws java.io.IOException
filename - a name of configuration filepublic void loadConfigurationFrom(java.util.Properties properties)
properties - configuration propertiesprotected void register(java.util.Properties properties)
properties - configuration properties of the converter
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)
public final boolean isTrue(java.lang.String name)
protected void correctOption(java.lang.String name,
java.lang.String value)
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 specified file 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 final java.io.InputStream getResourceAsStream(java.lang.String relPath,
java.lang.String path)
IOService.getResourceAsStream
method with the homePath() as the base path and the class of this
object as a base class.
public final java.lang.String getFilePath(java.lang.String relPath,
java.lang.String path)
IOService.getFilePath
method with the homePath() as the base path.public final java.io.InputStream openDataResource(java.lang.String path)
getResourceAsStream method
with the value of "data-path" option as the relative path.public void loadOptions(java.lang.String filename)
public final java.io.InputStream getUserPreferencesStream()
public final java.lang.String getUserPreferencesPath()
public boolean loadUserPreferences()
getUserPreferences()).
While loading, only known options are selected.
Other options are ignored.public void loadUserPreferences(java.util.Properties properties)
public 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 getUserPreferences()
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 | |||||||