FileDocCategorySizeDatePackage
PropertyFileInputHandler.javaAPI DocApache Ant 1.703110Wed Dec 13 06:16:24 GMT 2006org.apache.tools.ant.input

PropertyFileInputHandler

public class PropertyFileInputHandler extends Object implements InputHandler
Reads input from a property file, the file name is read from the system property ant.input.properties, the prompt is the key for input.
since
Ant 1.5

Fields Summary
private Properties
props
public static final String
FILE_NAME_KEY
Name of the system property we expect to hold the file name.
Constructors Summary
public PropertyFileInputHandler()
Empty no-arg constructor.


            
      
    
Methods Summary
public voidhandleInput(InputRequest request)
Picks up the input from a property, using the prompt as the name of the property.

param
request an input request.
exception
BuildException if no property of that name can be found.

        readProps();

        Object o = props.get(request.getPrompt());
        if (o == null) {
            throw new BuildException("Unable to find input for \'"
                                     + request.getPrompt() + "\'");
        }
        request.setInput(o.toString());
        if (!request.isInputValid()) {
            throw new BuildException("Found invalid input " + o
                                     + " for \'" + request.getPrompt() + "\'");
        }
    
private synchronized voidreadProps()
Reads the properties file if it hasn't already been read.

        if (props == null) {
            String propsFile = System.getProperty(FILE_NAME_KEY);
            if (propsFile == null) {
                throw new BuildException("System property "
                                         + FILE_NAME_KEY
                                         + " for PropertyFileInputHandler not"
                                         + " set");
            }

            props = new Properties();

            try {
                props.load(new FileInputStream(propsFile));
            } catch (IOException e) {
                throw new BuildException("Couldn't load " + propsFile, e);
            }
        }