code: public static String formatResourceName(String name, int maxLength) {
  
          if (name == null) {
              return null;
          }
  
          if (name.length() <= maxLength) {
              return name;
          }
  
          int total = name.length();
          String[] names = CmsStringUtil.splitAsArray(name, "/");
          if (name.endsWith("/")) {
              names[names.length - 1] = names[names.length - 1] + "/";
          }
          for (int i = 1; (total > maxLength) && (i < (names.length - 1)); i++) {
              if (i > 1) {
                  names[i - 1] = "";
              }
              names[i] = "...";
              total = 0;
              for (int j = 0; j < names.length; j++) {
                  int l = names[j].length();
                  total += l + ((l > 0) ? 1 : 0);
              }
          }
          if (total > maxLength) {
              names[0] = (names.length > 2) ? "" : (names.length > 1) ? "..." : names[0];
          }
  
          StringBuffer result = new StringBuffer();
          for (int i = 0; i < names.length; i++) {
              if (names[i].length() > 0) {
                  result.append("/");
                  result.append(names[i]);
              }
          }
  
          return result.toString();
      }
docs: Shortens a resource name or path so that it is not longer than the provided maximum length.<p>
  
  In order to reduce the length of the resource name, only
  complete folder names are removed and replaced with ... successively,
  starting with the second folder.
  The first folder is removed only in case the result still does not fit
  if all subfolders have been removed.<p>
  
  Example: <code>formatResourceName("/myfolder/subfolder/index.html", 21)</code>
  returns <code>/myfolder/.../index.html</code>.<p>
  
  <b>Directly exposed for JSP EL</b>, not through {@link org.opencms.jsp.util.CmsJspElFunctions}.<p>
  
  @param name the resource name to format
  @param maxLength the maximum length of the resource name (without leading <code>/...</code>)
  
  @return the formatted resource name