Changeset 3477 for trunk/gsdl3
- Timestamp:
- 2002-10-25T11:49:48+13:00 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java
r3440 r3477 32 32 * 33 33 * all file paths are created here 34 * also has file utility methods 34 35 * 35 36 * @author <a href="mailto:[email protected]">Katherine Don</a> … … 70 71 File.separatorChar+"buildcfg.xml"; 71 72 } 73 /** collection build config file path*/ 74 static public String collectionBuildConfigFileBuilding(String site_home, 75 String collection_name ) { 76 return site_home+File.separatorChar+"collect"+ 77 File.separatorChar+collection_name+ 78 File.separatorChar+"building"+ 79 File.separatorChar+"buildcfg.xml"; 80 } 72 81 73 82 /** XML Transform directory path */ … … 81 90 return site_home+File.separatorChar+"collect"+ 82 91 File.separatorChar+collection_name; 92 } 93 /** collection building directory path */ 94 static public String collectionBuildDir(String site_home, 95 String collection_name) { 96 return collectionBaseDir(site_home, collection_name) + 97 File.separatorChar+"building"; 98 } 99 /** collection building directory path */ 100 static public String collectionIndexDir(String site_home, 101 String collection_name) { 102 return collectionBaseDir(site_home, collection_name) + 103 File.separatorChar+"index"; 83 104 } 84 105 … … 106 127 File.separatorChar+filename; 107 128 } 108 129 130 static public String siteHome(String gsdl_home, String site_name) { 131 return gsdl_home + File.separatorChar + "sites" + 132 File.separatorChar +site_name; 133 } 134 135 static public String interfaceHome(String gsdl_home, 136 String interface_name) { 137 return gsdl_home + File.separatorChar + "interfaces" + 138 File.separatorChar + interface_name; 139 } 140 141 109 142 /** returns the absolute path to a stylesheet 110 143 * stylesheets are looked for in the following order … … 113 146 static public String stylesheetFile(ConfigVars config, String filename) { 114 147 // try site one first 115 File stylesheet = new File(config.sites_home_+File.separatorChar+116 config.site_name_+File.separatorChar+148 String site_home = siteHome(config.gsdl3_home_, config.site_name_); 149 File stylesheet = new File(site_home +File.separatorChar+ 117 150 "transform"+File.separatorChar+filename); 118 151 if (stylesheet.exists()) { … … 120 153 } 121 154 // try current interface 122 stylesheet = new File(config.interfaces_home_+File.separatorChar+ 123 config.interface_name_+File.separatorChar+ 155 String interface_home = interfaceHome(config.gsdl3_home_, 156 config.interface_name_); 157 stylesheet = new File(interface_home+File.separatorChar+ 124 158 "transform"+File.separatorChar+filename); 125 159 if (stylesheet.exists()) { … … 127 161 } 128 162 // try default interface 129 stylesheet = new File(config.interfaces_home_+File.separatorChar+130 "default"+File.separatorChar+163 interface_home = interfaceHome(config.gsdl3_home_, "default"); 164 stylesheet = new File(interface_home+File.separatorChar+ 131 165 "transform"+File.separatorChar+filename); 132 166 if (stylesheet.exists()) { … … 142 176 public static String translateFile(ConfigVars config, String lang) { 143 177 144 return config.interfaces_home_+File.separatorChar+ 178 return config.gsdl3_home_+File.separatorChar+ 179 "interfaces"+File.separatorChar+ 145 180 "translate"+File.separatorChar+lang+".xml"; 146 181 } … … 219 254 } 220 255 256 public static boolean deleteFile(File f) { 257 258 if (f.isDirectory()) { 259 File[] files = f.listFiles(); 260 for (int i=0; files!=null && i<files.length; i++) { 261 deleteFile(files[i]); 262 } 263 264 } 265 // delete the file or directory 266 return f.delete(); 267 } 268 269 /** Recursively moves the contents of source file to destination, 270 * maintaining paths. 271 * @param source A File representing the directory whose contents you 272 * wish to move. 273 * @param destination A File representing the directory you wish to move 274 * files to. 275 * @return true if successful 276 */ 277 public static boolean moveDirectory(File source, File destination) { 278 279 // first try rename 280 if (source.renameTo(destination)) { 281 return true; 282 } 283 284 // john T. said that this sometimes doesn't work, so you have to copy files manually 285 286 // copied from gatherer Utility class 287 File input[] = source.listFiles(); 288 for(int i = 0; i < input.length; i++) { 289 File output = new File(destination, input[i].getName()); 290 if(input[i].isDirectory()) { 291 moveDirectory(input[i], output); 292 } else { 293 System.out.println("moving directory manually"); 294 // Copy the file 295 try { 296 output.getParentFile().mkdirs(); 297 FileInputStream in = new FileInputStream(input[i]); 298 FileOutputStream out = new FileOutputStream(output); 299 int value = 0; 300 while((value = in.read()) != -1) { 301 out.write(value); 302 } 303 in.close(); 304 out.close(); 305 // Delete file 306 input[i].delete(); 307 } catch (Exception e) { 308 System.out.println("GSFile.moveDirectory: exception: "+e.getMessage()); 309 return false; 310 } 311 312 } 313 } 314 return true; 315 } 316 221 317 }
Note:
See TracChangeset
for help on using the changeset viewer.