FileTypeIconTag extends TagSupport { protected String createImageTag(final String filename, final Properties mappings) { Validate.notNull(filename, "Filename was null or empty"); final String extension = FilenameUtils.getExtension(filename.toLowerCase()); final String icon = extractIconFromMapping(mappings.getProperty(extension)); String description = extractDescriptionFromMapping(mappings.getProperty(extension)); if (description == null) { description = extension; } else { description = StringEscapeUtils.escapeHtml(description); } return "<img src=\"" + icon + "\" title=\"" + description + "\" alt=\"" + description + "\">"; }  @Override int doStartTag(); void setFallbackIcon(final String fallbackIcon); void setFilename(final String filename);  }
@Test public void testCreateImageTag() throws Exception { final Properties mappings = new Properties(); mappings.put("txt", "images/icon_txt.png"); mappings.put("war", "images/icon_file_zip.png;Web archive (WAR)"); final FileTypeIconTag iconTag = new FileTypeIconTag(); try { iconTag.createImageTag(null, mappings); fail("Should throw IllegalArgumentException"); } catch (IllegalArgumentException e) { } assertEquals("<img src=\"images/icon_file.png\" title=\"\" alt=\"\">", iconTag.createImageTag("", mappings)); assertEquals("<img src=\"images/icon_txt.png\" title=\"txt\" alt=\"txt\">", iconTag.createImageTag("filename.txt", mappings)); assertEquals("<img src=\"images/icon_txt.png\" title=\"txt\" alt=\"txt\">", iconTag.createImageTag("filename.TXT", mappings)); assertEquals("<img src=\"images/icon_file_zip.png\" title=\"Web archive (WAR)\" alt=\"Web archive (WAR)\">", iconTag.createImageTag("filename.war", mappings)); }