Changeset 3477 for trunk/gsdl3


Ignore:
Timestamp:
2002-10-25T11:49:48+13:00 (22 years ago)
Author:
kjdon
Message:

now uses gsdl3_home rather than sites_home and interfaces_home
some new File deletion and moving methods added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSFile.java

    r3440 r3477  
    3232 *
    3333 * all file paths are created here
     34 * also has file utility methods
    3435 *
    3536 * @author <a href="mailto:[email protected]">Katherine Don</a>
     
    7071            File.separatorChar+"buildcfg.xml";
    7172    }
     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    }
    7281
    7382    /** XML Transform directory path */
     
    8190    return site_home+File.separatorChar+"collect"+
    8291        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";
    83104    }
    84105
     
    106127        File.separatorChar+filename;
    107128    }
    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   
    109142    /** returns the absolute path to a stylesheet
    110143     * stylesheets are looked for in the following order
     
    113146    static public String stylesheetFile(ConfigVars config, String filename) {
    114147    // 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+
    117150                   "transform"+File.separatorChar+filename);
    118151    if (stylesheet.exists()) {
     
    120153    }
    121154    // 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+
    124158                  "transform"+File.separatorChar+filename);
    125159    if (stylesheet.exists()) {
     
    127161    }
    128162    // 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+
    131165                  "transform"+File.separatorChar+filename);
    132166    if (stylesheet.exists()) {
     
    142176    public static String translateFile(ConfigVars config, String lang) {
    143177   
    144     return config.interfaces_home_+File.separatorChar+
     178    return config.gsdl3_home_+File.separatorChar+
     179        "interfaces"+File.separatorChar+
    145180        "translate"+File.separatorChar+lang+".xml";
    146181    }   
     
    219254    }
    220255
     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   
    221317}
Note: See TracChangeset for help on using the changeset viewer.