@Test public void testEvalTokensBadFormats () { Properties props = new Properties (); props.setProperty ("XXX", "testSucceeds"); props.setProperty ("yYy", "123"); String test = "${XXX"; assertEquals (Util.evalTokens (test, props), "${XXX"); test = "${XX${XXX}}"; assertEquals (Util.evalTokens (test, props), "${XX${XXX}}"); ByteArrayOutputStream baos = new ByteArrayOutputStream (); WriterAppender wa = new WriterAppender (new SimpleLayout (), baos); Util.LOGGER.addAppender (wa); test = "${UNKNOWN}"; assertEquals (Util.evalTokens (test, props), "${UNKNOWN}"); String logMsg = baos.toString (); assertTrue (logMsg.contains ("Undefined") && logMsg.contains ("ERROR")); }
public static String evalTokens (String str, Properties props) { if (str == null) return str; if (props == null) return str; String result = str; Matcher m = m_substitutePattern.matcher (str); while (m.find ()) { String subsKey = m.group (1); String tgt = TOKEN_BEGIN + subsKey + TOKEN_END; String tgtVal = props.getProperty (subsKey); if (tgtVal == null) { LOGGER.error (MessageFormat.format ( "Undefined Rainbow property for token substitution: \"{0}\" in \"{1}\"", subsKey, str)); } else { result = result.replace (tgt, tgtVal); } } return result; }
Util { public static String evalTokens (String str, Properties props) { if (str == null) return str; if (props == null) return str; String result = str; Matcher m = m_substitutePattern.matcher (str); while (m.find ()) { String subsKey = m.group (1); String tgt = TOKEN_BEGIN + subsKey + TOKEN_END; String tgtVal = props.getProperty (subsKey); if (tgtVal == null) { LOGGER.error (MessageFormat.format ( "Undefined Rainbow property for token substitution: \"{0}\" in \"{1}\"", subsKey, str)); } else { result = result.replace (tgt, tgtVal); } } return result; } }
Util { public static String evalTokens (String str, Properties props) { if (str == null) return str; if (props == null) return str; String result = str; Matcher m = m_substitutePattern.matcher (str); while (m.find ()) { String subsKey = m.group (1); String tgt = TOKEN_BEGIN + subsKey + TOKEN_END; String tgtVal = props.getProperty (subsKey); if (tgtVal == null) { LOGGER.error (MessageFormat.format ( "Undefined Rainbow property for token substitution: \"{0}\" in \"{1}\"", subsKey, str)); } else { result = result.replace (tgt, tgtVal); } } return result; }  }
Util { public static String evalTokens (String str, Properties props) { if (str == null) return str; if (props == null) return str; String result = str; Matcher m = m_substitutePattern.matcher (str); while (m.find ()) { String subsKey = m.group (1); String tgt = TOKEN_BEGIN + subsKey + TOKEN_END; String tgtVal = props.getProperty (subsKey); if (tgtVal == null) { LOGGER.error (MessageFormat.format ( "Undefined Rainbow property for token substitution: \"{0}\" in \"{1}\"", subsKey, str)); } else { result = result.replace (tgt, tgtVal); } } return result; }  static File computeBasePath(final String configPath); static File getRelativeToPath(File parent, String relPath); static String unifyPath(String path); static String evalTokens(String str, Properties props); static String evalTokens(String str); static String[] evalCommandParameters(String value); static String[] evalCommand(String value); static Object parseObject(String val, String classStr); static Object parsePrimitiveValue(String val, Class<?> clazz); static Logger logger(); static String genID(String name, String target); static Pair<String, String> decomposeID(String id); static ModelReference decomposeModelReference(String modelRef); static String genModelRef(String modelName, String modelType); static String getProcessOutput(Process p); static void setExecutablePermission(String path); static String timestamp(); static String timestampShort(); static String timelog(); static String probeLogTimestamp(); static String probeLogTimestampFor(long milliseconds); static void pause(long ms); static Properties defineLoggerProperties(); static Logger dataLogger(); static void reportStack(String message); static void reportMemUsage(); static Class[] getClasses(String pkgname); static Level reportTypeToPriority(ReportType type); static Properties propertiesByPrefix(String prefix, Properties props); static Properties propertiesByRegex(String regex, Properties props); static boolean safeEquals(Object a, Object b); }
Util { public static String evalTokens (String str, Properties props) { if (str == null) return str; if (props == null) return str; String result = str; Matcher m = m_substitutePattern.matcher (str); while (m.find ()) { String subsKey = m.group (1); String tgt = TOKEN_BEGIN + subsKey + TOKEN_END; String tgtVal = props.getProperty (subsKey); if (tgtVal == null) { LOGGER.error (MessageFormat.format ( "Undefined Rainbow property for token substitution: \"{0}\" in \"{1}\"", subsKey, str)); } else { result = result.replace (tgt, tgtVal); } } return result; }  static File computeBasePath(final String configPath); static File getRelativeToPath(File parent, String relPath); static String unifyPath(String path); static String evalTokens(String str, Properties props); static String evalTokens(String str); static String[] evalCommandParameters(String value); static String[] evalCommand(String value); static Object parseObject(String val, String classStr); static Object parsePrimitiveValue(String val, Class<?> clazz); static Logger logger(); static String genID(String name, String target); static Pair<String, String> decomposeID(String id); static ModelReference decomposeModelReference(String modelRef); static String genModelRef(String modelName, String modelType); static String getProcessOutput(Process p); static void setExecutablePermission(String path); static String timestamp(); static String timestampShort(); static String timelog(); static String probeLogTimestamp(); static String probeLogTimestampFor(long milliseconds); static void pause(long ms); static Properties defineLoggerProperties(); static Logger dataLogger(); static void reportStack(String message); static void reportMemUsage(); static Class[] getClasses(String pkgname); static Level reportTypeToPriority(ReportType type); static Properties propertiesByPrefix(String prefix, Properties props); static Properties propertiesByRegex(String regex, Properties props); static boolean safeEquals(Object a, Object b); static final String FILESEP; static final String PATHSEP; static final String LOGEXT; static final String NEWLINE; static final String NEWLINE_WIN; static final String AT; static final String DOT; static final String DASH; static final String SIZE_SFX; static final int MAX_BYTES; static final int MAX_STRING_BUFFER_LENGTH; static final String TOKEN_BEGIN; static final String TOKEN_END; static final String DEFAULT_LEVEL; static final String DEFAULT_PATTERN; static final int DEFAULT_MAX_SIZE; static final int DEFAULT_MAX_BACKUPS; static final String CONSOLE_PATTERN; static final String DATA_LOGGER_NAME; static final String DATA_PATTERN; }