Class WurbelHelper
java.lang.Object
org.wurbelizer.wurbel.WurbelHelper
Helper methods for the Wurbelizer.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleandeleteFile(String fileName) Deletes a file.static intdetermineIndent(String str) Determines the indent of a text block.
Counts the number of spaces up to the first non-space character, ignoring leading empty lines.static StringfirstBefore(String str, char delimiter) Gets the part of a string before a given delimiter.static StringGets the first line from a multi-line string.static SourceRegionGets the default source region.static SourceTypeGets the default source type.static PropertiesGets the environment properties.static PropertiesGets the extra properties.static Map<String, SourceRegion> Lazily gets the map of source regions.
The key is the region type (name), the value is theSourceRegion.static Map<String, SourceType> Lazily gets the map of source types.
The key is the file extension, the value is theSourceType.static StringPerform indentation on generated source code.static StringGets the part of a string after a given delimiter.static ReaderopenReader(String fileName) Gets the reader for a given filename.
By convention, if the name starts with a dot, it is expected to be a HeapFile in memory.static StringscanPropertyLine(String line, Properties props) Scans a property line.static voidsetEnvProperties(Properties props) Sets environment properties (valid among all wurblets)static voidsetExtraProperties(Properties props) Set extra properties (valid among all wurblets).static StringtranslateCRLFtoLF(String str) Translates a string to LF line endings.static StringtranslateLFtoCRLF(String str) Translates a string to CRLF line endings.
Already existing CRLFs are left unchanged.static voidtranslateVariables(StringBuilder buf, boolean getenv, boolean lastLoop, Properties otherProps) Translates variables using StringBuilder.static voidtranslateVariables(StringBuilder buf, Properties otherProps) Translates variables in arguments, first properties, second environmen.static StringtranslateVariables(String arg, boolean getenv, boolean lastLoop, Properties otherProps) Translates variables in Strings.static StringtranslateVariables(String arg, Properties otherProps) Translates variables in arguments, first properties, second environment
-
Method Details
-
getSourceRegionMap
Lazily gets the map of source regions.
The key is the region type (name), the value is theSourceRegion.- Returns:
- the region map, never null
-
getDefaultSourceRegion
Gets the default source region.- Returns:
- the default region, null if none
-
getSourceTypeMap
Lazily gets the map of source types.
The key is the file extension, the value is theSourceType.- Returns:
- the type map, never null
-
getDefaultSourceType
Gets the default source type.- Returns:
- the default type, null if none
-
translateVariables
public static void translateVariables(StringBuilder buf, boolean getenv, boolean lastLoop, Properties otherProps) Translates variables using StringBuilder. The translation is recursive, i.e. loops until no more replacements were performed.- Parameters:
buf- the argument buffer to be translated/parsed in-placegetenv- true if check environment, false if system propertylastLoop- true if translate \$ to $ finallyotherProps- != null to use given properties for translation as well
-
translateVariables
public static String translateVariables(String arg, boolean getenv, boolean lastLoop, Properties otherProps) Translates variables in Strings. The translation is recursive, i.e. loops until no more replacements were performed.- Parameters:
arg- the argument to be translated/parsedgetenv- true if check environment, false if system propertylastLoop- true if translate \$ to $ finallyotherProps- != null to use given properties for translation as well- Returns:
- the parsed argument
-
translateVariables
Translates variables in arguments, first properties, second environmen. Using StringBuilder.- Parameters:
buf- argument buffer to be translated/parsed in placeotherProps- != null to use given properties for translation as well
-
translateVariables
Translates variables in arguments, first properties, second environment- Parameters:
arg- argument to be translated/parsedotherProps- != null to use given properties for translation as well- Returns:
- the parsed argument
-
setExtraProperties
Set extra properties (valid among all wurblets).- Parameters:
props- the properties
-
getExtraProperties
-
setEnvProperties
Sets environment properties (valid among all wurblets)- Parameters:
props- the properties
-
getEnvProperties
Gets the environment properties.- Returns:
- the properties
-
indent
-
scanPropertyLine
Scans a property line. The line must NOT contain newlines! Everything after a hash '#' is considered as comment.- Parameters:
line- is the source lineprops- are the properties to add to- Returns:
- the key if property added
-
firstBefore
-
lastAfter
-
firstLine
-
openReader
Gets the reader for a given filename.
By convention, if the name starts with a dot, it is expected to be a HeapFile in memory. Otherwise, it's a real file.- Parameters:
fileName- the name of the file- Returns:
- the reader
- Throws:
WurbelException- if reading the file failed, cause isFileNotFoundExceptionif file does not exist
-
deleteFile
Deletes a file.- Parameters:
fileName- the filename, from heap if starts with a dot- Returns:
- true if deleted, false if no such file
-
translateLFtoCRLF
-
translateCRLFtoLF
-
determineIndent
Determines the indent of a text block.
Counts the number of spaces up to the first non-space character, ignoring leading empty lines.- Parameters:
str- the string- Returns:
- the number of spaces
-