1 37 package net.sourceforge.cruisecontrol.publishers.email; 38 39 import java.util.Properties ; 40 import java.io.BufferedInputStream ; 41 import java.io.File ; 42 import java.io.FileInputStream ; 43 import java.io.IOException ; 44 45 import net.sourceforge.cruisecontrol.CruiseControlException; 46 47 public class PropertiesMapper extends EmailAddressMapper { 48 49 private String file = null; 50 private final Properties props = new Properties (); 51 52 public PropertiesMapper() { 53 super(); 54 } 55 56 public void setFile(String file) { 57 this.file = file; 58 } 59 60 public String getFile() { 61 return file; 62 } 63 64 public void validate() throws CruiseControlException { 65 if (file == null) { 66 throw new CruiseControlException("'file' not specified in configuration file."); 67 } 68 File f = new File (file); 69 if (!f.exists()) { 70 throw new CruiseControlException("File not found: " + file); 71 } 72 if (!f.canRead()) { 73 throw new CruiseControlException("Can not read file " + file); 74 } 75 if (!f.isFile()) { 76 throw new CruiseControlException(file + " is not a file"); 77 } 78 } 79 80 83 public void open() throws CruiseControlException { 84 File f = new File (getFile()); 85 86 try { 87 props.load(new BufferedInputStream (new FileInputStream (f))); 88 } catch (IOException ie) { 89 throw new CruiseControlException(ie); 90 } 91 } 92 93 public void close() { 94 props.clear(); 95 } 96 97 public String mapUser(String user) { 98 return props.getProperty(user); 99 } 100 } 101 | Popular Tags |