ErrorTag extends AbstractBodyTag { String processBody(String body, ErrorObject error) { StringBuilder sb = new StringBuilder(2048); int len = body.length(); boolean dollar = false; int bracketStart = -1; for (int i = 0; i < len; i++) { char ch = body.charAt(i); switch (ch) { case '$': if (dollar) { sb.append(ch); } dollar = true; break; case '{': if (dollar) { bracketStart = i; dollar = false; } else { sb.append(ch); } break; case '}': if (bracketStart >= 0) { String name = body.substring(bracketStart + 1, i); String value = processPlaceholder(name.trim(), error); if (value != null) { sb.append(value); } } bracketStart = -1; break; case '\\': if (i + 1 < len) { char ch2 = body.charAt(i + 1); if (ch2 == '\\' || ch2 == '$') { sb.append(ch2); i++; break; } } default: if (bracketStart < 0) { if (dollar) { sb.append('$'); } sb.append(ch); dollar = false; } break; } } return sb.toString(); }  @AttributeMeta(required = true) void setCode(String code); @AttributeMeta void setEnabled(boolean enabled);  }
@Test public void testCode() { ErrorTag tag = new ErrorTag(); String result = tag.processBody("Code is ${code}.", new ErrorObject("id")); String expected = "Code is id."; Assert.assertEquals(expected, result); }