@Test public void testSplitAbbreviate() { assertEquals(SHORT_TEXT, XsltHelper.split(SHORT_TEXT, 13, 1, true)); assertEquals("A short...", XsltHelper.split(SHORT_TEXT, 12, 1, true)); assertEquals("A short...", XsltHelper.split(SHORT_TEXT, 11, 1, true)); assertEquals("A short...", XsltHelper.split(SHORT_TEXT, 10, 1, true)); assertEquals("A shor...", XsltHelper.split(SHORT_TEXT, 9, 1, true)); assertEquals("A sho...", XsltHelper.split(SHORT_TEXT, 8, 1, true)); assertEquals("A sh...", XsltHelper.split(SHORT_TEXT, 7, 1, true)); assertEquals("A...", XsltHelper.split(SHORT_TEXT, 6, 1, true)); assertEquals("A...", XsltHelper.split(SHORT_TEXT, 5, 1, true)); assertEquals("A...", XsltHelper.split(SHORT_TEXT, 4, 1, true)); assertEquals("A", XsltHelper.split(SHORT_TEXT, 3, 1, true)); assertEquals("A", XsltHelper.split(SHORT_TEXT, 2, 1, true)); assertEquals("A", XsltHelper.split(SHORT_TEXT, 1, 1, true)); assertEquals(SHORT_TEXT, XsltHelper.split(SHORT_TEXT, 0, 1, true)); }
public static String split(String text, int maxChars, int line, boolean isLastLine) { if (text == null || line < 1) { return null; } if ((maxChars > text.length() && line == 1) || maxChars == 0) { return text; } String textWithSeparator = WordUtils.wrap(text, maxChars, LINE_SEPARATOR, true); String[] lines = textWithSeparator.split(LINE_SEPARATOR); if (lines.length >= line) { if (isLastLine && (lines.length > line) && (maxChars > 3)) { String lastLine = lines[line - 1] + "..."; return StringUtils.abbreviate(lastLine, maxChars); } else { return lines[line - 1]; } } else { return null; } }
XsltHelper { public static String split(String text, int maxChars, int line, boolean isLastLine) { if (text == null || line < 1) { return null; } if ((maxChars > text.length() && line == 1) || maxChars == 0) { return text; } String textWithSeparator = WordUtils.wrap(text, maxChars, LINE_SEPARATOR, true); String[] lines = textWithSeparator.split(LINE_SEPARATOR); if (lines.length >= line) { if (isLastLine && (lines.length > line) && (maxChars > 3)) { String lastLine = lines[line - 1] + "..."; return StringUtils.abbreviate(lastLine, maxChars); } else { return lines[line - 1]; } } else { return null; } } }
XsltHelper { public static String split(String text, int maxChars, int line, boolean isLastLine) { if (text == null || line < 1) { return null; } if ((maxChars > text.length() && line == 1) || maxChars == 0) { return text; } String textWithSeparator = WordUtils.wrap(text, maxChars, LINE_SEPARATOR, true); String[] lines = textWithSeparator.split(LINE_SEPARATOR); if (lines.length >= line) { if (isLastLine && (lines.length > line) && (maxChars > 3)) { String lastLine = lines[line - 1] + "..."; return StringUtils.abbreviate(lastLine, maxChars); } else { return lines[line - 1]; } } else { return null; } } private  XsltHelper(); }
XsltHelper { public static String split(String text, int maxChars, int line, boolean isLastLine) { if (text == null || line < 1) { return null; } if ((maxChars > text.length() && line == 1) || maxChars == 0) { return text; } String textWithSeparator = WordUtils.wrap(text, maxChars, LINE_SEPARATOR, true); String[] lines = textWithSeparator.split(LINE_SEPARATOR); if (lines.length >= line) { if (isLastLine && (lines.length > line) && (maxChars > 3)) { String lastLine = lines[line - 1] + "..."; return StringUtils.abbreviate(lastLine, maxChars); } else { return lines[line - 1]; } } else { return null; } } private  XsltHelper(); static String split(String text, int maxChars, int line, boolean isLastLine); }
XsltHelper { public static String split(String text, int maxChars, int line, boolean isLastLine) { if (text == null || line < 1) { return null; } if ((maxChars > text.length() && line == 1) || maxChars == 0) { return text; } String textWithSeparator = WordUtils.wrap(text, maxChars, LINE_SEPARATOR, true); String[] lines = textWithSeparator.split(LINE_SEPARATOR); if (lines.length >= line) { if (isLastLine && (lines.length > line) && (maxChars > 3)) { String lastLine = lines[line - 1] + "..."; return StringUtils.abbreviate(lastLine, maxChars); } else { return lines[line - 1]; } } else { return null; } } private  XsltHelper(); static String split(String text, int maxChars, int line, boolean isLastLine);  }