1 28 package net.sf.jguard.core.util; 29 30 import java.io.File ; 31 import java.net.URI ; 32 import java.util.logging.Logger ; 33 34 import javax.naming.Context ; 35 import javax.naming.InitialContext ; 36 import javax.naming.NamingException ; 37 38 43 public class FileUtils { 44 45 private static final String FILE = "file"; 46 private static final Logger logger = Logger.getLogger(FileUtils.class.getName()); 47 48 public static File getFile(URI uri){ 49 File file = null; 50 if(uri.getScheme().equals(FileUtils.FILE)){ 51 file = new File (uri); 52 }else{ 53 Context initContext; 54 try { 55 initContext = new InitialContext (); 56 file = (File )initContext.lookup(uri.toString()); 57 } catch (NamingException e) { 58 logger.warning(" file cannot be found : \nthe uri ("+uri.toString()+") pointing to it does not contains a 'file' scheme protocol or does not point to a JNDI object bound "); 59 logger.warning(e.getMessage()); 60 } 61 62 } 63 return file; 64 } 65 66 67 } 68 | Popular Tags |