code: public static String substitute(String input, Object model, Map<String,String> imageMap, boolean lenient)
      throws MdwException {
          StringBuffer substituted = new StringBuffer(input.length());
          try {
              Matcher matcher = tokenPattern.matcher(input);
              int index = 0;
              while (matcher.find()) {
                  String match = matcher.group();
                  substituted.append(input.substring(index, matcher.start()));
                  if (imageMap != null && (match.startsWith("${image:") || match.startsWith("#{image:"))) {
                      String imageFile = match.substring(8, match.length() - 1);
                      String imageId = imageFile.substring(0, imageFile.lastIndexOf('.'));
                      substituted.append("cid:" + imageId);
                      imageMap.put(imageId, imageFile);
                  }
                  else if (match.startsWith("#{")) { // ignore #{... in favor of facelets (except images)
                      substituted.append(match);
                  }
                  else {
                      Object value;
                      if (lenient) {
                          try {
                              value = propUtilsBean.getProperty(model, match.substring(2, match.length() - 1));
                              if (value == null)
                                  value = match;
                          } catch (Exception e) {
                              value = match;
                          }
                      } else {
                          value = propUtilsBean.getProperty(model, match.substring(2, match.length() - 1));
                      }
                      if (value != null)
                          substituted.append(value);
                  }
                  index = matcher.end();
              }
              substituted.append(input.substring(index));
              return substituted.toString();
          }
          catch (Exception ex) {
              throw new MdwException("Error substituting expression value(s)", ex);
          }
      }
docs: Substitutes dynamic values for expressions in the input string.
  @param input raw input string
  @param model object containing the values to substitute
  @param map of images to populate based on special ${image:*.gif} syntax
  @return string with values substituted