00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package dochelper;
00011
00012 import java.io.File;
00013 import java.util.ArrayList;
00014 import java.util.HashMap;
00015
00016 import dochelper.util.FileUtils;
00017
00031 public class FileRecord implements Record {
00032
00034 private File file;
00035
00037 protected HashMap<String, String> params;
00038
00040 private String name;
00041
00049 public FileRecord(File file, String name) {
00050 this.file = file;
00051 this.name = name;
00052
00053 String strpath = getFile().getAbsolutePath().replace(getFile().getName(), "");
00054 String filename = getFile().getName().substring(0, getFile().getName().lastIndexOf("."));
00055 String ext = getFile().getName().substring(getFile().getName().lastIndexOf("."));
00056
00057 params = new HashMap<String, String>();
00058 params.put("filename", filename);
00059 params.put("filepath", strpath);
00060 params.put("extension", ext);
00061
00062 }
00063
00074 public String getValue() {
00075
00076 String fileStr = "";
00077
00078 try {
00079
00080 fileStr = FileUtils.FileToString(getFile());
00081
00082 }
00083 catch (Exception e) {
00084 System.err.println("Error reading contects from file");
00085 }
00086
00087 return fileStr;
00088 }
00089
00100 public ResultNode execute(ArrayList<DocPattern> patterns) {
00101
00102 String value = this.getValue();
00103
00104 ResultNode root = new ResultNode(null, params, name);
00105
00106
00107 if (patterns != null) {
00108 for (DocPattern pattern : patterns) {
00109 root.addChild(pattern.execute(value));
00110 }
00111 }
00112
00113 return root;
00114 }
00115
00121 public File getFile() {
00122 return file;
00123 }
00124
00125 public String toString() {
00126 return "FileRecord: [" + this.name + ", " + params.get("filename") + " ]";
00127 }
00128 }