1 23 package org.enhydra.xml.xmlc.taskdef; 24 25 import java.io.File ; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 30 36 public class DefaultXmlcUtilsImpl extends XmlcUtils { 37 38 42 46 protected DefaultXmlcUtilsImpl() { 47 super(); 48 } 49 50 54 65 public String [] getOptionFiles(File theDirectory) { 66 return this.getOptionFiles(theDirectory,(String )null); 67 } 68 69 83 public String [] getOptionFiles(File theDirectory, String theOptionsFileName) { 84 File [] dirs = { theDirectory }; 85 return this.getOptionFiles(dirs, theOptionsFileName); 86 } 87 88 102 public String [] getOptionFiles(File theDirectory, String [] theOptionsFileNames) { 103 File [] dirs = { theDirectory }; 104 return this.getOptionFiles(dirs, theOptionsFileNames); 105 } 106 107 121 public String [] getOptionFiles(File [] theDirectories, String theOptionsFileName) { 122 String [] files = { theOptionsFileName }; 123 return this.getOptionFiles(theDirectories, files); 124 } 125 126 140 public String [] getOptionFiles(File [] theDirectories, String [] theOptionsFileNames) { 141 142 String [] optionsFileNames = theOptionsFileNames; 143 144 if (null != optionsFileNames && optionsFileNames.length > 0) { 145 for (int i = 0; i < optionsFileNames.length; i++) { 146 String currFileName = optionsFileNames[i]; 147 if (null == currFileName || currFileName.length() == 0) { 148 optionsFileNames[i] = DEFAULT_OPTIONS_FILENAME; 149 } 150 if (!optionsFileNames[i].endsWith(DEFAULT_OPTIONS_FILETYPE)) { 151 File tmpFile = new File (optionsFileNames[i]); 152 String tmpName = tmpFile.getName(); 153 int idx = tmpName.lastIndexOf("."); 154 if (-1 == idx) { 155 idx = tmpName.length(); 156 } 157 StringBuffer newFileName = new StringBuffer (tmpName.substring(0,idx)); 158 newFileName.append(DEFAULT_OPTIONS_FILETYPE); 159 optionsFileNames[i] = newFileName.toString(); 160 } 161 } 162 } else { 163 String [] defaultOptionsFileNames = {DEFAULT_OPTIONS_FILENAME}; 164 optionsFileNames = defaultOptionsFileNames; 165 } 166 167 ArrayList allOptionsFiles = new ArrayList (); 168 169 for (int fileNameIdx = 0; fileNameIdx < optionsFileNames.length; fileNameIdx++) { 170 String currFileName = optionsFileNames[fileNameIdx]; 171 for (int dirIdx = 0; dirIdx < theDirectories.length; dirIdx++) { 172 File currDir = theDirectories[dirIdx]; 173 this.addFileIfExists(new File (currDir, currFileName), 174 allOptionsFiles); 175 this.addFileIfExists(new File (currDir, DEFAULT_OPTIONS_FILENAME), 176 allOptionsFiles); 177 } 178 this.addFileIfExists(new File (currFileName), 180 allOptionsFiles); 181 } 182 this.addFileIfExists(new File (DEFAULT_OPTIONS_FILENAME), 183 allOptionsFiles); 184 185 String [] retVal = new String [ allOptionsFiles.size() ]; 186 for (int i = 0; i < allOptionsFiles.size(); i++) { 187 retVal[i] = (String )allOptionsFiles.get(i); 188 } 190 191 return retVal; 192 } 193 194 224 public String buildFullBaseFileName(String thePackageName, 225 String thePackageDir, 226 String theBaseFileName) { 227 File baseFile; 228 int dot = theBaseFileName.indexOf("."); 229 if (dot != -1) 230 baseFile = new File (theBaseFileName.substring(0, dot)); 231 else 232 baseFile = new File (theBaseFileName); 233 if (thePackageDir != null && thePackageDir.length() > 0) 234 { 235 baseFile = new File (thePackageDir, 236 baseFile.getName()); 237 } 238 if (thePackageName != null && thePackageName.length() > 0) 239 { 240 baseFile = new File (thePackageName.replace('.', File.separatorChar), 241 baseFile.getPath()); 242 } 243 return baseFile.getPath().replace(File.separatorChar, '/'); 244 } 245 246 257 public String buildClassName(String theFullBaseFileName, 258 String theModifier) { 259 String className = theFullBaseFileName.replace('/', '.'); 261 className = className.replace(File.separatorChar, '.') + theModifier; 262 return className; 263 } 264 265 269 273 281 private void addFileIfExists(File theFile, List theFileNameList) { 282 if (theFile.exists() && theFile.isFile()) { 283 String path = theFile.getAbsolutePath(); 284 if (!theFileNameList.contains(path)) { 285 theFileNameList.add (path); 286 } 287 } 288 } 289 290 } 291 | Popular Tags |