@Test public void testResolveActivityBody() { final ActivityDTO activity = context.mock(ActivityDTO.class, "activity"); final StreamEntityDTO actor = context.mock(StreamEntityDTO.class, "actor"); final HashMap<String, String> baseObjectProps = new HashMap<String, String>(); context.checking(new Expectations() { { allowing(activity).getBaseObjectProperties(); will(returnValue(baseObjectProps)); allowing(activity).getActor(); will(returnValue(actor)); allowing(actor).getDisplayName(); will(returnValue("John Doe")); } }); activity.getBaseObjectProperties().put("content", "Blah %EUREKA:ACTORNAME% blah %EUREKA:NOSUCH% blah."); String result = sut.resolveActivityBody(activity, velocityContext); context.assertIsSatisfied(); assertEquals("Blah John Doe blah %EUREKA:NOSUCH% blah.", result); }
public String resolveActivityBody(final ActivityDTO activity, final Context context) { StrSubstitutor transform = new StrSubstitutor(new StrLookup() { @Override public String lookup(final String variableName) { if ("ACTORNAME".equals(variableName)) { return activity.getActor().getDisplayName(); } else { return null; } } }, VARIABLE_START_MARKER, VARIABLE_END_MARKER, StrSubstitutor.DEFAULT_ESCAPE); String result = transform.replace(activity.getBaseObjectProperties().get("content")); if (!result.isEmpty()) { int startIndex = 0, lastSeenLinebreakInLeadingWhitespace = -1, endIndex = result.length(); while (startIndex < endIndex) { char c = result.charAt(startIndex); if (!Character.isWhitespace(c)) { break; } if (c != '\t' && Character.getType(c) == Character.CONTROL) { lastSeenLinebreakInLeadingWhitespace = startIndex; } startIndex++; } startIndex = lastSeenLinebreakInLeadingWhitespace + 1; while (startIndex < endIndex && Character.isWhitespace(result.charAt(endIndex - 1))) { endIndex--; } result = result.substring(startIndex, endIndex); } return result; }
NotificationMessageBuilderHelper { public String resolveActivityBody(final ActivityDTO activity, final Context context) { StrSubstitutor transform = new StrSubstitutor(new StrLookup() { @Override public String lookup(final String variableName) { if ("ACTORNAME".equals(variableName)) { return activity.getActor().getDisplayName(); } else { return null; } } }, VARIABLE_START_MARKER, VARIABLE_END_MARKER, StrSubstitutor.DEFAULT_ESCAPE); String result = transform.replace(activity.getBaseObjectProperties().get("content")); if (!result.isEmpty()) { int startIndex = 0, lastSeenLinebreakInLeadingWhitespace = -1, endIndex = result.length(); while (startIndex < endIndex) { char c = result.charAt(startIndex); if (!Character.isWhitespace(c)) { break; } if (c != '\t' && Character.getType(c) == Character.CONTROL) { lastSeenLinebreakInLeadingWhitespace = startIndex; } startIndex++; } startIndex = lastSeenLinebreakInLeadingWhitespace + 1; while (startIndex < endIndex && Character.isWhitespace(result.charAt(endIndex - 1))) { endIndex--; } result = result.substring(startIndex, endIndex); } return result; } }
NotificationMessageBuilderHelper { public String resolveActivityBody(final ActivityDTO activity, final Context context) { StrSubstitutor transform = new StrSubstitutor(new StrLookup() { @Override public String lookup(final String variableName) { if ("ACTORNAME".equals(variableName)) { return activity.getActor().getDisplayName(); } else { return null; } } }, VARIABLE_START_MARKER, VARIABLE_END_MARKER, StrSubstitutor.DEFAULT_ESCAPE); String result = transform.replace(activity.getBaseObjectProperties().get("content")); if (!result.isEmpty()) { int startIndex = 0, lastSeenLinebreakInLeadingWhitespace = -1, endIndex = result.length(); while (startIndex < endIndex) { char c = result.charAt(startIndex); if (!Character.isWhitespace(c)) { break; } if (c != '\t' && Character.getType(c) == Character.CONTROL) { lastSeenLinebreakInLeadingWhitespace = startIndex; } startIndex++; } startIndex = lastSeenLinebreakInLeadingWhitespace + 1; while (startIndex < endIndex && Character.isWhitespace(result.charAt(endIndex - 1))) { endIndex--; } result = result.substring(startIndex, endIndex); } return result; } NotificationMessageBuilderHelper(final String inBaseUrl); }
NotificationMessageBuilderHelper { public String resolveActivityBody(final ActivityDTO activity, final Context context) { StrSubstitutor transform = new StrSubstitutor(new StrLookup() { @Override public String lookup(final String variableName) { if ("ACTORNAME".equals(variableName)) { return activity.getActor().getDisplayName(); } else { return null; } } }, VARIABLE_START_MARKER, VARIABLE_END_MARKER, StrSubstitutor.DEFAULT_ESCAPE); String result = transform.replace(activity.getBaseObjectProperties().get("content")); if (!result.isEmpty()) { int startIndex = 0, lastSeenLinebreakInLeadingWhitespace = -1, endIndex = result.length(); while (startIndex < endIndex) { char c = result.charAt(startIndex); if (!Character.isWhitespace(c)) { break; } if (c != '\t' && Character.getType(c) == Character.CONTROL) { lastSeenLinebreakInLeadingWhitespace = startIndex; } startIndex++; } startIndex = lastSeenLinebreakInLeadingWhitespace + 1; while (startIndex < endIndex && Character.isWhitespace(result.charAt(endIndex - 1))) { endIndex--; } result = result.substring(startIndex, endIndex); } return result; } NotificationMessageBuilderHelper(final String inBaseUrl); String resolveActivityBody(final ActivityDTO activity, final Context context); String cleanWhitespace(final String input); String resolveMarkdownForText(final String input); String resolveMarkdownForHtml(final String input); }
NotificationMessageBuilderHelper { public String resolveActivityBody(final ActivityDTO activity, final Context context) { StrSubstitutor transform = new StrSubstitutor(new StrLookup() { @Override public String lookup(final String variableName) { if ("ACTORNAME".equals(variableName)) { return activity.getActor().getDisplayName(); } else { return null; } } }, VARIABLE_START_MARKER, VARIABLE_END_MARKER, StrSubstitutor.DEFAULT_ESCAPE); String result = transform.replace(activity.getBaseObjectProperties().get("content")); if (!result.isEmpty()) { int startIndex = 0, lastSeenLinebreakInLeadingWhitespace = -1, endIndex = result.length(); while (startIndex < endIndex) { char c = result.charAt(startIndex); if (!Character.isWhitespace(c)) { break; } if (c != '\t' && Character.getType(c) == Character.CONTROL) { lastSeenLinebreakInLeadingWhitespace = startIndex; } startIndex++; } startIndex = lastSeenLinebreakInLeadingWhitespace + 1; while (startIndex < endIndex && Character.isWhitespace(result.charAt(endIndex - 1))) { endIndex--; } result = result.substring(startIndex, endIndex); } return result; } NotificationMessageBuilderHelper(final String inBaseUrl); String resolveActivityBody(final ActivityDTO activity, final Context context); String cleanWhitespace(final String input); String resolveMarkdownForText(final String input); String resolveMarkdownForHtml(final String input);  }