Class WurbelHelper

java.lang.Object
org.wurbelizer.wurbel.WurbelHelper

public final class WurbelHelper extends Object
Helper methods for the Wurbelizer.
  • Method Details

    • getSourceRegionMap

      public static Map<String, SourceRegion> getSourceRegionMap()
      Lazily gets the map of source regions.
      The key is the region type (name), the value is the SourceRegion.
      Returns:
      the region map, never null
    • getDefaultSourceRegion

      public static SourceRegion getDefaultSourceRegion()
      Gets the default source region.
      Returns:
      the default region, null if none
    • getSourceTypeMap

      public static Map<String, SourceType> getSourceTypeMap()
      Lazily gets the map of source types.
      The key is the file extension, the value is the SourceType.
      Returns:
      the type map, never null
    • getDefaultSourceType

      public static SourceType 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-place
      getenv - true if check environment, false if system property
      lastLoop - true if translate \$ to $ finally
      otherProps - != 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/parsed
      getenv - true if check environment, false if system property
      lastLoop - true if translate \$ to $ finally
      otherProps - != null to use given properties for translation as well
      Returns:
      the parsed argument
    • translateVariables

      public static void translateVariables(StringBuilder buf, Properties otherProps)
      Translates variables in arguments, first properties, second environmen. Using StringBuilder.
      Parameters:
      buf - argument buffer to be translated/parsed in place
      otherProps - != null to use given properties for translation as well
    • translateVariables

      public static String translateVariables(String arg, Properties otherProps)
      Translates variables in arguments, first properties, second environment
      Parameters:
      arg - argument to be translated/parsed
      otherProps - != null to use given properties for translation as well
      Returns:
      the parsed argument
    • setExtraProperties

      public static void setExtraProperties(Properties props)
      Set extra properties (valid among all wurblets).
      Parameters:
      props - the properties
    • getExtraProperties

      public static Properties getExtraProperties()
      Gets the extra properties.
      Returns:
      the properties
    • setEnvProperties

      public static void setEnvProperties(Properties props)
      Sets environment properties (valid among all wurblets)
      Parameters:
      props - the properties
    • getEnvProperties

      public static Properties getEnvProperties()
      Gets the environment properties.
      Returns:
      the properties
    • indent

      public static String indent(String source, int indent)
      Perform indentation on generated source code. Implements the indent=... wurbler argumemt
      Parameters:
      source - is the original string (of lines)
      indent - is the number of spaces to insert at start of each line
      Returns:
      the new source string
    • scanPropertyLine

      public static String scanPropertyLine(String line, Properties props)
      Scans a property line. The line must NOT contain newlines! Everything after a hash '#' is considered as comment.
      Parameters:
      line - is the source line
      props - are the properties to add to
      Returns:
      the key if property added
    • firstBefore

      public static String firstBefore(String str, char delimiter)
      Gets the part of a string before a given delimiter.
      Parameters:
      str - the string
      delimiter - the delimiter
      Returns:
      the first part up to but excluding delimiter or the string if no delimiter at all
    • lastAfter

      public static String lastAfter(String str, char delimiter)
      Gets the part of a string after a given delimiter.
      Parameters:
      str - the string
      delimiter - the delimiter
      Returns:
      the last part following delimiter or the string if no delimiter at all
    • firstLine

      public static String firstLine(String str)
      Gets the first line from a multi-line string. Nice in tables.
      Parameters:
      str - the multiline string
      Returns:
      the first line, null if str == null
    • openReader

      public static Reader openReader(String fileName) throws WurbelException
      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 is FileNotFoundException if file does not exist
    • deleteFile

      public static boolean deleteFile(String fileName)
      Deletes a file.
      Parameters:
      fileName - the filename, from heap if starts with a dot
      Returns:
      true if deleted, false if no such file
    • translateLFtoCRLF

      public static String translateLFtoCRLF(String str)
      Translates a string to CRLF line endings.
      Already existing CRLFs are left unchanged.
      Parameters:
      str - the string to translate
      Returns:
      the translated string
    • translateCRLFtoLF

      public static String translateCRLFtoLF(String str)
      Translates a string to LF line endings.
      Parameters:
      str - the string to translate
      Returns:
      the translated string
    • determineIndent

      public static int determineIndent(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.
      Parameters:
      str - the string
      Returns:
      the number of spaces