001: package org.enhydra.snapperAdmin.business;
002:
003: import java.io.File;
004: import java.util.Calendar;
005: import java.util.Date;
006: import java.util.Vector;
007:
008: import org.enhydra.snapperAdmin.spec.FileType;
009: import org.enhydra.snapperAdmin.spec.Site;
010:
011: //import com.lutris.appserver.server.sql.DBTransaction;
012:
013: /**
014: * FileChecker
015: * <p>
016: * Class that checks size, age and type of the file qued for indexing.
017: * Maximal <code>size</code> and <code>age</code> as well as file <code>types</code>
018: * allowed for the site beeing indexed are stored in the SITES table in the database.
019: *
020: * returns true if the file can
021: */
022:
023: public class FileChecker {
024: long size;
025: Date age;
026: Calendar c1;
027: Site site;
028:
029: public FileChecker() {
030: this .size = -1;
031: this .age = new Date(0);
032:
033: }
034:
035: public FileChecker(int tAge, int size, Site site) {
036: this .site = site;
037:
038: this .c1 = Calendar.getInstance();
039: this .c1.setTimeInMillis(System.currentTimeMillis());
040: this .c1.add(Calendar.DATE, -tAge);
041: //System.out.println("c1: " + c1.getTime());
042:
043: this .size = size * 1024;
044: }
045:
046: public boolean check(File file) {
047: String name = file.getName();
048: String type = null;
049:
050: if (file.isDirectory()) {
051: try {
052: return this .site.getINDEXDIRECTORY();
053: } catch (Exception e) {
054: return false;
055: }
056: }
057:
058: int i = name.lastIndexOf('.');
059: if (i > 0 && i < name.length() - 1) {
060: type = name.substring(i + 1).toLowerCase();
061: } else
062: type = "";
063:
064: Date fileAge = new Date(file.lastModified());
065: try {
066: if (fileAge.after(this .c1.getTime())
067: && (file.length() < this .size)
068: && site.getDocumentGroup() != null) {
069:
070: Vector listDocGrop = (Vector) site.getDocumentGroup()
071: .getListOfDocumentGroup();
072:
073: if (listDocGrop != null) {
074: for (int j = 0; j < listDocGrop.size(); j++) {
075: FileType[] listPT = site.getDocumentGroup()
076: .getListOfFILETYPES(
077: (String) listDocGrop
078: .elementAt(j));
079: if (listPT != null) {
080: for (int k = 0; k < listPT.length; k++) {
081: if (listPT[k].getEXTENSION()
082: .equalsIgnoreCase(type))
083: return true;
084: }
085: }
086:
087: }
088: }
089:
090: if (site.getINDEXUNKNOWNFILETYPES())
091: return true;
092: else
093: return false;
094:
095: }
096: } catch (Exception ex) {
097: System.out.println(ex);
098: }
099:
100: return false;
101: }
102:
103: public boolean check(String fileNAme, long modified) {
104:
105: String type = null;
106:
107: int i = fileNAme.lastIndexOf('.');
108: if (i > 0 && i < fileNAme.length() - 1) {
109: type = fileNAme.substring(i + 1).toLowerCase();
110: } else
111: type = "";
112:
113: Date fileAge = new Date(modified);
114: try {
115: //if (fileAge.after(this.c1.getTime()) && (file.length() < this.size) && site.getDocumentGroup()!=null) {
116: if (fileAge.after(this .c1.getTime())
117: && site.getDocumentGroup() != null) {
118:
119: Vector listDocGrop = (Vector) site.getDocumentGroup()
120: .getListOfDocumentGroup();
121:
122: if (listDocGrop != null) {
123: for (int j = 0; j < listDocGrop.size(); j++) {
124: FileType[] listPT = site.getDocumentGroup()
125: .getListOfFILETYPES(
126: (String) listDocGrop
127: .elementAt(j));
128: if (listPT != null) {
129: for (int k = 0; k < listPT.length; k++) {
130: if (listPT[k].getEXTENSION()
131: .equalsIgnoreCase(type))
132: return true;
133: }
134: }
135:
136: }
137: }
138:
139: if (site.getINDEXUNKNOWNFILETYPES())
140: return true;
141: else
142: return false;
143:
144: }
145: } catch (Exception ex) {
146: System.out.println(ex);
147: }
148:
149: return false;
150: }
151:
152: }
|