@Test public void testSplit() { assertEquals(null, XsltHelper.split(null, 50, 1, false)); assertEquals(TEXT1, XsltHelper.split(TEXT1, 0, 1, false)); assertEquals(null, XsltHelper.split(TEXT1, 50, 0, false)); assertEquals(SHORT_TEXT, XsltHelper.split(SHORT_TEXT, 50, 1, false)); assertEquals(null, XsltHelper.split(SHORT_TEXT, 50, 2, false)); assertEquals("Multiscale Climatic, Topographic, and Biotic", XsltHelper.split(TEXT1, 50, 1, false)); assertEquals("Controls of Tree Invasion in a Sub-Alpine Parkland", XsltHelper.split(TEXT1, 50, 2, false)); assertEquals("Landscape, Jefferson Park, Oregon Cascades, USA", XsltHelper.split(TEXT1, 50, 3, false)); assertEquals("The Ancient Ancestors of these Indians here:", XsltHelper.split(TEXT2, 44, 1, false)); assertEquals("The Ancient Ancestors of these Indians", XsltHelper.split(TEXT2, 43, 1, false)); assertEquals("Dies ist ein", XsltHelper.split(TEXT3, 15, 1, false)); assertEquals("\"Klassiker\" zur", XsltHelper.split(TEXT3, 15, 2, false)); assertEquals("Dies ist ein", XsltHelper.split(TEXT3, 23, 1, false)); assertEquals("\"Klassiker\" zur", XsltHelper.split(TEXT3, 23, 2, false)); assertEquals("Dies ist ein \"Klassiker\"", XsltHelper.split(TEXT3, 24, 1, false)); assertEquals("zur Gesprächsführung:", XsltHelper.split(TEXT3, 24, 2, false)); assertEquals("Angehrn Tobias, Biedermann", XsltHelper.split(TEXT4, 31, 1, false)); assertEquals("Angehrn Tobias, Biedermann Anja,", XsltHelper.split(TEXT4, 32, 1, false)); }
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);  }