All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.ibatis.parsing.PropertyParser Maven / Gradle / Ivy

There is a newer version: 3.0-beta-10
Show newest version
package org.apache.ibatis.parsing;

import java.util.Properties;

public class PropertyParser {

  public static String parse(String string, Properties variables) {
    VariableTokenHandler handler = new VariableTokenHandler(variables);
    GenericTokenParser parser = new GenericTokenParser("${", "}", handler);
    return parser.parse(string);
  }

  private static class VariableTokenHandler implements GenericTokenParser.TokenHandler {
    private Properties variables;

    public VariableTokenHandler(Properties variables) {
      this.variables = variables;
    }

    public String handleToken(String content) {
      if (variables != null && variables.containsKey(content)) {
        return variables == null ? content : variables.getProperty(content);
      } else {
        return "${" + content + "}";
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy