1 19 20 package org.netbeans.modules.web.wizards; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 27 import org.openide.filesystems.FileObject; 28 import org.openide.loaders.DataFolder; 29 import org.openide.util.NbBundle; 30 import org.netbeans.api.project.Project; 31 32 37 38 abstract class Evaluator { 39 40 private FileType fileType = null; 41 private static final boolean debug=false; 42 43 Evaluator(FileType fileType) { 44 this.fileType = fileType; 45 } 46 47 abstract boolean isValid(); 48 abstract String getTargetPath(); 49 abstract String getErrorMessage(); 50 abstract Iterator getPathItems(); 51 abstract void setInitialFolder(DataFolder df, Project project); 52 53 FileType getFileType() { 54 return fileType; 55 } 56 57 61 62 String getTargetPath(Iterator pathItems) { 63 64 StringBuffer buffer = new StringBuffer (); 65 while(pathItems.hasNext()) { 66 buffer.append((String )(pathItems.next())); 67 if(pathItems.hasNext()) 68 buffer.append(File.separator); 69 } 70 buffer.append("."); buffer.append(fileType.getSuffix()); 72 return buffer.toString(); 73 } 74 75 void checkFile(Iterator pathItems, FileObject root) throws IOException { 76 if(debug) log("::checkFile() "+root); 78 String pathItem; 79 FileObject fo = root; 80 81 while(pathItems.hasNext()) { 82 83 85 pathItem = (String )(pathItems.next()); 86 if(debug) log("\tpath item is " + pathItem); 88 if(pathItems.hasNext()) { 90 if(debug) log("\tNot the last one"); try { 92 fo = fo.getFileObject(pathItem, null); 93 } 94 catch(IllegalArgumentException iaex) { 95 throw new IOException (NbBundle.getMessage(Evaluator.class, 96 "MSG_clash_path", 97 pathItem)); 98 } 99 if(debug) log("\tfo="+fo); if(fo == null) return; 102 103 if(debug) 104 log("\tgot next file object " + fo.getPath()); 106 if(!fo.isFolder()) { 107 if(debug) log("\tNot a folder"); throw new IOException (NbBundle.getMessage(Evaluator.class, 109 "MSG_clash_path", 110 pathItem)); 111 112 } 113 } 114 else { 115 if(debug) log("\tThis is the last one"); try { 117 fo = fo.getFileObject(pathItem, fileType.getSuffix()); 118 } 119 catch(IllegalArgumentException iaex) { 120 throw new IOException (NbBundle.getMessage(Evaluator.class, 121 "MSG_clash_path", 122 pathItem)); 123 } 124 if(fo == null) return; 125 if(fo.isData()) 126 throw new IOException (NbBundle.getMessage(Evaluator.class, 127 "MSG_file_exists", 128 pathItem)); 129 } 130 } 131 if(debug) log("\tAt end of checkFile()"); } 133 134 private static void log(String s) { 135 System.out.println("Evaluator" + s); 136 } 137 138 } 139 140 | Popular Tags |