code: private String resolveTemplate(boolean toValue)
     {
        String result = template;
        if (StringUtils.isEmptyTrimmed(result))
           return result;
  
        String key;
  
        while ((key = StringUtils.getExpressionKey(result)) != null)
        {
           String subs;
           Expression ex = entities.get(key);
           String nKey = StringUtils.getExpressionKey(ex.getDefaultValue());
           if (toValue)
              subs = ex.getValue();
           else if (nKey != null && ex.getResolvedValue() != null &&
                 ex.getDefaultValue().equals(nKey))
           {
              entities.get(nKey).setResolvedValue(ex.getResolvedValue());
              subs = ex.toString();
           }
           else
              subs = ex.toSubstitution();
  
           result = result.replace(key, subs);
        }
        return result;
     }
docs: Resolves the template to the String value depending on boolean switch
  @param toValue if equals true - all Expression entities within the template
  will be presented by their values, otherwise - by their substitutions
  @return resulting String