Index: src/build.xml =================================================================== --- src/build.xml (revision 2735) +++ src/build.xml (working copy) @@ -239,8 +239,8 @@ - - + + Index: src/lib/com/izforge/izpack/installer/ConsoleInstaller.java =================================================================== --- src/lib/com/izforge/izpack/installer/ConsoleInstaller.java (revision 2735) +++ src/lib/com/izforge/izpack/installer/ConsoleInstaller.java (working copy) @@ -29,6 +29,7 @@ import com.izforge.izpack.LocaleDatabase; import com.izforge.izpack.Panel; +import com.izforge.izpack.installer.DataValidator.Status; import com.izforge.izpack.util.Debug; import com.izforge.izpack.util.Housekeeper; import com.izforge.izpack.util.OsConstraint; @@ -148,16 +149,21 @@ strCondition); } - if (strAction.equals("doInstall") &&bIsConditionFulfilled) + if (strAction.equals("doInstall") && bIsConditionFulfilled) { - bActionResult = consoleHelperInstance.runConsole(this.installdata); + do + { + bActionResult = consoleHelperInstance.runConsole(this.installdata); + } + while (!validatePanel(p)); } else if (strAction.equals("doGeneratePropertiesFile")) { bActionResult = consoleHelperInstance.runGeneratePropertiesFile( this.installdata, this.printWriter); } - else if (strAction.equals("doInstallFromPropertiesFile") &&bIsConditionFulfilled) + else if (strAction.equals("doInstallFromPropertiesFile") + && bIsConditionFulfilled) { bActionResult = consoleHelperInstance.runConsoleFromPropertiesFile( this.installdata, this.properties); @@ -260,4 +266,35 @@ Housekeeper.getInstance().shutDown(this.result ? 0 : 1); } } + + /** + * Validate a panel. + * + * @param p The panel to validate + * @throws InstallerException thrown if the validation fails. + */ + private boolean validatePanel(final Panel p) throws InstallerException + { + boolean bValidity = true; + String dataValidator = p.getValidator(); + if (dataValidator != null) + { + DataValidator validator = DataValidatorFactory.createDataValidator(dataValidator); + Status validationResult = validator.validateData(installdata); + if (validationResult != DataValidator.Status.OK) + { + // if defaultAnswer is true, result is ok + if (validationResult == Status.WARNING && validator.getDefaultAnswer()) + { + System.out + .println("Configuration said, it's ok to go on, if validation is not successfull"); + + } + // make installation fail instantly + bValidity = false; + System.out.println("Validation failed, please verify your input"); + } + } + return bValidity; + } } Index: src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java =================================================================== --- src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (revision 2735) +++ src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (working copy) @@ -25,9 +25,11 @@ import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Properties; +import java.util.StringTokenizer; import java.util.Vector; import com.izforge.izpack.Panel; @@ -85,6 +87,22 @@ private static final String RADIO_FIELD = "radio"; + private static final String TITLE_FIELD = "title"; + + private static final String CHECK_FIELD = "check"; + + private static final String RULE_FIELD = "rule"; + + static final String DISPLAY_FORMAT = "displayFormat"; + + static final String PLAIN_STRING = "plainString"; + + static final String SPECIAL_SEPARATOR = "specialSeparator"; + + static final String LAYOUT = "layout"; + + static final String RESULT_FORMAT = "resultFormat"; + private static final String DESCRIPTION = "description"; private static final String TRUE = "true"; @@ -138,7 +156,7 @@ { System.out.println(text); } - if (TEXT_FIELD.equals(input.strFieldType)) + if (TEXT_FIELD.equals(input.strFieldType) || RULE_FIELD.equals(input.strFieldType)) { status = status && processTextField(input, idata); } @@ -147,6 +165,10 @@ { status = status && processComboRadioField(input, idata); } + else if (CHECK_FIELD.equals(input.strFieldType)) + { + status = status && processCheckField(input, idata); + } } @@ -357,17 +379,105 @@ } + boolean processCheckField(Input input, AutomatedInstallData idata) + { + String variable = input.strVariableName; + if ((variable == null) || (variable.length() == 0)) { return false; } + String currentvariablevalue = idata.getVariable(variable); + if (currentvariablevalue == null) + { + currentvariablevalue = ""; + } + List lisChoices = input.listChoices; + if (lisChoices.size() == 0) + { + Debug.trace("Error: no spec element defined in check field"); + return false; + } + Choice choice = null; + for (int i = 0; i < lisChoices.size(); i++) + { + choice = lisChoices.get(i); + String value = choice.strValue; + + if ((value != null) && (value.length() > 0) && (currentvariablevalue.equals(value))) + { + input.iSelectedChoice = i; + } + else + { + String set = input.strDefaultValue; + if (set != null) + { + if (set != null && !"".equals(set)) + { + VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables()); + set = vs.substitute(set, null); + } + if (set.equals(TRUE)) + { + input.iSelectedChoice = 1; + } + } + } + } + System.out.println(" [" + (input.iSelectedChoice == 1 ? "x" : " ") + "] " + + (choice.strText != null ? choice.strText : "")); + try + { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + boolean bKeepAsking = true; + + while (bKeepAsking) + { + System.out.println("input 1 to select, 0 to deseclect:"); + String strIn = br.readLine(); + // take default value if default value exists and no user input + if (strIn.trim().equals("")) + { + bKeepAsking = false; + } + int j = -1; + try + { + j = Integer.valueOf(strIn).intValue(); + } + catch (Exception ex) + {} + // take user input if user input is valid + if ((j == 0) || j == 1) + { + input.iSelectedChoice = j; + bKeepAsking = false; + } + } + } + catch (IOException e) + { + e.printStackTrace(); + } + idata.setVariable(variable, input.listChoices.get(input.iSelectedChoice).strValue); + return true; + + } + public Input getInputFromField(IXMLElement field) { String strVariableName = field.getAttribute(VARIABLE); String strFieldType = field.getAttribute(TYPE_ATTRIBUTE); - if (STATIC_TEXT.equals(strFieldType)) + if (TITLE_FIELD.equals(strFieldType)) { String strText = null; strText = field.getAttribute(TEXT); + return new Input(strVariableName, null, null, TITLE_FIELD, strText, 0); + } + else if (STATIC_TEXT.equals(strFieldType)) + { + String strText = null; + strText = field.getAttribute(TEXT); return new Input(strVariableName, null, null, STATIC_TEXT, strText, 0); } - if (TEXT_FIELD.equals(strFieldType)) + else if (TEXT_FIELD.equals(strFieldType)) { List choicesList = new ArrayList(); String strFieldText = null; @@ -388,6 +498,77 @@ return new Input(strVariableName, strSet, choicesList, TEXT_FIELD, strFieldText, 0); } + else if (RULE_FIELD.equals(strFieldType)) + { + + List choicesList = new ArrayList(); + String strFieldText = null; + String strSet = null; + String strText = null; + IXMLElement spec = field.getFirstChildNamed(SPEC); + IXMLElement description = field.getFirstChildNamed(DESCRIPTION); + if (spec != null) + { + strText = field.getFirstChildNamed(SPEC).getAttribute(TEXT); + strSet = field.getFirstChildNamed(SPEC).getAttribute(SET); + } + if (description != null) + { + strFieldText = description.getAttribute(TEXT); + } + if (strSet != null && spec.getAttribute(LAYOUT) != null) + { + StringTokenizer layoutTokenizer = new StringTokenizer(spec.getAttribute(LAYOUT)); + List listSet = Arrays.asList(new String[layoutTokenizer.countTokens()]); + StringTokenizer setTokenizer = new StringTokenizer(strSet); + String token; + while (setTokenizer.hasMoreTokens()) + { + token = setTokenizer.nextToken(); + if (token.indexOf(":") > -1) + { + listSet.set(new Integer(token.substring(0, token.indexOf(":"))).intValue(), + token.substring(token.indexOf(":") + 1)); + } + } + + int iCounter = 0; + StringBuffer sb = new StringBuffer(); + String strRusultFormat = spec.getAttribute(RESULT_FORMAT); + String strSpecialSeparator = spec.getAttribute(SPECIAL_SEPARATOR); + while (layoutTokenizer.hasMoreTokens()) + { + token = layoutTokenizer.nextToken(); + if (token.matches(".*:.*:.*")) + { + sb.append(listSet.get(iCounter) != null ? listSet.get(iCounter) : ""); + iCounter++; + } + else + { + if (SPECIAL_SEPARATOR.equals(strRusultFormat)) + { + sb.append(strSpecialSeparator); + } + else if (PLAIN_STRING.equals(strRusultFormat)) + { + + } + else + // if (DISPLAY_FORMAT.equals(strRusultFormat)) + { + sb.append(token); + } + + } + } + strSet = sb.toString(); + } + choicesList.add(new Choice(strText, null, strSet)); + return new Input(strVariableName, strSet, choicesList, TEXT_FIELD, strFieldText, 0); + + } + else if (COMBO_FIELD.equals(strFieldType) || RADIO_FIELD.equals(strFieldType)) { List choicesList = new ArrayList(); @@ -411,6 +592,41 @@ } return new Input(strVariableName, null, choicesList, COMBO_FIELD, strFieldText, -1); } + else if (CHECK_FIELD.equals(strFieldType)) + { + List choicesList = new ArrayList(); + String strFieldText = null; + String strSet = null; + String strText = null; + int iSelectedChoice = 0; + IXMLElement spec = field.getFirstChildNamed(SPEC); + IXMLElement description = field.getFirstChildNamed(DESCRIPTION); + if (spec != null) + { + strText = spec.getAttribute(TEXT); + strSet = spec.getAttribute(SET); + choicesList.add(new Choice(strText, spec.getAttribute("false"), null)); + choicesList.add(new Choice(strText, spec.getAttribute("true"), null)); + if (strSet != null) + { + if ("true".equals(strSet)) + { + iSelectedChoice = 1; + } + } + } + else + { + System.out.println("No spec specified for input of type check"); + } + + if (description != null) + { + strFieldText = description.getAttribute(TEXT); + } + return new Input(strVariableName, strSet, choicesList, CHECK_FIELD, strFieldText, + iSelectedChoice); + } else { System.out.println(strFieldType + " field collection not implemented");