Ignore:
Timestamp:
2002-10-04T11:30:37+12:00 (22 years ago)
Author:
kjdon
Message:

tidied this up a bit

File:
1 edited

Legend:

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

    r3386 r3440  
    2929
    3030/**
    31  * GSFiles - utility class for Greenstone.
    32  *
    33  * contains File creation methods.
     31 * GSFile - utility class for Greenstone.
     32 *
     33 * all file paths are created here
    3434 *
    3535 * @author <a href="mailto:[email protected]">Katherine Don</a>
     
    3737 * @see File
    3838 */
     39
    3940public class GSFile {
    4041
    41     /** creates a File for the site config file */
    42     static public File siteConfigFile(String site_home) {
    43     return new File(site_home + File.separatorChar+"sitecfg.xml");
    44 
    45     }
    46 
    47     /** creates a File for the collection directory */
    48     static public File collectDirFile(String site_home) {
    49     return new File(site_home+File.separatorChar+"collect");
     42    /**  site config file path */
     43    static public String siteConfigFile(String site_home) {
     44    return site_home + File.separatorChar+"sitecfg.xml";
     45
     46    }
     47
     48    /** collection directory path */
     49    static public String collectDir(String site_home) {
     50    return site_home+File.separatorChar+"collect";
    5051    }
    5152   
    5253   
    53     /** creates a File for the collection config file */
    54     static public File collectionConfigFile(String site_home,
    55                         String collection_name) {
    56     return new File(site_home+File.separatorChar+"collect"+
     54    /** collection config file path*/
     55    static public String collectionConfigFile(String site_home,
     56                          String collection_name) {
     57    return site_home+File.separatorChar+"collect"+
    5758            File.separatorChar+collection_name+
    5859            File.separatorChar+"etc"+
    59             File.separatorChar+"collectcfg.xml");
    60 
    61     }
    62 
    63     /** creates a File for the collection build config file */
    64     static public File collectionBuildConfigFile(String site_home,
    65                          String collection_name ) {
    66     return new File(site_home+File.separatorChar+"collect"+
     60            File.separatorChar+"collectcfg.xml";
     61
     62    }
     63
     64    /** collection build config file path*/
     65    static public String collectionBuildConfigFile(String site_home,
     66                           String collection_name ) {
     67    return site_home+File.separatorChar+"collect"+
    6768            File.separatorChar+collection_name+
    6869            File.separatorChar+"index"+
    69             File.separatorChar+"buildcfg.xml");
    70     }
    71 
    72     /** returns the directory for XML Transforms */
    73     static public String xmlTransformDir(String gsdl_home) {
    74     return gsdl_home+File.separatorChar+"transform";
    75     }
    76 
    77     /** returns the base directory name for a collection */ 
     70            File.separatorChar+"buildcfg.xml";
     71    }
     72
     73    /** XML Transform directory path */
     74    static public String xmlTransformDir(String interface_home) {
     75    return interface_home+File.separatorChar+"transform";
     76    }
     77
     78    /** collection base directory path */   
    7879    static public String collectionBaseDir(String site_home,
    7980                       String collection_name) {
     
    8283    }
    8384
    84     /** returns the text path (for doc retrieval) relative to collectionBaseDir */
     85    /** text path (for doc retrieval) relative to collectionBaseDir */
    8586    static public String collectionTextPath(String collection_name) {
    8687    return "index"+File.separatorChar+"text"+File.separatorChar+
     
    8889    }
    8990
    90     /** returns the index path (for querying) relative to collectionBaseDir */
     91    /** index path (for querying) relative to collectionBaseDir */
    9192    static public String collectionIndexPath(String collection_name,
    9293                         String index_name) {
     
    9596    }
    9697
    97     /** returns an absolute path for an associated file */
     98    /** absolute path for an associated file */
    9899    static public String assocFileAbsolutePath(String site_home,
    99100                           String collection_name,
     
    108109    /** returns the absolute path to a stylesheet
    109110     * stylesheets are looked for in the following order
    110      * site-specific, ui specific, default
    111      * returns null  if the file cannot be found*/
    112     /*    static public String stylesheetPath(String gsdl_home, String display_home,
    113                     String site_home, String filename) {
    114 
    115     // try site one first
    116     File stylesheet = new File(site_home+File.separatorChar+"transform"+
    117                    File.separatorChar+filename);
    118     if (stylesheet.exists()) {
    119         return stylesheet.getPath();
    120     }
    121     // try custom display
    122     stylesheet = new File(display_home+File.separatorChar+"transform"+
    123                    File.separatorChar+filename);
    124     if (stylesheet.exists()) {
    125         return stylesheet.getPath();
    126     }
    127     // return the default one - should we check that it exists here?
    128     stylesheet = new File(gsdl_home+File.separatorChar+"transform"+
    129                    File.separatorChar+filename);
    130     if (stylesheet.exists()) {
    131         return stylesheet.getPath();
    132     }
    133        
    134     // cant find it
    135     return null;
    136     }
    137     */
    138 
    139    
    140     static public String stylesheetPath(ConfigVars config, String filename) {
     111     * site-specific, interface-specific, default
     112     * returns null  if the file cannot be found */
     113    static public String stylesheetFile(ConfigVars config, String filename) {
    141114    // try site one first
    142115    File stylesheet = new File(config.sites_home_+File.separatorChar+
     
    146119        return stylesheet.getPath();
    147120    }
    148     // try custom display
     121    // try current interface
    149122    stylesheet = new File(config.interfaces_home_+File.separatorChar+
    150123                  config.interface_name_+File.separatorChar+
     
    153126        return stylesheet.getPath();
    154127    }
    155     // return the default one - should we check that it exists here?
     128    // try default interface
    156129    stylesheet = new File(config.interfaces_home_+File.separatorChar+
    157130                  "default"+File.separatorChar+
     
    164137    return null;
    165138    }
     139
     140
     141    /** language specific files directory */
     142    public static String translateFile(ConfigVars config, String lang) {
     143   
     144    return config.interfaces_home_+File.separatorChar+
     145        "translate"+File.separatorChar+lang+".xml";
     146    }   
     147    /** base directory for phind data */
     148    public static String phindBaseDir(String site_home, String coll_name,
     149                      String phind_index) {
     150    return site_home + File.separatorChar +
     151        "collect" + File.separatorChar +
     152        coll_name + File.separatorChar +
     153        "index" + File.separatorChar +
     154        "phind"+phind_index;
     155    }
     156
     157    /** the gdbm database file -
     158     * note, need to change extension depending on OS */
     159    static public String GDBMDatabaseFile(String site_home,
     160                      String collection_name) {
     161
     162    return site_home + File.separatorChar +
     163        "collect" + File.separatorChar +
     164        collection_name + File.separatorChar +
     165        "index" + File.separatorChar + "text" + File.separatorChar +
     166        collection_name + ".ldb";
     167
     168    }
     169
     170    // some file utility methods
     171
     172    /** read in a file and encode it using base64
     173     * encoded data returned as a String */
    166174    static public String base64EncodeFromFile(String in_filename) {
    167175    byte [] data=null;
     
    175183
    176184    }
     185
     186    /** decode some base64 data, and write it to the specified file */
    177187    static public boolean base64DecodeToFile(String data, String out_filename) {
    178188    try {
     
    188198    }
    189199
     200    /** read in a file to a byte array */
    190201    public static byte[] readFile(String filename) throws IOException {
    191202    File file = new File(filename);
     
    198209    return buffer;
    199210    }
     211
     212    /** write a byte array to a file */
    200213    public static void writeFile(byte [] buffer, String filename) throws IOException {
    201214    File file = new File(filename);
     
    206219    }
    207220
    208     // this assumes that lang stuff is in its own directory -
    209     //interfaces_home/translate
    210     public static String getLangPath(ConfigVars config, String lang) {
    211    
    212     return config.interfaces_home_+File.separatorChar+
    213         "translate"+File.separatorChar+lang+".xml";
    214     }   
    215 
    216     public static File getLangFile(ConfigVars config, String lang) {
    217    
    218     return new File(config.interfaces_home_+File.separatorChar+
    219         "translate"+File.separatorChar+lang+".xml");
    220     }
    221 
    222     public static String phindBasePath(String site_home, String coll_name,
    223                        String phind_index) {
    224     return site_home + File.separatorChar +
    225         "collect" + File.separatorChar +
    226         coll_name + File.separatorChar +
    227         "index" + File.separatorChar +
    228         "phind"+phind_index;
    229     }
    230 
    231221}
Note: See TracChangeset for help on using the changeset viewer.