1 19 20 package org.netbeans.modules.web.wizards; 21 22 import org.openide.filesystems.FileObject; 23 import org.openide.util.NbBundle; 24 import org.openide.WizardDescriptor; 25 29 public class Utilities { 30 37 final public static String canUseFileName (java.io.File dir, String relativePath, String objectName, String extension) { 38 String newObjectName=objectName; 39 if (extension != null && extension.length () > 0) { 40 StringBuffer sb = new StringBuffer (); 41 sb.append (objectName); 42 sb.append ('.'); sb.append (extension); 44 newObjectName = sb.toString (); 45 } 46 47 49 if (!checkFileName(objectName)) { 50 return NbBundle.getMessage (Utilities.class, "MSG_invalid_filename", newObjectName); } 52 FileObject folder = null; 54 if (dir!=null) { 55 try { 56 folder = org.openide.filesystems.FileUtil.toFileObject(dir); 57 } catch(java.lang.IllegalArgumentException ex) { 58 return NbBundle.getMessage (Utilities.class, "MSG_invalid_path", relativePath); } 60 } 61 62 if (folder!= null) { 64 if (!folder.canWrite ()) { 66 return NbBundle.getMessage (Utilities.class, "MSG_fs_is_readonly"); } 68 69 if (folder.getFileObject (newObjectName) != null) { 70 return NbBundle.getMessage (Utilities.class, "MSG_file_already_exist", newObjectName); } 72 73 if (org.openide.util.Utilities.isWindows ()) { 74 if (checkCaseInsensitiveName (folder, newObjectName)) { 75 return NbBundle.getMessage (Utilities.class, "MSG_file_already_exist", newObjectName); } 77 } 78 } 79 80 return null; 82 } 83 84 92 private static boolean checkCaseInsensitiveName (FileObject folder, String name) { 93 java.util.Enumeration children = folder.getChildren (false); 95 FileObject fo; 96 while (children.hasMoreElements ()) { 97 fo = (FileObject) children.nextElement (); 98 if (name.equalsIgnoreCase (fo.getName ())) { 99 return true; 100 } 101 } 102 return false; 103 } 104 105 private static boolean checkFileName(String str) { 106 char c[] = str.toCharArray(); 107 for (int i=0;i<c.length;i++) { 108 if (c[i]=='\\') return false; 109 if (c[i]=='/') return false; 110 } 111 return true; 112 } 113 114 public static String [] createSteps(String [] before, WizardDescriptor.Panel[] panels) { 115 int diff = 0; 118 if (before == null) { 119 before = new String [0]; 120 } else if (before.length > 0) { 121 diff = ("...".equals (before[before.length - 1])) ? 1 : 0; } 123 String [] res = new String [ (before.length - diff) + panels.length]; 124 for (int i = 0; i < res.length; i++) { 125 if (i < (before.length - diff)) { 126 res[i] = before[i]; 127 } else { 128 res[i] = panels[i - before.length + diff].getComponent ().getName (); 129 } 130 } 131 return res; 132 } 133 } 134 | Popular Tags |