Ejemplo n.º 1
0
  /**
   * Using the given String-representation of the value and the current InformationState, calculate
   * the current Value
   *
   * @param str - the String-representation of the value
   * @param is - the current InformationState
   * @return Value
   * @throws TemplateRunException
   */
  public Value getDynamicValue(String str, InformationState is) throws TemplateRunException {
    /* Determine the start-index and the end-index of the IS-reference, and create the IS-path */
    int startindex = str.indexOf("$");
    if (startindex == -1) {
      throw new TemplateRunException("Missing $-sign in referenced value (" + str + ").");
    }
    int endindex = -1;
    for (int i = startindex + 1; i < str.length(); i++) {
      char ch = str.charAt(i);
      if (!(Character.isLetter(ch) || Character.isDigit(ch) || ch == '_' || ch == '.')) {
        endindex = i;
      }
    }
    if (endindex == -1) {
      endindex = str.length();
    }
    String path = str.substring(startindex, endindex);

    /* Use the reference-path, get the InformationState-Item of the corresponding IS-variable */
    Item item = is.getValueOfPath(path);
    if (item == null) {
      return null;
    } else {
      return new Value(item);
    }
  }