Class FWFrameworkHelper

java.lang.Object
net.simplace.core.FWFrameworkHelper

public final class FWFrameworkHelper extends Object
Provides some static method for working with strings.
Author:
Andreas Enders
  • Field Details

    • WEBEUROSIGN

      public static final char WEBEUROSIGN
      See Also:
    • PARAMPATTERN

      public static final Pattern PARAMPATTERN
      [$][{][^},^{]*[}]
    • EXPRESSIONPATTERN

      public static final Pattern EXPRESSIONPATTERN
      [!][A-Z]*:.*[!]
    • MATHRULE_PARSER

      public static final de.schmitzm.lang.tree.OperationTreeParser MATHRULE_PARSER
      Parser, which creates an mathematical operation tree from a rule string.
  • Method Details

    • getParameterFromMap

      public static Object getParameterFromMap(Map<String,Object> aParamMap, String aKey, Object aDefault)
      getting parameter value from key if value is Map or Date using '!' as a seperator.
      Parameters:
      aParamMap -
      aKey -
      aDefault -
      Returns:
      parameter value from key if value is Map or Date using '!' as a seperator
    • getStringParameterFromMap

      public static String getStringParameterFromMap(Map<String,Object> aParamMap, String aKey, Object aDefault)
      getting parameter value from map as string.
      Parameters:
      aParamMap -
      aKey -
      aDefault -
      Returns:
      parameter value from map as string
    • getNumberParameterFromMap

      public static <T extends Number> T getNumberParameterFromMap(Map<String,Object> aParamMap, String aKey, Class<T> aNumberType, T aDefault)
      Getting parameter value from map as a number.
      Type Parameters:
      T -
      Parameters:
      aParamMap - map the parameter is taken from
      aKey - key for the map
      aNumberType - number type, the determined value is converted to (subclass of Number)
      aDefault - default value, which is returned if parameter not set or value can not be converted to aNumberType.
      Returns:
      parameter value from map as a number
    • replaceParamTokens

      public static String replaceParamTokens(Map<String,Object> aParamMap, String aValue, Object aDefault)
      replaces Parameters in
      Parameters:
      aValue - matching the regexp '.*[${].*[}].*' with given parameters in
      aParamMap -
      aDefault -
      Returns:
      aNewValue
    • replaceParamTokens

      public static String replaceParamTokens(Map<String,Object> aParamMap, String aValue, Object aDefault, boolean aIgnoreNull)
      replaces Parameters in
      Parameters:
      aValue - matching the regexp '.*[${].*[}].*' with given parameters in
      aParamMap -
      aDefault -
      aIgnoreNull -
      Returns:
      aNewValue
    • getValueFromSpecialParameter

      public static Object getValueFromSpecialParameter(Map<String,Object> aParamMap, String aKey, Object aDefault)
      getting parameter value from key if value is Map or Date using '!' as a separator.
      Parameters:
      aParamMap -
      aKey -
      aDefault -
      Returns:
      parameter value from key if value is Map or Date using '!' as a separator
    • evaluateExpression

      public static double evaluateExpression(String aValue, Map<String,Object> aParameterMap)
      evaluates expressions fith arithmetric operations
      Parameters:
      aValue -
      aParameterMap -
      Returns:
      the double result value
    • evaluateMathematicalRule

      public static double evaluateMathematicalRule(String aRule)
      Parst einen String, erstellt daraus einen Operator-Baum und wertet diesen aus. Fuer die Syntax gelten die gleichen Regeln, wie fuer evaluateRule(String). Das Ergebnis wird jedoch immer als numerisch interpretiert. Ist das Ergebnis keine Instanz von Number, wird 0 zurueckgegeben.
      Parameters:
      aRule - mathematical Rule
      Returns:
      the result ot the rule or 0 if the result is not numeric
      See Also:
      • for details about the format
    • evaluateRule

      public static Object evaluateRule(String aRule)
      Parameters:
      aRule -
      Returns:
      resulting object
      See Also:
      • for details about the format
    • evaluateRule

      public static Object evaluateRule(String aRule, de.schmitzm.lang.tree.OperationTreeParser aParser)

      Evaluation of Rules in SIMPLACE Framework with the SchmitzM Operation Tree Parser

      The Operation Tree Parser evaluates mathematical rules of different type. Logical or numerical operations can be evaluated. Before evaluating the given rules the parameters given in the algorithm are replaced. If a parameter was not correctly found the rule cannot be evaluated. Make sure that either a value or a default is given for the specific parameter.

      Variables enclosed in ${variable.name}

      First parameters have to be replaced hierarchically (not within this method), then calculation takes place (here!).

       ${some.parameter.name} * 15 / ${some.other.param${param.index.param}}

      Constant numerical values:

      • Numbers in double type
      • rand or random as alias for random numbers between 0 and 1
      • "Not a number" (NaN): "NaN"
      • Boolean TRUE (1)
      • Boolean FALSE (0)
      • Current time ms (System.currentTimeMillis()): "CURR_MILLIS"
      • One day in ms (LangUtil?.DAY_MILLIS): "DAY_MILLIS"
      • One Week in ms (LangUtil?.WEEK_MILLIS): "WEEK_MILLIS"

      Constant String values

      • Character arrays are started and ended by " or '.

      2-partner arithmetic operation

      • Summation: "+"
      • Subtraction: "-"
      • Multiplication: "*"
      • Division: "/"
      • Exponent: ""
        15 + 5.6 (20.6)

      The 2-partner Boolean operator

      • Boolean AND: "&"
      • Boolean OR: "|"
      • Equals: "=" or "=="
      • Unequal: "!=" or "<>"
      • Smaller than: "<"
      • Greater than ">"
      • Smaller equals: "<="
      • Greater equals: ">="

      The 2-partner character operation

      • String-concatenation: "+"
      • Regular expression check: "regex(expression,regular expr)"
      • First value of a String-Splits via regular expression: "split(expression,regular expr)"
      • N-th value of the string split via regular expression: "split(expression,regular expr,n)"
      • String-Replace: "replAll(expression,pattern expr,repl expr)"

      The singular operation

      • Absolute Value: "abs(.)"
      • Square root: "sqr(.)" or "sqrt(.)"
      • Round: "rnd(.)" or "round(.)"
      • Cut: "int(.)" or "trunc(.)"
      • Test Not A Number (NaN): "isNaN(.)"
      • Sinus: "sin(.)"
      • Co sinus: "cos(.)"
      • Tangent: "tan(.)"
      • Arcos-Sinus: "arcsin(.)" or "asin(.)"
      • Arcos - Co sinus: "arccos(.)" or "acos(.)"
      • Arcos - Tangent: "arctan(.)" or "atan(.)"
      • Exponential: "exp(.)"
      • Logarithmic base e: "ln(.)"
      • Logarithmic base 10: "log(.)"

      The singular Boolean operation

      • Boolean NOT: "!(.)"

      The singular String operation

      • Boolean NOT: "!(.)"
      • Convert Number to String: "str(.)"
      • Convert String to Number: "val(.)"
      • Convert to upper case: "toupper(.)"
      • Convert to lower case: "tolower(.)"
      • Convert date-String to Milli-Seconds: str2millis(string expr, format string expr)
      • Convert date to Milli-Seconds: date2millis(year, month, day)
      • Convert Milli-Seconds to date-String: millis2Str(millis, format string expr)
      • Convert date to date-String: date2Str(year, month, day, format string expr)

      The 3-partner operation ITE(.,.,.)

      • The ITE-operation: "If .. Then .. Else ..".
        ITE(${some.parameter.name} > 5,0,1) 

      First parameter is replaced, then checked first partner. Result (0) if parameter was > 5, (1) if not

      To combine Boolean and arithmetic operations the operands have to be coded as (1) or (0), not as TRUE or FALSE where op > 0 is TRUE and 0 is FALSE.

      Parameters:
      aRule - a Rule
      aParser -
      Returns:
      the result ot the rule
      See Also:
      • for details about the format
    • processTemplate

      public static String processTemplate(String aTemplate, org.opengis.feature.simple.SimpleFeature tFeatureToUse, ResultSet aResultSet, Map<String,Object> aParameterMap)
      Parameters:
      aTemplate -
      tFeatureToUse -
      aResultSet -
      aParameterMap -
      Returns:
      a processed Template
    • combineHTML

      public static String combineHTML(String aHTMLBefore, String aStyleSheet) throws IOException
      Reads the html and the stylesheet from the parameters and returns a combined html.
      Parameters:
      aHTMLBefore -
      aStyleSheet -
      Returns:
      a combined html
      Throws:
      IOException
    • saveProblemReport

      public static void saveProblemReport()
    • transformMapToStringValue

      public static Map<String,String> transformMapToStringValue(Map<String,Object> aParameterMap)
      Parameters:
      aParameterMap -
      Returns:
      Map, transformed to String value
    • getParametersMatchingRegex

      public static Map<Object,Object> getParametersMatchingRegex(Map<String,Object> aMap, String aRegexString)
      Parameters:
      aMap -
      aRegexString -
      Returns:
      parameters, which match the given Regex
    • getParametersFromString

      public static Set<String> getParametersFromString(String aString)
      Parameters:
      aString - to be analyzed for Parameters
      Returns:
      a Set of all Parameters within the given String
    • replaceParamsInFile

      public static void replaceParamsInFile(FWObservable aObservable, File aFile)
      Parameters:
      aFile -
      aObservable - containing Parameter Map and File replaces Parameters and evaluates the expressions within the given Textfile
    • createMapFromCollection

      public static <T> Map<T,Object> createMapFromCollection(Collection<T> tLoopList)
      Type Parameters:
      T -
      Parameters:
      tLoopList -
      Returns:
      Map, created from Collection
    • createFormComponentLocaleBundleKey

      public static String createFormComponentLocaleBundleKey(FWObservable aObservable, String aFormComponentID, String aShortKey)
      Creates a locale bundle key for the specified short key. Parameter wildcards in short key are replaced from parameter map. Spaces in short key are replaced by "_". If form component ID is specified, it is used as prefix for locale bundle key (besides standard prefix: .FormComponent).
      Parameters:
      aObservable - used to retrieve the parameter map to replace wildcards in short key (from parameter map)
      aFormComponentID - form component ID, which is used as prefix for localization key (can be null or empty)
      aShortKey - short key
      Returns:
      null if aShortKey is null
    • localizeFormComponentValue

      public static String localizeFormComponentValue(FWObservable aObservable, String aFormComponentID, String aFormComponentValue)
      Localizes a form component value (e.g. table cell value from database) by generating a locale bundle key from value as follows: Parameter wildcards in form component value are replaced from parameter map. Spaces in form component value are replaced by "_". If form component ID is specified, it is used as prefix for locale bundle key (besides standard prefix: .FormComponent).
      Parameters:
      aObservable - used to retrieve the parameter map to replace wildcards in short key (from parameter map)
      aFormComponentID - form component ID, which is used as prefix for localization key (can be null or empty)
      aFormComponentValue - value to determine a localization for
      Returns:
      unchanged form component value, if no localization can be found
    • checkEquals

      public static boolean checkEquals(Object aValueCalculated, Object aValueExpected, FWSimVariable.DATA_TYPE aDATA_TYPE)
    • toStringForm

      public static String toStringForm(Collection<FWSimVariable<?>> aVariableList, String aSeparator)