Changeset 1508 for trunk/grails-app/services/dbnp
- Timestamp:
- Feb 9, 2011, 11:10:38 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/dbnp/studycapturing/FileService.groovy
r1430 r1508 15 15 package dbnp.studycapturing 16 16 17 import java.io.File; 18 17 19 import org.codehaus.groovy.grails.commons.ApplicationHolder 20 import org.codehaus.groovy.grails.commons.ConfigurationHolder 18 21 19 22 class FileService implements Serializable { … … 29 32 */ 30 33 def File getUploadDir() { 31 // Find the absolute path to the fileuploads directory. This code is foundon32 // http://stackoverflow.com/questions/491067/how-to-find-the-physical-path-of-a-gsp-file-in-a-deployed-grails-application 33 // 34 // The code used in NMC-DSP didn't work, because that code only works in 35 // controllers: 36 // grailsAttributes.getApplicationContext().getResource("/fileuploads").getFile(); 37 return ApplicationHolder.application.parentContext.getResource("fileuploads").getFile() 34 // Find the file upload directory name from the configuration 35 String dir = ConfigurationHolder.config.uploads.uploadDir 36 37 if( !dir ) 38 dir = "fileuploads" 39 40 return absolutePath( dir ); 38 41 } 42 43 /** 44 * Returns the absolute path for the given pathname. If the pathname is relative, it is taken relative to the web-app directory 45 * @param pathname 46 * @return 47 */ 48 private File absolutePath( String pathname ) { 49 if( pathname == null) 50 return null 51 52 // Check if this is an absolute path 53 File f = new File( pathname ); 54 55 if( f.isAbsolute() ) { 56 return f 57 } else { 58 // Find the absolute path relative to the web-app directory. This code is found on 59 // http://stackoverflow.com/questions/491067/how-to-find-the-physical-path-of-a-gsp-file-in-a-deployed-grails-application 60 return ApplicationHolder.application.parentContext.getResource(pathname).getFile() 61 } 62 } 39 63 40 64 /**
Note: See TracChangeset
for help on using the changeset viewer.