package filesystem; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class Extensions { ArrayList extensionList; ArrayList extensions; ArrayList extensionName; public Extensions() { super(); //Instantiate variables extensionList = new ArrayList(); extensionName = new ArrayList(); } /** Given a file of a list of extensions * * @param File to read * @param Name of list */ public void addExtensionList(File f, String name) { //Make array and load extensions extensions = new ArrayList(); try{ BufferedReader in = new BufferedReader( new FileReader(f)); String str; while((str = in.readLine()) != null) { extensions.add(str); } extensionList.add(extensions); extensionName.add(name); } catch(IOException e){ } } /** * Given a file name, it checks to see what image to pull up to properly * represent the file graphically and returns the appropriate image * Else, it will return a generic page image * * @return String to resource */ //TODO: Figure out a way to pull down the cyclomatic complexity ? It's @104... public String getExtensionIcon(String fileName) { //Get extension int dotPos = fileName.lastIndexOf('.'); String extension = (fileName.substring(dotPos+1)).toLowerCase(); char initial = extension.charAt(0); //Go through else if statements to determine image if(initial == 'a') { if(extension.equals("ace")) { return ("/resources/32x32/file_extension_ace.png"); } if(extension.equals("ai")) { return ("/resources/32x32/file_extension_ai.png"); } if(extension.equals("aif")) { return ("/resources/32x32/file_extension_aif.png"); } if(extension.equals("aiff")) { return ("/resources/32x32/file_extension_aiff.png"); } if(extension.equals("amr")) { return ("/resources/32x32/file_extension_amr.png"); } if(extension.equals("asf")) { return ("/resources/32x32/file_extension_asf.png"); } if(extension.equals("asx")) { return ("/resources/32x32/file_extension_asx.png"); } } else if(initial == 'b') { if(extension.equals("bat")) { return ("/resources/32x32/file_extension_bat.png"); } if(extension.equals("bin")) { return ("/resources/32x32/file_extension_bin.png"); } if(extension.equals("bmp")) { return ("/resources/32x32/file_extension_bmp.png"); } if(extension.equals("bup")) { return ("/resources/32x32/file_extension_bup.png"); } } else if(initial == 'c') { if(extension.equals("cab")) { return ("/resources/32x32/file_extension_cab.png"); } if(extension.equals("cbr")) { return ("/resources/32x32/file_extension_cbr.png"); } if(extension.equals("cda")) { return ("/resources/32x32/file_extension_cda.png"); } if(extension.equals("cdl")) { return ("/resources/32x32/file_extension_cdl.png"); } if(extension.equals("cdr")) { return ("/resources/32x32/file_extension_cdr.png"); } if(extension.equals("chm")) { return ("/resources/32x32/file_extension_chm.png"); } } else if(initial == 'd') { if(extension.equals("dat")) { return ("/resources/32x32/file_extension_dat.png"); } if(extension.equals("divx")) { return ("/resources/32x32/file_extension_divx.png"); } if(extension.equals("dll")) { return ("/resources/32x32/file_extension_dll.png"); } if(extension.equals("dmg")) { return ("/resources/32x32/file_extension_dmg.png"); } if(extension.equals("doc")) { return ("/resources/32x32/file_extension_doc.png"); } if(extension.equals("docx")) { return ("/resources/32x32/report_word.png"); } if(extension.equals("dss")) { return ("/resources/32x32/file_extension_dss.png"); } if(extension.equals("dvf")) { return ("/resources/32x32/file_extension_dvf.png"); } if(extension.equals("dwg")) { return ("/resources/32x32/file_extension_dwg.png"); } } else if(initial == 'e') { if(extension.equals("eml")) { return ("/resources/32x32/file_extension_eml.png"); } if(extension.equals("eps")) { return ("/resources/32x32/file_extension_eps.png"); } if(extension.equals("exe")) { return ("/resources/32x32/file_extension_exe.png"); } } else if(initial == 'f') { if(extension.equals("fla")) { return ("/resources/32x32/file_extension_fla.png"); } if(extension.equals("flv")) { return ("/resources/32x32/file_extension_flv.png"); } } else if(initial == 'g') { if(extension.equals("gif")) { return ("/resources/32x32/file_extension_gif.png"); } if(extension.equals("gz")) { return ("/resources/32x32/file_extension_gz.png"); } } else if(initial == 'h') { if(extension.equals("hqx")) { return ("/resources/32x32/file_extension_hqx.png"); } if(extension.equals("htm")) { return ("/resources/32x32/file_extension_htm.png"); } if(extension.equals("html")) { return ("/resources/32x32/file_extension_html.png"); } } else if(initial == 'i') { if(extension.equals("ifo")) { return ("/resources/32x32/file_extension_ifo.png"); } if(extension.equals("indd")) { return ("/resources/32x32/file_extension_indd.png"); } if(extension.equals("iso")) { return ("/resources/32x32/file_extension_iso.png"); } } else if(initial == 'j') { if(extension.equals("jar")) { return ("/resources/32x32/file_extension_jar.png"); } if(extension.equals("jpeg")) { return ("/resources/32x32/file_extension_jpeg.png"); } if(extension.equals("jpg")) { return ("/resources/32x32/file_extension_jpg.png"); } } else if(initial == 'l') { if(extension.equals("lnk")) { return ("/resources/32x32/file_extension_lnk.png"); } if(extension.equals("log")) { return ("/resources/32x32/file_extension_log.png"); } } else if(initial == 'm') { if(extension.equals("m4a")) { return ("/resources/32x32/file_extension_m4a.png"); } if(extension.equals("m4b")) { return ("/resources/32x32/file_extension_m4b.png"); } if(extension.equals("m4p")) { return ("/resources/32x32/file_extension_m4p.png"); } if(extension.equals("m4v")) { return ("/resources/32x32/file_extension_m4v.png"); } if(extension.equals("mcd")) { return ("/resources/32x32/file_extension_mcd.png"); } if(extension.equals("mdb")) { return ("/resources/32x32/file_extension_mdb.png"); } if(extension.equals("mid")) { return ("/resources/32x32/file_extension_mid.png"); } if(extension.equals("mkv")) { return ("/resources/32x32/film.png"); } if(extension.equals("mov")) { return ("/resources/32x32/file_extension_mov.png"); } if(extension.equals("mp2")) { return ("/resources/32x32/file_extension_mp2.png"); } if(extension.equals("mp3")) { return ("/resources/32x32/music.png"); } if(extension.equals("mp4")) { return ("/resources/32x32/file_extension_mp4.png"); } if(extension.equals("mpeg")) { return ("/resources/32x32/file_extension_mpeg.png"); } if(extension.equals("msi")) { return ("/resources/32x32/file_extension_msi.png"); } if(extension.equals("mswmm")) { return ("/resources/32x32/file_extension_mswmm.png"); } } else if(initial == 'o') { if(extension.equals("ogg")) { return ("/resources/32x32/file_extension_ogg.png"); } } else if(initial == 'p') { if(extension.equals("pdf")) { return ("/resources/32x32/file_extension_pdf.png"); } if(extension.equals("png")) { return ("/resources/32x32/file_extension_png.png"); } if(extension.equals("pps")) { return ("/resources/32x32/file_extension_pps.png"); } if(extension.equals("ps")) { return ("/resources/32x32/file_extension_ps.png"); } if(extension.equals("psd")) { return ("/resources/32x32/file_extension_psd.png"); } if(extension.equals("pst")) { return ("/resources/32x32/file_extension_pst.png"); } if(extension.equals("ptb")) { return ("/resources/32x32/file_extension_ptb.png"); } if(extension.equals("pub")) { return ("/resources/32x32/file_extension_pub.png"); } } else if(initial == 'q') { if(extension.equals("qbb")) { return ("/resources/32x32/file_extension_qbb.png"); } if(extension.equals("qbw")) { return ("/resources/32x32/file_extension_qbw.png"); } if(extension.equals("qxd")) { return ("/resources/32x32/file_extension_qxd.png"); } } else if(initial == 'r') { if(extension.equals("ram")) { return ("/resources/32x32/file_extension_ram.png"); } if(extension.equals("rar")) { return ("/resources/32x32/file_extension_rar.png"); } if(extension.equals("rb") || extension.equals("rbx")) { return ("/resources/32x32/ruby.png"); } if(extension.equals("rm")) { return ("/resources/32x32/file_extension_rm.png"); } if(extension.equals("rmvb")) { return ("/resources/32x32/file_extension_rmvb.png"); } if(extension.equals("rtf")) { return ("/resources/32x32/file_extension_rtf.png"); } } else if(initial == 's') { if(extension.equals("sea")) { return ("/resources/32x32/file_extension_sea.png"); } if(extension.equals("ses")) { return ("/resources/32x32/file_extension_ses.png"); } if(extension.equals("sit")) { return ("/resources/32x32/file_extension_sit.png"); } if(extension.equals("sitx")) { return ("/resources/32x32/file_extension_sitx.png"); } if(extension.equals("ss")) { return ("/resources/32x32/file_extension_ss.png"); } if(extension.equals("swf")) { return ("/resources/32x32/file_extension_swf.png"); } } else if(initial == 't') { if(extension.equals("tgz")) { return ("/resources/32x32/file_extension_tgz.png"); } if(extension.equals("thm")) { return ("/resources/32x32/file_extension_thm.png"); } if(extension.equals("tif")) { return ("/resources/32x32/file_extension_tif.png"); } if(extension.equals("tmp")) { return ("/resources/32x32/file_extension_tmp.png"); } if(extension.equals("torrent")) { return ("/resources/32x32/file_extension_torrent.png"); } if(extension.equals("ttf")) { return ("/resources/32x32/file_extension_ttf.png"); } if(extension.equals("txt")) { return ("/resources/32x32/file_extension_txt.png"); } } else if(initial == 'u') { if(extension.equals("url")) { return ("/resources/32x32/world_link.png"); } } else if(initial == 'v') { if(extension.equals("vcd")) { return ("/resources/32x32/file_extension_vcd.png"); } if(extension.equals("vob")) { return ("/resources/32x32/file_extension_vob.png"); } } else if(initial == 'w') { if(extension.equals("wav")) { return ("/resources/32x32/file_extension_wav.png"); } if(extension.equals("wma")) { return ("/resources/32x32/file_extension_wma.png"); } if(extension.equals("wmv")) { return ("/resources/32x32/file_extension_wmv.png"); } if(extension.equals("wps")) { return ("/resources/32x32/file_extension_wps.png"); } } else if(initial == 'x') { if(extension.equals("xls")) { return ("/resources/32x32/file_extension_xls.png"); } if(extension.equals("xpi")) { return ("/resources/32x32/file_extension_xpi.png"); } } else if(initial == 'z') { if(extension.equals("zip")) { return ("/resources/32x32/file_extension_zip.png"); } } if(extension.equals("3gp")) { return ("/resources/32x32/file_extension_3gp.png"); } if(extension.equals("7z")) { return ("/resources/32x32/file_extension_7z.png"); } //Default image return ("/resources/32x32/page.png"); } }