Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register
Show
Ignore:
Timestamp:
05/20/08 17:00:47 (8 months ago)
Author:
tmdugan
Message:

-- dss

* cleaned up utility methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs-modules/dss/src/org/openmrs/module/dss/util/IOUtil.java

    r3597 r4278  
    99import java.io.FileInputStream; 
    1010import java.io.FileOutputStream; 
     11import java.io.FilenameFilter; 
    1112import java.io.IOException; 
    1213import java.io.InputStream; 
     
    311312                } 
    312313        } 
     314         
     315        /** 
     316         * Returns a list of file names within a specific directory 
     317         *  
     318         * @param xmlDirectory specific directory 
     319         * @return String[] list of file names 
     320         */ 
     321        public static String[] getFilesInDirectory(String xmlDirectory) 
     322        { 
     323                File dir = new File(xmlDirectory); 
     324 
     325                return dir.list(); 
     326        } 
     327         
     328        public static File[] getFilesInDirectory(String directoryName, final String[] fileExtensions) 
     329        { 
     330                File directory = new File(directoryName); 
     331 
     332                File[] files = directory.listFiles(new FilenameFilter() 
     333                { 
     334                        public boolean accept(File dir, String name) 
     335                        { 
     336                                for(String currFileExtension:fileExtensions) 
     337                                { 
     338                                        return name.endsWith(currFileExtension); 
     339                                } 
     340                                return false; 
     341                        } 
     342                }); 
     343                return files; 
     344        } 
     345         
     346        /** 
     347         * Returns the file name without an extension or directory path 
     348         * @param filepath path to the file 
     349         * @return String file name without an extension or directory path 
     350         */ 
     351        public static String getFilenameWithoutExtension(String filepath) 
     352        { 
     353                String filename = filepath; 
     354                int index = filename.lastIndexOf("/"); 
     355                int index2 = filename.lastIndexOf("\\"); 
     356                 
     357                if(index2 > index) 
     358                { 
     359                        index = index2; 
     360                } 
     361                 
     362                if(index>-1) 
     363                { 
     364                        filename = filename.substring(index+1); 
     365                } 
     366                                 
     367                index = filename.lastIndexOf("."); 
     368                 
     369                if(index > -1) 
     370                { 
     371                        filename = filename.substring(0,index); 
     372                } 
     373                 
     374                return filename; 
     375        } 
     376         
     377        /** 
     378         * Adds slashes if needed to a file directory 
     379         * @param fileDirectory file directory path 
     380         * @return String formatted file directory path 
     381         */ 
     382        public static String formatDirectoryName(String fileDirectory) 
     383        { 
     384                if(!(fileDirectory.endsWith("/")||fileDirectory.endsWith("\\"))) 
     385                { 
     386                        fileDirectory+="/"; 
     387                } 
     388                return fileDirectory; 
     389        } 
    313390}