1 22 package org.enhydra.kelp.common.importer; 23 24 import org.enhydra.tool.common.PathHandle; 26 import org.enhydra.tool.common.ExtensionFilter; 27 28 import org.enhydra.kelp.common.Constants; 30 import org.enhydra.kelp.common.node.OtterProject; 31 32 import java.io.FileFilter ; 34 import java.io.File ; 35 public class ResourceFilter extends ExtensionFilter implements FileFilter { 37 private OtterProject project = null; 38 private boolean resourcePath = false; 39 private String [] contentTypes = null; 40 41 44 public ResourceFilter() { 45 setDirectoryValid(false); 46 } 47 48 public boolean isResourcePath() { 49 return resourcePath; 50 } 51 52 public void setResourcePath(boolean b) { 53 resourcePath = b; 54 } 55 56 58 public boolean accept(File f) { 59 boolean acceptFile = super.accept(f); 60 PathHandle thisPath = null; 61 62 if (acceptFile && (getProject() == null)) { 63 acceptFile = false; 64 } 65 if (acceptFile && isResourcePath()) { 66 int index = -1; 67 StringBuffer buf = new StringBuffer (); 68 buf.append('/'); 69 buf.append(Constants.DIR_RESOURCES); 70 buf.append('/'); 71 72 thisPath = PathHandle.createPathHandle(f); 73 index = thisPath.getPath().toLowerCase().indexOf(buf.toString()); 74 if (index == -1) { 75 acceptFile = false; 76 } 77 } 78 if (acceptFile) { 79 PathHandle skipPath = null; 80 StringBuffer buf = new StringBuffer (); 81 82 thisPath = PathHandle.createPathHandle(f); 83 buf.append(getProject().getRootPath()); 84 buf.append(File.separator); 85 buf.append(getProject().getProjectRootName()); 86 buf.append('.'); 87 buf.append(Constants.TYPE_HTML); 88 skipPath = PathHandle.createPathHandle(buf.toString()); 89 if (thisPath.equals(skipPath)) { 90 acceptFile = false; 91 } 92 } 93 return acceptFile; 94 } 95 96 public OtterProject getProject() { 97 return project; 98 } 99 100 public void setProject(OtterProject p) { 101 project = p; 102 if (contentTypes == null) { 103 contentTypes = project.getContentTypes(); 104 for (int i = 0; i < contentTypes.length; i++) { 105 addExtension(contentTypes[i]); 106 } 107 } 108 } 109 110 } 111 | Popular Tags |