1 18 19 package org.apache.tools.ant.input; 20 21 import java.io.FileInputStream ; 22 import java.io.IOException ; 23 import java.util.Properties ; 24 import org.apache.tools.ant.BuildException; 25 26 32 public class PropertyFileInputHandler implements InputHandler { 33 private Properties props = null; 34 35 38 public static final String FILE_NAME_KEY = "ant.input.properties"; 39 40 43 public PropertyFileInputHandler() { 44 } 45 46 53 public void handleInput(InputRequest request) throws BuildException { 54 readProps(); 55 56 Object o = props.get(request.getPrompt()); 57 if (o == null) { 58 throw new BuildException("Unable to find input for \'" 59 + request.getPrompt() + "\'"); 60 } 61 request.setInput(o.toString()); 62 if (!request.isInputValid()) { 63 throw new BuildException("Found invalid input " + o 64 + " for \'" + request.getPrompt() + "\'"); 65 } 66 } 67 68 71 private synchronized void readProps() throws BuildException { 72 if (props == null) { 73 String propsFile = System.getProperty(FILE_NAME_KEY); 74 if (propsFile == null) { 75 throw new BuildException("System property " 76 + FILE_NAME_KEY 77 + " for PropertyFileInputHandler not" 78 + " set"); 79 } 80 81 props = new Properties (); 82 83 try { 84 props.load(new FileInputStream (propsFile)); 85 } catch (IOException e) { 86 throw new BuildException("Couldn't load " + propsFile, e); 87 } 88 } 89 } 90 91 } 92 | Popular Tags |