protected void processVariables(Iterator variables, VelocityContext context, final boolean interactiveMode) throws ArchetypeTemplateProcessingException
{
while (variables.hasNext())
{
Variable var = (Variable) variables.next();
String val = System.getProperty(var.getName(), var.getDefvalue());
if (interactiveMode)
{
StringBuilder message = new StringBuilder();
message.append(var.getName()).append(": ")
.append(NEW_LINE)
.append(StringUtils.repeat("*", MESSAGE_LINE_LENGTH))
.append(NEW_LINE)
.append(NEW_LINE)
.append(StringUtils.center(var.getDescription(), MESSAGE_LINE_LENGTH))
.append(NEW_LINE)
.append(StringUtils.leftPad("[default: " + val + "]", MESSAGE_LINE_LENGTH))
.append(NEW_LINE)
.append(StringUtils.repeat("*", MESSAGE_LINE_LENGTH));
getLogger().info(message.toString());
try
{
String answer = inputHandler.readLine();
if (!StringUtils.isEmpty(answer))
{
val = answer;
}
}
catch (IOException ie)
{
throw new ArchetypeTemplateProcessingException(ie);
}
context.put(var.getName(), val);
}
else
{
context.put(var.getName(), val);
}
if (val.toLowerCase().equals("false") || val.toLowerCase().equals("n"))
{
if (var.getVariables() != null)
{
//keep processing the variables picking up the default values
processVariables(var.getVariables().iterator(), context, false);
}
}
else if (var.getVariables() != null)
{
//keep processing the variables in the current interaction mode
processVariables(var.getVariables().iterator(), context, interactiveMode);
}
}
}