@Test public void testIsExpressionLanguagePresent() { assertTrue(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${value}")); assertTrue(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${myFunction()}")); assertTrue(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${attr:chained():function()}")); assertTrue(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${}")); assertTrue(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "$ ${var}")); assertFalse(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${")); assertFalse(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "$${var}")); assertFalse(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "plain value")); assertFalse(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "plain")); assertFalse(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${'}'")); assertFalse(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${'}")); assertTrue(ExpressionLanguageUtil.isExpressionLanguagePresent(DESCRIPTOR, "${\"'\"}")); }
public static boolean isExpressionLanguagePresent(final PropertyDescriptor descriptor, final String value) { final ExpressionLanguageScope scope = descriptor.getExpressionLanguageScope(); if (scope == null || scope == ExpressionLanguageScope.NONE) { return false; } char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { return true; } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return false; }
ExpressionLanguageUtil { public static boolean isExpressionLanguagePresent(final PropertyDescriptor descriptor, final String value) { final ExpressionLanguageScope scope = descriptor.getExpressionLanguageScope(); if (scope == null || scope == ExpressionLanguageScope.NONE) { return false; } char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { return true; } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return false; } }
ExpressionLanguageUtil { public static boolean isExpressionLanguagePresent(final PropertyDescriptor descriptor, final String value) { final ExpressionLanguageScope scope = descriptor.getExpressionLanguageScope(); if (scope == null || scope == ExpressionLanguageScope.NONE) { return false; } char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { return true; } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return false; }  }
ExpressionLanguageUtil { public static boolean isExpressionLanguagePresent(final PropertyDescriptor descriptor, final String value) { final ExpressionLanguageScope scope = descriptor.getExpressionLanguageScope(); if (scope == null || scope == ExpressionLanguageScope.NONE) { return false; } char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { return true; } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return false; }  static boolean isExpressionLanguagePresent(final PropertyDescriptor descriptor, final String value); }
ExpressionLanguageUtil { public static boolean isExpressionLanguagePresent(final PropertyDescriptor descriptor, final String value) { final ExpressionLanguageScope scope = descriptor.getExpressionLanguageScope(); if (scope == null || scope == ExpressionLanguageScope.NONE) { return false; } char lastChar = 0; int embeddedCount = 0; int expressionStart = -1; boolean oddDollarCount = false; int backslashCount = 0; for (int i = 0; i < value.length(); i++) { final char c = value.charAt(i); if (expressionStart > -1 && (c == '\'' || c == '"') && (lastChar != '\\' || backslashCount % 2 == 0)) { final int endQuoteIndex = findEndQuoteChar(value, i); if (endQuoteIndex < 0) { break; } i = endQuoteIndex; continue; } if (c == '{') { if (oddDollarCount && lastChar == '$') { if (embeddedCount == 0) { expressionStart = i - 1; } } if (expressionStart > -1) { embeddedCount++; } } else if (c == '}') { if (embeddedCount <= 0) { continue; } if (--embeddedCount == 0) { if (expressionStart > -1) { return true; } expressionStart = -1; } } else if (c == '$') { oddDollarCount = !oddDollarCount; } else if (c == '\\') { backslashCount++; } else { oddDollarCount = false; } lastChar = c; } return false; }  static boolean isExpressionLanguagePresent(final PropertyDescriptor descriptor, final String value);  }