1 2 24 package org.enhydra.tool.archive; 25 26 import org.enhydra.tool.common.FileUtil; 28 import org.enhydra.tool.common.PathHandle; 29 import org.enhydra.tool.common.ResUtil; 30 31 import java.io.File ; 33 import java.io.FileFilter ; 34 import java.util.Arrays ; 35 import java.util.ResourceBundle ; 36 37 public class WarPlan extends JarPlan { 39 40 private String contentRoot = null; 42 private String [] contentFiles = null; 43 44 public WarPlan() { 45 super(); 46 Descriptor[] initDD = new Descriptor[2]; 47 48 initDD[0] = new Descriptor(true, Descriptor.WEB); 49 initDD[1] = new Descriptor(false, Descriptor.ENHYDRA_WEB); 50 setDescriptors(initDD); 51 52 } 53 54 public String getContentRoot() { 55 return contentRoot; 56 } 57 58 public String [] getContentFiles() { 59 return contentFiles; 60 } 61 62 public void setContentFiles(String [] contPaths) { 63 if (isEqual(getContentFileArray(), contPaths)) { 64 contentFiles = null; 65 } else { 66 contentFiles = contPaths; 67 } 68 } 69 70 public void setContentRoot(String in) throws ArchiveException { 71 if (in == null) { 72 throw new ArchiveException(res.getString("Content_directory_is")); 73 } else { 74 PathHandle path = PathHandle.createPathHandle(in); 75 76 if (isValidate()) { 77 if (!path.isDirectory()) { 78 throw new ArchiveException(ResUtil.format(res.getString("Content_directory_not"), 79 path)); 80 } 81 } 82 contentRoot = path.getPath(); 83 } 84 } 85 86 public File [] getContentFileArray() { 87 File [] files = new File [0]; 88 89 fileList.clear(); 90 setFillFilter(new ContentFilter()); 91 if (getContentRoot() == null) { 92 93 } else if (contentFiles == null) { 95 fillFileList(new File (getContentRoot())); 96 } else { 97 for (int i = 0; i < contentFiles.length; i++) { 98 File cursor = new File (contentFiles[i]); 99 100 if (getFillFilter().accept(cursor)) { 101 fileList.add(cursor); 102 } 103 } 104 } 105 fileList.trimToSize(); 106 files = new File [fileList.size()]; 107 files = (File []) fileList.toArray(files); 108 fileList.clear(); 109 return files; 110 } 111 112 public boolean equals(Object comp) { 113 WarPlan plan = null; 114 boolean equal = false; 115 116 if (comp instanceof WarPlan) { 117 plan = (WarPlan) comp; 118 equal = super.equals(comp); 119 } 120 if (equal) { 121 if (plan.getContentRoot() == null && getContentRoot() == null) {} 122 else if (plan.getContentRoot().equals(getContentRoot())) {} 123 else { 124 equal = false; 125 } 126 } 127 if (equal) { 128 if (!Arrays.equals(plan.getContentFiles(), getContentFiles())) { 129 equal = false; 130 } 131 } 132 return equal; 133 } 134 135 private class ContentFilter implements FileFilter { 137 private String [] ddPaths = new String [0]; 138 private PathHandle rootPath = null; 139 140 public ContentFilter() { 141 super(); 142 ddPaths = new String [getDescriptors().length]; 143 rootPath = PathHandle.createPathHandle(getContentRoot()); 144 } 145 146 public boolean accept(File file) { 147 boolean include = false; 148 PathHandle filePath = null; 149 150 for (int i = 0; i < ddPaths.length; i++) { 151 ddPaths[i] = getDescriptors()[i].getPath(); 152 } 153 filePath = PathHandle.createPathHandle(file); 154 if (file.isDirectory()) { 155 include = true; 156 } else if (rootPath.parentOf(filePath)) { 157 include = true; 158 for (int i = 0; i < ddPaths.length; i++) { 159 if (filePath.equals(ddPaths[i])) { 160 include = false; 161 break; 162 } 163 } 164 } 165 return include; 166 } 167 168 } 169 } 170 | Popular Tags |