class NetworkUtil {

    public static String replaceExpression(String pValue) {
        if (pValue == null) {
            return null;
        }
        Matcher matcher = EXPRESSION_EXTRACTOR.matcher(pValue);
        StringBuffer ret = new StringBuffer();
        try {
            while (matcher.find()) {
                String var = matcher.group(1);
                String value;
                if (var.equalsIgnoreCase("host")) {
                    value = getLocalAddress().getHostName();
                } else if (var.equalsIgnoreCase("ip")) {
                    value = getLocalAddress().getHostAddress();
                } else {
                    String key = extractKey(var,"env");
                    if (key != null)  {
                        value = System.getenv(key);
                    } else {
                        key = extractKey(var,"prop");
                        if (key != null) {
                            value = System.getProperty(key);
                        } else {
                            throw new IllegalArgumentException("Unknown expression " + var + " in " + pValue);
                        }
                    }
                }
                matcher.appendReplacement(ret, value != null ? value.trim() : null);
            }
            matcher.appendTail(ret);
        } catch (IOException e) {
            throw new IllegalArgumentException("Cannot lookup host" + e, e);
        }
        return ret.toString();
    }

    private  NetworkUtil();

}