FileDocCategorySizeDatePackage
Input.javaAPI DocApache Ant 1.708088Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs

Input

public class Input extends org.apache.tools.ant.Task
Reads an input line from the console.
since
Ant 1.5
ant.task
category="control"

Fields Summary
private String
validargs
private String
message
private String
addproperty
private String
defaultvalue
private Handler
handler
private boolean
messageAttribute
Constructors Summary
public Input()
No arg constructor.

    
Methods Summary
public voidaddText(java.lang.String msg)
Set a multiline message.

param
msg The message to be displayed.

        if (messageAttribute && "".equals(msg.trim())) {
            return;
        }
        message += getProject().replaceProperties(msg);
    
public org.apache.tools.ant.taskdefs.Input$HandlercreateHandler()
Create a nested handler element.

return
a Handler for this Input task.

        if (handler != null) {
            throw new BuildException(
                "Cannot define > 1 nested input handler");
        }
        handler = new Handler();
        return handler;
    
public voidexecute()
Actual method executed by ant.

throws
BuildException on error

        if (addproperty != null
            && getProject().getProperty(addproperty) != null) {
            log("skipping " + getTaskName() + " as property " + addproperty
                + " has already been set.");
            return;
        }

        InputRequest request = null;
        if (validargs != null) {
            Vector accept = StringUtils.split(validargs, ',");
            request = new MultipleChoiceInputRequest(message, accept);
        } else {
            request = new InputRequest(message);
        }
        request.setDefaultValue(defaultvalue);

        InputHandler h = handler == null
            ? getProject().getInputHandler()
            : handler.getInputHandler();

        h.handleInput(request);

        String value = request.getInput();
        if ((value == null || value.trim().length() == 0)
            && defaultvalue != null) {
            value = defaultvalue;
        }
        if (addproperty != null && value != null) {
            getProject().setNewProperty(addproperty, value);
        }
    
public voidsetAddproperty(java.lang.String addproperty)
Defines the name of a property to be created from input. Behaviour is according to property task which means that existing properties cannot be overridden.

param
addproperty Name for the property to be created from input

        this.addproperty = addproperty;
    
public voidsetDefaultvalue(java.lang.String defaultvalue)
Defines the default value of the property to be created from input. Property value will be set to default if not input is received.

param
defaultvalue Default value for the property if no input is received

        this.defaultvalue = defaultvalue;
    
public voidsetMessage(java.lang.String message)
Sets the Message which gets displayed to the user during the build run.

param
message The message to be displayed.

        this.message = message;
        messageAttribute = true;
    
public voidsetValidargs(java.lang.String validargs)
Defines valid input parameters as comma separated strings. If set, input task will reject any input not defined as accepted and requires the user to reenter it. Validargs are case sensitive. If you want 'a' and 'A' to be accepted you need to define both values as accepted arguments.

param
validargs A comma separated String defining valid input args.


                                                                    
         
        this.validargs = validargs;