/** * */ package org.gcube.portlets.user.geoportaldataviewer.client.util; /** * The Class StringUtil. * * @author Francesco Mangiacrapa at ISTI-CNR (francesco.mangiacrapa@isti.cnr.it) * * Nov 16, 2020 */ public class StringUtil { /** * Ellipsize. * * @param input the input string that may be subjected to shortening * @param maxCharacters the maximum characters that must be returned for the input string. Must be at least 3 (that is the ellipses size) * @return the string * @throws Exception the exception */ public static String ellipsize(String input, int maxCharacters) throws Exception{ if(maxCharacters < 3) { throw new IllegalArgumentException("maxCharacters must be at least 3 because the ellipsis already take up 3 characters"); } if (input == null || input.length() < maxCharacters) { return input; } return input.substring(0, maxCharacters)+"..."; } }