1 package org.enhydra.snapper.business; 2 3 import java.io.File ; 4 import java.util.Calendar ; 5 import java.util.Date ; 6 7 8 9 18 19 public class FileChecker { 20 long size; 21 Date age; 22 Calendar c1; 23 boolean doc, html, msg, pdf, rtf, txt, xls, ppt, pps, eml, zip, sxw, sxc, other; 24 25 public FileChecker(){ 26 this.size = -1; 27 this.age = new Date (0); 28 29 } 30 31 public FileChecker(int tAge, int size, boolean doc, boolean html, 32 boolean msg, boolean pdf, boolean rtf, boolean txt, boolean xls, 33 boolean ppt, boolean pps, boolean eml, boolean zip, boolean sxw, boolean sxc, boolean other){ 34 this.doc = doc; 35 this.html =html; 36 this.msg = msg; 37 this.pdf = pdf; 38 this.rtf = rtf; 39 this.txt = txt; 40 this.xls = xls; 41 this.ppt = ppt; 42 this.pps = pps; 43 this.eml = zip; 44 this.zip = zip; 45 this.sxw = sxw; 46 this.sxc = sxc; 47 this.other = other; 48 49 c1 = Calendar.getInstance(); 50 c1.setTimeInMillis(System.currentTimeMillis()); 51 c1.add(Calendar.DATE, -tAge); 52 54 this.size = size * 1024; 55 } 56 57 public boolean check(File file){ 58 if (file.isDirectory()) return false; 59 String name = file.getName(); 60 String type = null; 61 int i = name.lastIndexOf('.'); 62 if (i > 0 && i < name.length() - 1) { 63 type = name.substring(i+1).toLowerCase(); 64 } 65 else 66 type = ""; 67 68 Date fileAge = new Date (file.lastModified()); 69 70 try{ 71 if (fileAge.after(c1.getTime()) && (file.length() < size)){ 72 73 if (type.equals("doc")){ 74 if (doc == true) 75 return true; 76 } 77 else if (type.equals("html") || type.equals("htm") ){ 78 if (html == true) 79 return true; 80 } 81 82 else if (type.equals("msg")){ 83 if (msg == true) 84 return true; 85 } 86 87 else if (type.equals("pdf")){ 88 if (pdf == true) 89 return true; 90 } 91 92 else if (type.equals("rtf")){ 93 if (rtf == true) 94 return true; 95 } 96 97 else if (type.equals("txt")){ 98 if (txt == true) 99 return true; 100 } 101 102 else if (type.equals("xls")){ 103 if (xls == true) 104 return true; 105 } 106 107 else if (type.equals("ppt")){ 108 if (ppt == true) 109 return true; 110 } 111 else if (type.equals("pps")){ 112 if (pps == true) 113 return true; 114 } 115 else if (type.equals("eml")){ 116 if (eml == true) 117 return true; 118 } 119 else if (type.equals("zip")){ 120 if (zip == true) 121 return true; 122 } 123 else if (type.equals("sxw")){ 124 if (sxw == true) 125 return true; 126 } 127 else if (type.equals("sxc")){ 128 if (sxc == true) 129 return true; 130 } 131 else if (other == true) 132 return true; 133 134 } 135 136 } catch (Exception ex) { 137 System.out.println(ex); 138 } 140 141 return false; 142 143 } 144 } | Popular Tags |