Package com.igormaznitsa.jcp.context
Class PreprocessorContext
- java.lang.Object
-
- com.igormaznitsa.jcp.context.PreprocessorContext
-
public final class PreprocessorContext extends java.lang.ObjectThe preprocessor context class is a main class which contains all options of the preprocessor and allows to work with variables in expressions
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowWhitespaceprivate booleancareForLastNextLineprivate booleanclearDestinationDirectoryBeforeprivate booleanclonedprivate booleancompareDestinationprivate java.util.List<java.io.File>configFilesprivate booleancopyFileAttributesprivate TextFileDataContainercurrentInCloneSourceprivate PreprocessingStatecurrentStatestatic java.lang.StringDEFAULT_CHARSETstatic java.lang.StringDEFAULT_DEST_DIRECTORYstatic java.lang.StringDEFAULT_EXCLUDED_EXTENSIONSstatic java.lang.StringDEFAULT_PROCESSING_EXTENSIONSstatic java.lang.StringDEFAULT_SOURCE_DIRECTORYprivate java.lang.StringdestinationDirectoryprivate java.io.FiledestinationDirectoryFileprivate java.util.Set<java.lang.String>excludedFileExtensionsprivate java.lang.String[]excludedFolderPatternsprivate booleanfileOutputDisabledprivate java.util.Map<java.lang.String,Value>globalVarTableprivate java.lang.StringinCharacterEncodingprivate booleankeepNonExecutingLinesprivate java.util.Map<java.lang.String,Value>localVarTableprivate java.util.Map<java.lang.String,SpecialVariableProcessor>mapVariableNameToSpecialVarProcessorprivate java.lang.StringoutCharacterEncodingprivate PreprocessorExtensionpreprocessorExtensionprivate PreprocessorLoggerpreprocessorLoggerprivate booleanpreserveIndentprivate java.util.Set<java.lang.String>processingFileExtensionsprivate booleanremoveCommentsprivate java.util.Map<java.lang.String,java.lang.Object>sharedResourcesprivate java.lang.StringsourceDirectoriesprivate java.io.File[]sourceDirectoryFilesprivate booleanunknownVariableAsFalseprivate booleanverbose
-
Constructor Summary
Constructors Constructor Description PreprocessorContext()The constructorPreprocessorContext(PreprocessorContext context)Make clone of a preprocessor context but without cloning state.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddConfigFile(java.io.File file)Add a configuration file, it is a file which contains directives and global variable definitionsPreprocessorContextclearLocalVariables()Remove all local variables from the inside storagebooleancontainsGlobalVariable(java.lang.String name)Check that there is a named global variable in the inside storagebooleancontainsLocalVariable(java.lang.String name)Check that a local variable for a name is presentedjava.io.FilecreateDestinationFileForPath(java.lang.String path)It allows to create a File object for its path subject to the destination directory pathbooleandoesClearDestinationDirBefore()Get the flag to clear the destination directory before preprocessingjava.io.FilefindFileInSourceFolder(java.lang.String path)It finds a file for its path among files in source folder, it is prohibited to return files out of preprocessing folders.ValuefindVariableForName(java.lang.String name, boolean enforceUnknownVarAsNull)Find value among local and global variables for a name.java.io.File[]getConfigFiles()Get array of current registered configuration filesjava.lang.StringgetDestinationDirectory()Get the string representation of the destination directoryjava.io.FilegetDestinationDirectoryAsFile()Get the current destination directory as a File objectjava.lang.String[]getExcludedFileExtensions()Get excluded file extension list as a string arrayjava.lang.String[]getExcludedFolderPatterns()Get patterns for excluded folders.java.lang.StringgetInCharacterEncoding()Get the current character encoding for text readingValuegetLocalVariable(java.lang.String name)Get a local variable valuejava.lang.StringgetOutCharacterEncoding()Get the current character encoding for text writingprivate java.io.File[]getParsedSourceDirectoryAsFiles()Inside auxiliary method to parse the source directories list into file arrayPreprocessingStategetPreprocessingState()Get the last generated preprocessing state, it is the current onePreprocessorExtensiongetPreprocessorExtension()Get the current preprocessor extensionjava.lang.String[]getProcessingFileExtensions()Get file extensions of files to be preprocessed as a string arrayjava.lang.ObjectgetSharedResource(java.lang.String name)Get a shared source from inside mapjava.lang.StringgetSourceDirectories()Get the source directories as semi separated stringjava.io.File[]getSourceDirectoryAsFiles()Get the current source directories as a file arraybooleanisAllowWhitespace()Get flag that whitespace allowed between directive and comment.booleanisCareForLastNextLine()booleanisCloned()Check that the preprocessor context is a clone of another context.booleanisCompareDestination()Check the flag to check content of existing file before saving.booleanisCopyFileAttributes()Check that the preprocessor must copy file attributes.booleanisFileAllowedToBeProcessed(java.io.File file)Check that a file is allowed to be preprocessed fo its extensionbooleanisFileExcludedFromProcess(java.io.File file)Check that a file is excluded from preprocessing and coping actionsbooleanisFileOutputDisabled()Check that writing operations is disabledbooleanisGlobalVariable(java.lang.String variableName)Check that there is a global variable with such name.booleanisKeepLines()Check that the preprocessor must keep lines as commented onesbooleanisLocalVariable(java.lang.String variableName)Check that there is a local variable with such name.booleanisPreserveIndent()Get flag indicating whether preserve-indent is enabled or disabled.booleanisRemoveComments()It returns the flag shows that all comments must be removed from the resultbooleanisUnknownVariableAsFalse()Get flag shows that unknown variable is recognized as FALSE.booleanisVerbose()Check the verbose flagvoidlogDebug(java.lang.String text)Print some debug info into the current logvoidlogError(java.lang.String text)Print an information about an error into the current logvoidlogForVerbose(java.lang.String str)voidlogInfo(java.lang.String text)Print an information into the current logvoidlogWarning(java.lang.String text)Print an information about a warning situation into the current logPreprocessorExceptionmakeException(java.lang.String text, java.lang.Throwable cause)Prepare exception with message and cause, or return cause if it is a preprocessor exceptionprivate static java.lang.StringmakeStackView(TextFileDataContainer cloneSource, boolean cloned, java.util.List<TextFileDataContainer> list)PreprocessingStateproduceNewPreprocessingState(FileInfoContainer fileContainer, int phaseIndex)Generate new preprocessing state object, also the new preprocessing state will be saved as the current one in the contextPreprocessingStateproduceNewPreprocessingState(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 contextvoidregisterSpecialVariableProcessor(SpecialVariableProcessor processor)It allows to register a special variable processor which can process some special global variablesPreprocessorContextremoveGlobalVariable(java.lang.String name)Remove a global variable value from the context.PreprocessorContextremoveLocalVariable(java.lang.String name)Remove a local variable value from the context.java.lang.ObjectremoveSharedResource(java.lang.String name)Remove a shared object from the inside map for its namevoidsetAllowWhitespace(boolean flag)Set flag to allow whitespace between directive and comment chars.voidsetCareForLastNextLine(boolean flag)Set the flag to care to be precise in processing the last file next line charPreprocessorContextsetClearDestinationDirBefore(boolean flag)Set the flag to clear the destination directory before preprocessingPreprocessorContextsetCompareDestination(boolean flag)Set the flag to check before saving if the content changed.PreprocessorContextsetCopyFileAttributes(boolean value)Set the flag to copy file attributes.PreprocessorContextsetDestinationDirectory(java.lang.String directory)Set a destination directory for result filesPreprocessorContextsetExcludedFileExtensions(java.lang.String extensions)Set comma separated list of file extensions to be excluded from preprocessingvoidsetExcludedFolderPatterns(java.lang.String... patterns)Set patterns for excluded folders.voidsetFileOutputDisabled(boolean flag)It allows to disable all writing operations of the preprocessorPreprocessorContextsetGlobalVariable(java.lang.String name, Value value)Set a global variable valuePreprocessorContextsetInCharacterEncoding(java.lang.String characterEncoding)Set the character encoding for reading texts, it must be supported by the Java platform else an exception will be thrownPreprocessorContextsetKeepLines(boolean flag)Set the flag to keep lines as commented onesPreprocessorContextsetLocalVariable(java.lang.String name, Value value)Set a local variable valuePreprocessorContextsetOutCharacterEncoding(java.lang.String characterEncoding)Set the output texts character encoding, it must be supported by the Java platform else an exception will be thrownPreprocessorContextsetPreprocessorExtension(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 workvoidsetPreprocessorLogger(PreprocessorLogger logger)Set the logger to print information and error messagesvoidsetPreserveIndent(boolean flag)Set flag to control whether prefixes "//$", "//$$" should replaced with equal length whitespace strings rather than just removed.PreprocessorContextsetProcessingFileExtensions(java.lang.String extensions)Set file extensions of files to be preprocessed, it is a comma separated listPreprocessorContextsetRemoveComments(boolean removingComments)Set the remove comments flagvoidsetSharedResource(java.lang.String name, java.lang.Object obj)Set a shared source, it is an object saved into the inside map for a namePreprocessorContextsetSourceDirectories(java.lang.String directories)Set source directoriesvoidsetUnknownVariableAsFalse(boolean flag)Set flag to interpret unknown variable value as FALSE.PreprocessorContextsetVerbose(boolean flag)Set the verbose flag
-
-
-
Field Detail
-
DEFAULT_SOURCE_DIRECTORY
public static final java.lang.String DEFAULT_SOURCE_DIRECTORY
-
DEFAULT_DEST_DIRECTORY
public static final java.lang.String DEFAULT_DEST_DIRECTORY
-
DEFAULT_PROCESSING_EXTENSIONS
public static final java.lang.String DEFAULT_PROCESSING_EXTENSIONS
- See Also:
- Constant Field Values
-
DEFAULT_EXCLUDED_EXTENSIONS
public static final java.lang.String DEFAULT_EXCLUDED_EXTENSIONS
- See Also:
- Constant Field Values
-
DEFAULT_CHARSET
public static final java.lang.String DEFAULT_CHARSET
- See Also:
- Constant Field Values
-
verbose
private boolean verbose
-
removeComments
private boolean removeComments
-
clearDestinationDirectoryBefore
private boolean clearDestinationDirectoryBefore
-
fileOutputDisabled
private boolean fileOutputDisabled
-
keepNonExecutingLines
private boolean keepNonExecutingLines
-
careForLastNextLine
private boolean careForLastNextLine
-
compareDestination
private boolean compareDestination
-
allowWhitespace
private boolean allowWhitespace
-
preserveIndent
private boolean preserveIndent
-
copyFileAttributes
private boolean copyFileAttributes
-
unknownVariableAsFalse
private boolean unknownVariableAsFalse
-
sourceDirectories
private java.lang.String sourceDirectories
-
destinationDirectory
private java.lang.String destinationDirectory
-
destinationDirectoryFile
private java.io.File destinationDirectoryFile
-
sourceDirectoryFiles
private java.io.File[] sourceDirectoryFiles
-
processingFileExtensions
private java.util.Set<java.lang.String> processingFileExtensions
-
excludedFileExtensions
private java.util.Set<java.lang.String> excludedFileExtensions
-
preprocessorExtension
private PreprocessorExtension preprocessorExtension
-
inCharacterEncoding
private java.lang.String inCharacterEncoding
-
outCharacterEncoding
private java.lang.String outCharacterEncoding
-
globalVarTable
private final java.util.Map<java.lang.String,Value> globalVarTable
-
localVarTable
private final java.util.Map<java.lang.String,Value> localVarTable
-
mapVariableNameToSpecialVarProcessor
private final java.util.Map<java.lang.String,SpecialVariableProcessor> mapVariableNameToSpecialVarProcessor
-
sharedResources
private final java.util.Map<java.lang.String,java.lang.Object> sharedResources
-
preprocessorLogger
private PreprocessorLogger preprocessorLogger
-
configFiles
private final java.util.List<java.io.File> configFiles
-
currentState
private transient PreprocessingState currentState
-
cloned
private final boolean cloned
-
currentInCloneSource
private final TextFileDataContainer currentInCloneSource
-
excludedFolderPatterns
private java.lang.String[] excludedFolderPatterns
-
-
Constructor Detail
-
PreprocessorContext
public PreprocessorContext()
The constructor
-
PreprocessorContext
public PreprocessorContext(PreprocessorContext context)
Make clone of a preprocessor context but without cloning state.- Parameters:
context- the context to be cloned, must not be null.
-
-
Method Detail
-
setExcludedFolderPatterns
public void setExcludedFolderPatterns(@MustNotContainNull java.lang.String... patterns)
Set patterns for excluded folders.- Parameters:
patterns- array contains Ant path patterns
-
getExcludedFolderPatterns
@MustNotContainNull public java.lang.String[] getExcludedFolderPatterns()
Get patterns for excluded folders.- Returns:
- array of patterns in Ant pattern format
-
setCareForLastNextLine
public void setCareForLastNextLine(boolean flag)
Set the flag to care to be precise in processing the last file next line char- Parameters:
flag- true to turn on the mode, false to turn off
-
isCareForLastNextLine
public boolean isCareForLastNextLine()
-
isCloned
public boolean isCloned()
Check that the preprocessor context is a clone of another context.- Returns:
- true if the context is a clone, false otherwise
-
setPreprocessorLogger
public void setPreprocessorLogger(PreprocessorLogger logger)
Set the logger to print information and error messages- Parameters:
logger- a logger to be used for output, it can be null
-
registerSpecialVariableProcessor
public void registerSpecialVariableProcessor(SpecialVariableProcessor processor)
It allows to register a special variable processor which can process some special global variables- Parameters:
processor- a variable processor to be registered, it must not be null- See Also:
SpecialVariableProcessor
-
logInfo
public void logInfo(java.lang.String text)
Print an information into the current log- Parameters:
text- a String to be printed into the information log, it can be null
-
logError
public void logError(java.lang.String text)
Print an information about an error into the current log- Parameters:
text- a String to be printed into the error log, it can be null
-
logDebug
public void logDebug(java.lang.String text)
Print some debug info into the current log- Parameters:
text- a String to be printed into the error log, it can be null- Since:
- 6.0.1
-
logWarning
public void logWarning(java.lang.String text)
Print an information about a warning situation into the current log- Parameters:
text- a String to be printed into the warning log, it can be null
-
setRemoveComments
public PreprocessorContext setRemoveComments(boolean removingComments)
Set the remove comments flag- Parameters:
removingComments- the flag to set, true if comments must be removed from the result files, otherwise else- Returns:
- the preprocessor context instance
-
isRemoveComments
public boolean isRemoveComments()
It returns the flag shows that all comments must be removed from the result- Returns:
- true if comments must be returned, otherwise false
-
setFileOutputDisabled
public void setFileOutputDisabled(boolean flag)
It allows to disable all writing operations of the preprocessor- Parameters:
flag- true if preprocessor must not make any writing operations, otherwise false
-
isFileOutputDisabled
public boolean isFileOutputDisabled()
Check that writing operations is disabled- Returns:
- true if writing operations disabled, otherwise false
-
setAllowWhitespace
public void setAllowWhitespace(boolean flag)
Set flag to allow whitespace between directive and comment chars.- Parameters:
flag- true if whitespace allowed, false otherwise
-
isAllowWhitespace
public boolean isAllowWhitespace()
Get flag that whitespace allowed between directive and comment.- Returns:
- true if whitespace allowed, false otherwise
-
setUnknownVariableAsFalse
public void setUnknownVariableAsFalse(boolean flag)
Set flag to interpret unknown variable value as FALSE.- Parameters:
flag- true to turn on mode when unknown variable will be recognized as FALSE
-
isUnknownVariableAsFalse
public boolean isUnknownVariableAsFalse()
Get flag shows that unknown variable is recognized as FALSE.- Returns:
- true if unknown variable must be recognized as FALSE.
-
setPreserveIndent
public void setPreserveIndent(boolean flag)
Set flag to control whether prefixes "//$", "//$$" should replaced with equal length whitespace strings rather than just removed.- Parameters:
flag- true enables preserve-indent, false disables it
-
isPreserveIndent
public boolean isPreserveIndent()
Get flag indicating whether preserve-indent is enabled or disabled.- Returns:
- true if preserve-indent is enabled, false otherwise
-
setSourceDirectories
public PreprocessorContext setSourceDirectories(java.lang.String directories)
Set source directories- Parameters:
directories- semi separated list of source directories, must not be null- Returns:
- this preprocessor context instance
-
setSharedResource
public void setSharedResource(java.lang.String name, java.lang.Object obj)Set a shared source, it is an object saved into the inside map for a name- Parameters:
name- the name for the saved project, must not be nullobj- the object to be saved in, must not be null
-
getSharedResource
public java.lang.Object getSharedResource(java.lang.String name)
Get a shared source from inside map- Parameters:
name- the name of the needed object, it must not be null- Returns:
- a cached object or null if it is not found
-
removeSharedResource
public java.lang.Object removeSharedResource(java.lang.String name)
Remove a shared object from the inside map for its name- Parameters:
name- the object name, it must not be null- Returns:
- removing object or null if it is not found
-
getSourceDirectories
public java.lang.String getSourceDirectories()
Get the source directories as semi separated string- Returns:
- the current source directories semi separated list
-
getSourceDirectoryAsFiles
@MustNotContainNull public java.io.File[] getSourceDirectoryAsFiles()
Get the current source directories as a file array- Returns:
- the current source directories as a file array
-
getParsedSourceDirectoryAsFiles
@MustNotContainNull private java.io.File[] getParsedSourceDirectoryAsFiles()
Inside auxiliary method to parse the source directories list into file array- Returns:
- parsed file list, each file must exist and be a directory
-
setDestinationDirectory
public PreprocessorContext setDestinationDirectory(java.lang.String directory)
Set a destination directory for result files- Parameters:
directory- a path to the directory as String, it must not be null- Returns:
- this preprocessor context instance
-
getDestinationDirectoryAsFile
public java.io.File getDestinationDirectoryAsFile()
Get the current destination directory as a File object- Returns:
- the current destination directory as an object
-
getDestinationDirectory
public java.lang.String getDestinationDirectory()
Get the string representation of the destination directory- Returns:
- the current destination directory as a String
-
setProcessingFileExtensions
public PreprocessorContext setProcessingFileExtensions(java.lang.String extensions)
Set file extensions of files to be preprocessed, it is a comma separated list- Parameters:
extensions- comma separated extensions list of file extensions to be preprocessed, must not be null- Returns:
- this preprocessor context
-
getProcessingFileExtensions
@MustNotContainNull public java.lang.String[] getProcessingFileExtensions()
Get file extensions of files to be preprocessed as a string array- Returns:
- a string array of file extensions to be preprocessed
-
isFileAllowedToBeProcessed
public final boolean isFileAllowedToBeProcessed(java.io.File file)
Check that a file is allowed to be preprocessed fo its extension- Parameters:
file- a file to be checked- Returns:
- true if the file is allowed, false otherwise
-
isFileExcludedFromProcess
public final boolean isFileExcludedFromProcess(java.io.File file)
Check that a file is excluded from preprocessing and coping actions- Parameters:
file- a file to be checked- Returns:
- true if th file must be excluded, otherwise false
-
setExcludedFileExtensions
public PreprocessorContext setExcludedFileExtensions(java.lang.String extensions)
Set comma separated list of file extensions to be excluded from preprocessing- Parameters:
extensions- a comma separated file extension list, it must not be null- Returns:
- this preprocessor context
-
getExcludedFileExtensions
@MustNotContainNull public java.lang.String[] getExcludedFileExtensions()
Get excluded file extension list as a string array- Returns:
- a string array contains file extensions to be excluded from preprocessing act
-
setClearDestinationDirBefore
public PreprocessorContext setClearDestinationDirBefore(boolean flag)
Set the flag to clear the destination directory before preprocessing- Parameters:
flag- true if the directory must be cleaned, otherwise false- Returns:
- this preprocessor context
-
doesClearDestinationDirBefore
public boolean doesClearDestinationDirBefore()
Get the flag to clear the destination directory before preprocessing- Returns:
- true if the directory must be cleaned, otherwise false
-
setLocalVariable
public PreprocessorContext setLocalVariable(java.lang.String name, Value value)
Set a local variable value- Parameters:
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 null- Returns:
- this preprocessor context
- See Also:
Value
-
removeLocalVariable
public PreprocessorContext removeLocalVariable(java.lang.String name)
Remove a local variable value from the context.- Parameters:
name- the variable name, must not be null, remember that the name will be normalized and will be entirely in lower case- Returns:
- this preprocessor context
- See Also:
Value
-
removeGlobalVariable
public PreprocessorContext removeGlobalVariable(java.lang.String name)
Remove a global variable value from the context.- Parameters:
name- the variable name, must not be null, remember that the name will be normalized and will be entirely in lower case- Returns:
- this preprocessor context
- See Also:
Value
-
getLocalVariable
public Value getLocalVariable(java.lang.String name)
Get a local variable value- Parameters:
name- the name for the variable, it can be null. The name will be normalized to allowed one.- Returns:
- null either if the name is null or the variable is not found, otherwise its value
-
containsLocalVariable
public boolean containsLocalVariable(java.lang.String name)
Check that a local variable for a name is presented- Parameters:
name- the checking name, it will be normalized to the support format and can be null- Returns:
- false either if the name is null or there is not any local variable for the name, otherwise true
-
clearLocalVariables
public PreprocessorContext clearLocalVariables()
Remove all local variables from the inside storage- Returns:
- this preprocessor context
-
setGlobalVariable
public PreprocessorContext setGlobalVariable(java.lang.String name, Value value)
Set a global variable value- Parameters:
name- the variable name, it must not be null and will be normalized to the supported formatvalue- the variable value, it must not be null- Returns:
- this preprocessor context
-
containsGlobalVariable
public boolean containsGlobalVariable(java.lang.String name)
Check that there is a named global variable in the inside storage- Parameters:
name- the checking name, it will be normalized to the supported format, it can be null- Returns:
- true if such variable is presented for its name in the inside storage, otherwise false (also it is false if the name is null)
-
findVariableForName
public Value findVariableForName(java.lang.String name, boolean enforceUnknownVarAsNull)
Find value among local and global variables for a name. It finds in the order: special processors, local variables, global variables- Parameters:
name- the name for the needed variable, it will be normalized to the supported formatenforceUnknownVarAsNull- if true then state of the unknownVariableAsFalse flag in context will be ignored- Returns:
- false if either the variable is not found or the name is null, otherwise the variable value
-
isGlobalVariable
public boolean isGlobalVariable(java.lang.String variableName)
Check that there is a global variable with such name.- Parameters:
variableName- a name to be checked, can be null- Returns:
- false if there is not such variable or it is null, true if such global or special variable exists
-
isLocalVariable
public boolean isLocalVariable(java.lang.String variableName)
Check that there is a local variable with such name.- Parameters:
variableName- a name to be checked, can be null- Returns:
- false if there is not such variable or it is null, true if such local variable exists
-
setVerbose
public PreprocessorContext setVerbose(boolean flag)
Set the verbose flag- Parameters:
flag- true if the preprocessor must be verbose, otherwise false- Returns:
- this preprocessor context
-
isVerbose
public boolean isVerbose()
Check the verbose flag- Returns:
- true if the preprocessor must be verbose, otherwise false
-
setCompareDestination
public PreprocessorContext setCompareDestination(boolean flag)
Set the flag to check before saving if the content changed.- Parameters:
flag- true if to check, false otherwise- Returns:
- the preprocessor context
-
isCompareDestination
public boolean isCompareDestination()
Check the flag to check content of existing file before saving.- Returns:
- true if the content should be checked and new content must not be replaced if it is the same
-
setKeepLines
public PreprocessorContext setKeepLines(boolean flag)
Set the flag to keep lines as commented ones- Parameters:
flag- true if the preprocessor must keep non-executing lines, otherwise false- Returns:
- this preprocessor context
-
isKeepLines
public boolean isKeepLines()
Check that the preprocessor must keep lines as commented ones- Returns:
- true if the preprocessor must keep lines, false otherwise
-
isCopyFileAttributes
public boolean isCopyFileAttributes()
Check that the preprocessor must copy file attributes.- Returns:
- true if the preprocessor must copy file attributes, false otherwise.
-
setCopyFileAttributes
public PreprocessorContext setCopyFileAttributes(boolean value)
Set the flag to copy file attributes.- Parameters:
value- true if file attributes must be copied, false otherwise.- Returns:
- the preprocessor context
-
setPreprocessorExtension
public 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- Parameters:
extension- an object implements the PreprocessorExtension interface, it can be null- Returns:
- this preprocessor context
- See Also:
PreprocessorExtension
-
getPreprocessorExtension
public PreprocessorExtension getPreprocessorExtension()
Get the current preprocessor extension- Returns:
- the current preprocessor extension, it can be null
- See Also:
PreprocessorExtension
-
setInCharacterEncoding
public PreprocessorContext setInCharacterEncoding(java.lang.String characterEncoding)
Set the character encoding for reading texts, it must be supported by the Java platform else an exception will be thrown- Parameters:
characterEncoding- a character encoding as a String, it must not be null and must be supported by the Java platform- Returns:
- this preprocessor context
-
setOutCharacterEncoding
public PreprocessorContext setOutCharacterEncoding(java.lang.String characterEncoding)
Set the output texts character encoding, it must be supported by the Java platform else an exception will be thrown- Parameters:
characterEncoding- a character encoding as a String, it must not be null and must be supported by the Java platform- Returns:
- this preprocessor context
-
getInCharacterEncoding
public java.lang.String getInCharacterEncoding()
Get the current character encoding for text reading- Returns:
- the current read texts character encoding as a String
-
getOutCharacterEncoding
public java.lang.String getOutCharacterEncoding()
Get the current character encoding for text writing- Returns:
- the current text writing character encoding as a String
-
createDestinationFileForPath
public java.io.File createDestinationFileForPath(java.lang.String path)
It allows to create a File object for its path subject to the destination directory path- Parameters:
path- the path to the file, it must not be null- Returns:
- a generated File object for the path
-
findFileInSourceFolder
public java.io.File findFileInSourceFolder(java.lang.String path) throws java.io.IOExceptionIt finds a file for its path among files in source folder, it is prohibited to return files out of preprocessing folders.- Parameters:
path- the path to the needed file, it must not be null and the file must exist and be a file and be among files in preprocessing source folders- Returns:
- detected file object for the path
- Throws:
java.io.IOException- if it is impossible to find a file for the path
-
addConfigFile
public void addConfigFile(java.io.File file)
Add a configuration file, it is a file which contains directives and global variable definitions- Parameters:
file- a file, it must not be null
-
getConfigFiles
@MustNotContainNull public java.io.File[] getConfigFiles()
Get array of current registered configuration files- Returns:
- a file array contains the current registered configuration files
-
produceNewPreprocessingState
public PreprocessingState produceNewPreprocessingState(FileInfoContainer fileContainer, int phaseIndex) throws java.io.IOException
Generate new preprocessing state object, also the new preprocessing state will be saved as the current one in the context- Parameters:
fileContainer- a file container which will be using the preprocessor state, it must not be nullphaseIndex- index of phase (0 - global, 1 - preprocessing)- Returns:
- new generated preprocessor state
- Throws:
java.io.IOException- it will be throws if there is any error in opening and reading operations
-
produceNewPreprocessingState
public 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- Parameters:
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 null- Returns:
- new generated preprocessing state
-
getPreprocessingState
public PreprocessingState getPreprocessingState()
Get the last generated preprocessing state, it is the current one- Returns:
- the last generated preprocessing state
-
makeException
public PreprocessorException makeException(java.lang.String text, java.lang.Throwable cause)
Prepare exception with message and cause, or return cause if it is a preprocessor exception- Parameters:
text- the message text, must not be nullcause- the cause, it can be null- Returns:
- prepared exception with additional information
-
logForVerbose
public void logForVerbose(java.lang.String str)
-
makeStackView
private static java.lang.String makeStackView(TextFileDataContainer cloneSource, boolean cloned, @MustNotContainNull java.util.List<TextFileDataContainer> list)
-
-