1 19 20 package org.netbeans.modules.web.wizards; 21 22 import java.io.IOException ; 23 import java.util.ArrayList ; 24 import java.util.Iterator ; 25 26 import org.openide.ErrorManager; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileStateInvalidException; 29 import org.openide.loaders.DataFolder; 30 import org.openide.util.NbBundle; 31 import org.openide.util.Utilities; 32 import org.netbeans.modules.web.api.webmodule.WebModule; 33 import org.netbeans.api.java.classpath.ClassPath; 34 import org.netbeans.api.java.project.JavaProjectConstants; 35 import org.netbeans.api.project.FileOwnerQuery; 36 import org.netbeans.api.project.Project; 37 import org.netbeans.api.project.ProjectUtils; 38 import org.netbeans.api.project.SourceGroup; 39 import org.netbeans.api.project.Sources; 40 41 class TargetEvaluator extends Evaluator { 42 43 private final boolean debug = false; 44 45 private ArrayList pathItems = null; 46 private DeployData deployData = null; 47 private String errorMessage = null; 48 private String fileName; 49 private boolean initialized = false; 50 private String className; 51 52 TargetEvaluator(FileType fileType, DeployData deployData) { 53 super(fileType); 54 if(debug) { 55 log("::CONSTRUCTOR"); 56 log("file type is " + getFileType().toString()); 57 } 58 this.deployData = deployData; 59 } 60 61 String getErrorMessage() { 62 if(errorMessage == null) return ""; 63 else return errorMessage; 64 } 65 66 69 DeployData getDeployData() { 70 return deployData; 71 } 72 73 77 String getClassName() { 78 return className; 79 93 } 94 95 99 100 void setClassName(String fileName, String targetFolder) { 102 if (targetFolder.length()>0) 103 className=targetFolder+"."+fileName; 104 else className=fileName; 105 this.fileName=fileName; 106 127 } 128 129 132 String getFileName() { 133 return fileName; 134 } 135 136 139 Iterator getPathItems() { 140 if(debug) log("::getPathItems()"+pathItems.size()); return pathItems.iterator(); 142 } 143 144 String getTargetPath() { 145 return super.getTargetPath(pathItems.iterator()); 146 } 147 148 152 153 void setInitialFolder(DataFolder selectedFolder, Project p) { 154 if(selectedFolder == null) { 155 if(debug) log("\t" + "No target folder!"); return; 157 } 158 FileObject targetFolder = selectedFolder.getPrimaryFile(); 159 Sources sources = ProjectUtils.getSources(p); 160 SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); 161 String packageName = null; 162 for (int i = 0; i < groups.length && packageName == null; i++) { 163 packageName = org.openide.filesystems.FileUtil.getRelativePath (groups [i].getRootFolder (), targetFolder); 164 deployData.setWebApp(DeployData.getWebAppFor(groups [i].getRootFolder ())); 165 } 166 if (packageName==null) packageName=""; 167 setInitialPath(packageName); 168 } 169 170 173 boolean isValid() { 174 return true; 175 } 176 177 178 179 186 187 private void setInitialPath(String dirPath) { 188 189 if(debug) log("::setInitialPath()"); 190 191 pathItems = new ArrayList (); 192 193 String path[] = dirPath.split("/"); if(path.length > 0) { 195 for(int i=0; i<path.length; ++i) { 196 if(!path[i].equals("")) { 197 pathItems.add(path[i]); 198 } 199 } 200 } 201 if(debug) log("::setInitialPath():pathItems.size() "+pathItems.size()); 202 } 203 204 private static void log(String s) { 205 System.out.println("TargetEvaluator" + s); 206 } 207 208 private void setAlternativeName (String fileName, FileObject targetFolder) { 209 int index = 0; 210 String tempName = fileName; 211 boolean pathOK = false; 212 while(!pathOK) { 213 pathItems.remove(tempName); 214 tempName = fileName.concat("_").concat(String.valueOf(++index)); 215 pathItems.add(tempName); 216 try { 217 checkFile(pathItems.iterator(),targetFolder); 218 pathOK = true; 219 this.fileName=tempName; 220 } 221 catch(IOException ioex) { 222 pathOK = true; 223 } 224 } 225 } 226 227 } 228 | Popular Tags |