public class PreprocessorContext extends Object
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CHARSET |
static String |
DEFAULT_DEST_DIRECTORY |
static String |
DEFAULT_EXCLUDED_EXTENSIONS |
static String |
DEFAULT_PROCESSING_EXTENSIONS |
static String |
DEFAULT_SOURCE_DIRECTORY |
Constructor and Description |
---|
PreprocessorContext()
The constructor
|
PreprocessorContext(PreprocessorContext context)
Make clone of a preprocessor context but without cloning state.
|
Modifier and Type | Method and Description |
---|---|
void |
addConfigFile(File file)
Add a configuration file, it is a file which contains directives and global
variable definitions
|
PreprocessorContext |
clearLocalVariables()
Remove all local variables from the inside storage
|
boolean |
containsGlobalVariable(String name)
Check that there is a named global variable in the inside storage
|
boolean |
containsLocalVariable(String name)
Check that a local variable for a name is presented
|
File |
createDestinationFileForPath(String path)
It allows to create a File object for its path subject to the destination
directory path
|
boolean |
doesClearDestinationDirBefore()
Get the flag to clear the destination directory before preprocessing
|
Value |
findVariableForName(String name)
Find value among local and global variables for a name.
|
File[] |
getConfigFiles()
Get array of current registered configuration files
|
String |
getDestinationDirectory()
Get the string representation of the destination directory
|
File |
getDestinationDirectoryAsFile()
Get the current destination directory as a File object
|
String[] |
getExcludedFileExtensions()
Get excluded file extension list as a string array
|
String |
getInCharacterEncoding()
Get the current character encoding for text reading
|
Value |
getLocalVariable(String name)
Get a local variable value
|
String |
getOutCharacterEncoding()
Get the current character encoding for text writing
|
PreprocessingState |
getPreprocessingState()
Get the last generated preprocessing state, it is the current one
|
PreprocessorExtension |
getPreprocessorExtension()
Get the current preprocessor extension
|
String[] |
getProcessingFileExtensions()
Get file extensions of files to be preprocessed as a string array
|
Object |
getSharedResource(String name)
Get a shared source from inside map
|
String |
getSourceDirectories()
Get the source directories as semi separated string
|
File[] |
getSourceDirectoryAsFiles()
Get the current source directories as a file array
|
File |
getSourceFile(String path)
It returns a File object for a path to a source file subject to the source
directory path
|
boolean |
isCareForLastNextLine() |
boolean |
isCloned()
Check that the preprocessor context is a clone of another context.
|
boolean |
isCompareDestination()
Check the flag to check content of existing file before saving.
|
boolean |
isFileAllowedToBeProcessed(File file)
Check that a file is allowed to be preprocessed fo its extension
|
boolean |
isFileExcludedFromProcess(File file)
Check that a file is excluded from preprocessing and coping actions
|
boolean |
isFileOutputDisabled()
Check that writing operations is disabled
|
boolean |
isGlobalVariable(String variableName)
Check that there is a global variable with such name.
|
boolean |
isKeepLines()
Check that the preprocessor must keep lines as commented ones
|
boolean |
isLocalVariable(String variableName)
Check that there is a local variable with such name.
|
boolean |
isRemoveComments()
It returns the flag shows that all comments must be removed from the result
|
boolean |
isVerbose()
Check the verbose flag
|
void |
logDebug(String text)
Print some debug info into the current log
|
void |
logError(String text)
Print an information about an error into the current log
|
void |
logForVerbose(String str) |
void |
logInfo(String text)
Print an information into the current log
|
void |
logWarning(String text)
Print an information about a warning situation into the current log
|
PreprocessorException |
makeException(String text,
Throwable cause)
Prepare exception with message and cause, or return cause if it is a
preprocessor exception
|
PreprocessingState |
produceNewPreprocessingState(FileInfoContainer fileContainer,
int phaseIndex)
Generate new preprocessing state object, also the new preprocessing state
will be saved as the current one in the context
|
PreprocessingState |
produceNewPreprocessingState(FileInfoContainer fileContainer,
TextFileDataContainer textContainer)
Generate new preprocessing state for a file container and a text container,
also the new preprocessing state will be saved as the current one in the
context
|
void |
registerSpecialVariableProcessor(SpecialVariableProcessor processor)
It allows to register a special variable processor which can process some
special global variables
|
PreprocessorContext |
removeGlobalVariable(String name)
Remove a global variable value from the context.
|
PreprocessorContext |
removeLocalVariable(String name)
Remove a local variable value from the context.
|
Object |
removeSharedResource(String name)
Remove a shared object from the inside map for its name
|
void |
setCareForLastNextLine(boolean flag)
Set the flag to care to be precise in processing the last file next line char
|
PreprocessorContext |
setClearDestinationDirBefore(boolean flag)
Set the flag to clear the destination directory before preprocessing
|
PreprocessorContext |
setCompareDestination(boolean flag)
Set the flag to check before saving if the content changed.
|
PreprocessorContext |
setDestinationDirectory(String directory)
Set a destination directory for result files
|
PreprocessorContext |
setExcludedFileExtensions(String extensions)
Set comma separated list of file extensions to be excluded from
preprocessing
|
void |
setFileOutputDisabled(boolean flag)
It allows to disable all writing operations of the preprocessor
|
PreprocessorContext |
setGlobalVariable(String name,
Value value)
Set a global variable value
|
PreprocessorContext |
setInCharacterEncoding(String characterEncoding)
Set the character encoding for reading texts, it must be supported by the
Java platform else an exception will be thrown
|
PreprocessorContext |
setKeepLines(boolean flag)
Set the flag to keep lines as commented ones
|
PreprocessorContext |
setLocalVariable(String name,
Value value)
Set a local variable value
|
PreprocessorContext |
setOutCharacterEncoding(String characterEncoding)
Set the output texts character encoding, it must be supported by the Java
platform else an exception will be thrown
|
PreprocessorContext |
setPreprocessorExtension(PreprocessorExtension extension)
Set a preprocessor extension, it is a module implements the
PreprocessorExtension interface which can process and get some calls from a
preprocessor during its work
|
void |
setPreprocessorLogger(PreprocessorLogger logger)
Set the logger to print information and error messages
|
PreprocessorContext |
setProcessingFileExtensions(String extensions)
Set file extensions of files to be preprocessed, it is a comma separated
list
|
PreprocessorContext |
setRemoveComments(boolean removingComments)
Set the remove comments flag
|
void |
setSharedResource(String name,
Object obj)
Set a shared source, it is an object saved into the inside map for a name
|
PreprocessorContext |
setSourceDirectories(String directories)
Set source directories
|
PreprocessorContext |
setVerbose(boolean flag)
Set the verbose flag
|
public static final String DEFAULT_SOURCE_DIRECTORY
public static final String DEFAULT_DEST_DIRECTORY
public static final String DEFAULT_PROCESSING_EXTENSIONS
public static final String DEFAULT_EXCLUDED_EXTENSIONS
public static final String DEFAULT_CHARSET
public PreprocessorContext()
public PreprocessorContext(PreprocessorContext context)
context
- the context to be cloned, must not be null.public void setCareForLastNextLine(boolean flag)
flag
- true to turn on the mode, false to turn offpublic boolean isCareForLastNextLine()
public boolean isCloned()
public void setPreprocessorLogger(PreprocessorLogger logger)
logger
- a logger to be used for output, it can be nullpublic void registerSpecialVariableProcessor(SpecialVariableProcessor processor)
processor
- a variable processor to be registered, it must not be nullSpecialVariableProcessor
public void logInfo(String text)
text
- a String to be printed into the information log, it can be nullpublic void logError(String text)
text
- a String to be printed into the error log, it can be nullpublic void logDebug(String text)
text
- a String to be printed into the error log, it can be nullpublic void logWarning(String text)
text
- a String to be printed into the warning log, it can be nullpublic PreprocessorContext setRemoveComments(boolean removingComments)
removingComments
- the flag to set, true if comments must be removed
from the result files, otherwise elsepublic boolean isRemoveComments()
public void setFileOutputDisabled(boolean flag)
flag
- true if preprocessor must not make any writing operations,
otherwise falsepublic boolean isFileOutputDisabled()
public PreprocessorContext setSourceDirectories(String directories)
directories
- semi separated list of source directories, must not be
nullpublic void setSharedResource(String name, Object obj)
name
- the name for the saved project, must not be nullobj
- the object to be saved in, must not be nullpublic Object getSharedResource(String name)
name
- the name of the needed object, it must not be nullpublic Object removeSharedResource(String name)
name
- the object name, it must not be nullpublic String getSourceDirectories()
public File[] getSourceDirectoryAsFiles()
public PreprocessorContext setDestinationDirectory(String directory)
directory
- a path to the directory as String, it must not be nullpublic File getDestinationDirectoryAsFile()
public String getDestinationDirectory()
public PreprocessorContext setProcessingFileExtensions(String extensions)
extensions
- comma separated extensions list of file extensions to be
preprocessed, must not be nullpublic String[] getProcessingFileExtensions()
public final boolean isFileAllowedToBeProcessed(File file)
file
- a file to be checkedpublic final boolean isFileExcludedFromProcess(File file)
file
- a file to be checkedpublic PreprocessorContext setExcludedFileExtensions(String extensions)
extensions
- a comma separated file extension list, it must not be
nullpublic String[] getExcludedFileExtensions()
public PreprocessorContext setClearDestinationDirBefore(boolean flag)
flag
- true if the directory must be cleaned, otherwise falsepublic boolean doesClearDestinationDirBefore()
public PreprocessorContext setLocalVariable(String name, Value value)
name
- the variable name, must not be null, remember that the name
will be normalized and will be entirely in lower casevalue
- the value for the variable, it must not be nullValue
public PreprocessorContext removeLocalVariable(String name)
name
- the variable name, must not be null, remember that the name
will be normalized and will be entirely in lower caseValue
public PreprocessorContext removeGlobalVariable(String name)
name
- the variable name, must not be null, remember that the name
will be normalized and will be entirely in lower caseValue
public Value getLocalVariable(String name)
name
- the name for the variable, it can be null. The name will be
normalized to allowed one.public boolean containsLocalVariable(String name)
name
- the checking name, it will be normalized to the support format
and can be nullpublic PreprocessorContext clearLocalVariables()
public PreprocessorContext setGlobalVariable(String name, Value value)
name
- the variable name, it must not be null and will be normalized
to the supported formatvalue
- the variable value, it must not be nullpublic boolean containsGlobalVariable(String name)
name
- the checking name, it will be normalized to the supported
format, it can be nullpublic Value findVariableForName(String name)
name
- the name for the needed variable, it will be normalized to the
supported formatpublic boolean isGlobalVariable(String variableName)
variableName
- a name to be checked, can be nullpublic boolean isLocalVariable(String variableName)
variableName
- a name to be checked, can be nullpublic PreprocessorContext setVerbose(boolean flag)
flag
- true if the preprocessor must be verbose, otherwise falsepublic boolean isVerbose()
public PreprocessorContext setCompareDestination(boolean flag)
flag
- true if to check, false otherwisepublic boolean isCompareDestination()
public PreprocessorContext setKeepLines(boolean flag)
flag
- true if the preprocessor must keep non-executing lines,
otherwise falsepublic boolean isKeepLines()
public PreprocessorContext setPreprocessorExtension(PreprocessorExtension extension)
extension
- an object implements the PreprocessorExtension interface,
it can be nullPreprocessorExtension
public PreprocessorExtension getPreprocessorExtension()
PreprocessorExtension
public PreprocessorContext setInCharacterEncoding(String characterEncoding)
characterEncoding
- a character encoding as a String, it must not be
null and must be supported by the Java platformpublic PreprocessorContext setOutCharacterEncoding(String characterEncoding)
characterEncoding
- a character encoding as a String, it must not be
null and must be supported by the Java platformpublic String getInCharacterEncoding()
public String getOutCharacterEncoding()
public File createDestinationFileForPath(String path)
path
- the path to the file, it must not be nullpublic File getSourceFile(String path) throws IOException
path
- the path to the needed source file, it must not be null and the
file must exist and be a fileIOException
- it will be thrown for problem to create the File or to
find it on the diskpublic void addConfigFile(File file)
file
- a file, it must not be nullpublic File[] getConfigFiles()
public PreprocessingState produceNewPreprocessingState(FileInfoContainer fileContainer, int phaseIndex) throws IOException
fileContainer
- a file container which will be using the preprocessor
state, it must not be nullphaseIndex
- index of phase (0 - global, 1 - preprocessing)IOException
- it will be throws if there is any error in opening and
reading operationspublic PreprocessingState produceNewPreprocessingState(FileInfoContainer fileContainer, TextFileDataContainer textContainer)
fileContainer
- the file container to be used to create the new
preprocessing state, it must not be nulltextContainer
- the text container to be used to create the new
preprocessing state, it must not be nullpublic PreprocessingState getPreprocessingState()
public PreprocessorException makeException(String text, Throwable cause)
text
- the message text, must not be nullcause
- the cause, it can be nullpublic void logForVerbose(String str)
Copyright © 2011–2016 Igor Maznitsa. All rights reserved.