Index: src/lib/com/izforge/izpack/panels/HTMLLicencePanelConsoleHelper.java =================================================================== --- src/lib/com/izforge/izpack/panels/HTMLLicencePanelConsoleHelper.java (revision 2796) +++ src/lib/com/izforge/izpack/panels/HTMLLicencePanelConsoleHelper.java (working copy) @@ -87,7 +87,7 @@ } - int i = askToAcceptLicense(); + int i = askToAcceptLicense(idata); if (i == 1) { @@ -130,30 +130,49 @@ return false; } - private int askToAcceptLicense() + private int askToAcceptLicense(AutomatedInstallData idata) { + String accept = idata.langpack.getString("LicencePanel.agree"); + String reject = idata.langpack.getString("LicencePanel.notagree"); + + + System.out.println(0 + " [ ] " + accept); + System.out.println(1 + " [ ] " + reject); + try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - while (true) + boolean bKeepAsking = true; + + while (bKeepAsking) { - System.out.println("press 1 to accept, 2 to reject, 3 to redisplay"); + System.out.println("0 or 1:"); String strIn = br.readLine(); - if (strIn.equals("1")) + // take default value if default value exists and no user input + if (strIn.trim().equals("") ) { - return 1; + continue; } - else if (strIn.equals("2")) + int j = -1; + try { - return 2; + j = Integer.valueOf(strIn).intValue(); } - else if (strIn.equals("3")) { return 3; } + catch (Exception ex) + {} + // take user input if user input is valid + if (j >= 0 && j < 2) + { + if (j == 0) return 1; + if (j == 1) return 2; + + + } } - } catch (IOException e) { - e.printStackTrace(); + e.printStackTrace(); } return 2; } Index: src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java =================================================================== --- src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (revision 2796) +++ src/lib/com/izforge/izpack/panels/UserInputPanelConsoleHelper.java (working copy) @@ -38,6 +38,8 @@ import com.izforge.izpack.installer.AutomatedInstallData; import com.izforge.izpack.installer.PanelConsole; import com.izforge.izpack.installer.PanelConsoleHelper; +import com.izforge.izpack.installer.ResourceManager; +import com.izforge.izpack.installer.ResourceNotFoundException; import com.izforge.izpack.util.Debug; import com.izforge.izpack.util.OsVersion; import com.izforge.izpack.util.SpecHelper; @@ -56,6 +58,8 @@ private static int instanceCount = 0; private static final String SPEC_FILE_NAME = "userInputSpec.xml"; + + private static final String LANG_FILE_NAME = "userInputLang.xml"; private static final String NODE_ID = "panel"; @@ -75,6 +79,8 @@ private static final String SPEC = "spec"; + private static final String KEY = "id"; + private static final String PWD = "pwd"; private static final String TYPE_ATTRIBUTE = "type"; @@ -132,6 +138,12 @@ private static Input DIVIDER_INPUT_FIELD = new Input(DIVIDER, null, null, DIVIDER, "------------------------------------------", 0); public List listInputs; + + /** + * The installation data. + */ + protected AutomatedInstallData idata; + public UserInputPanelConsoleHelper() { @@ -172,6 +184,25 @@ public boolean runConsole(AutomatedInstallData idata) { + + this.idata = idata; + + // ---------------------------------------------------- + // get a locale database + // ---------------------------------------------------- + try + { + String resource = LANG_FILE_NAME + "_" + this.idata.localeISO3; + idata.langpack.add(ResourceManager.getInstance().getInputStream(resource)); + } + catch (ResourceNotFoundException e) + { + Debug.trace(e); + } + catch (Exception e) + { + e.printStackTrace(); + } boolean processpanel = collectInputs(idata); if (!processpanel) { @@ -438,12 +469,17 @@ while (bKeepAsking) { - System.out.println("input selection:"); + if (input.iSelectedChoice < 0) { + System.out.println("input selection:"); + } else { + System.out.println("input selection [" + input.iSelectedChoice + "]:"); + } String strIn = br.readLine(); // take default value if default value exists and no user input if (strIn.trim().equals("") && input.iSelectedChoice != -1) { bKeepAsking = false; + continue; } int j = -1; try @@ -526,6 +562,7 @@ if (strIn.trim().equals("")) { bKeepAsking = false; + continue; } int j = -1; try @@ -557,15 +594,13 @@ String strFieldType = field.getAttribute(TYPE_ATTRIBUTE); if (TITLE_FIELD.equals(strFieldType)) { - String strText = null; - strText = field.getAttribute(TEXT); - return new Input(strVariableName, null, null, TITLE_FIELD, strText, 0); + String strText = getText(field); + return new Input(strVariableName, null, null, TITLE_FIELD, strText, 0); } if (STATIC_TEXT.equals(strFieldType)) { - String strText = null; - strText = field.getAttribute(TEXT); + String strText = getText(field); return new Input(strVariableName, null, null, STATIC_TEXT, strText, 0); } @@ -579,12 +614,12 @@ IXMLElement description = field.getFirstChildNamed(DESCRIPTION); if (spec != null) { - strText = spec.getAttribute(TEXT); + strText = getText(spec); strSet = spec.getAttribute(SET); } if (description != null) { - strFieldText = description.getAttribute(TEXT); + strFieldText = getText(description); } choicesList.add(new Choice(strText, null, strSet)); return new Input(strVariableName, strSet, choicesList, strFieldType, strFieldText, 0); @@ -602,12 +637,12 @@ IXMLElement description = field.getFirstChildNamed(DESCRIPTION); if (spec != null) { - strText = spec.getAttribute(TEXT); + strText = getText(spec); strSet = spec.getAttribute(SET); } if (description != null) { - strFieldText = description.getAttribute(TEXT); + strFieldText = getText(description); } if (strSet != null && spec.getAttribute(LAYOUT) != null) { @@ -676,7 +711,7 @@ } if (description != null) { - strFieldText = description.getAttribute(TEXT); + strFieldText = getText(description); } for (int i = 0; i < choices.size(); i++) { @@ -748,7 +783,7 @@ choicesList.add(new Choice( - choice.getAttribute(TEXT), + getText(choice), value, set)); @@ -773,7 +808,7 @@ IXMLElement description = field.getFirstChildNamed(DESCRIPTION); if (spec != null) { - strText = spec.getAttribute(TEXT); + strText = getText(spec); strSet = spec.getAttribute(SET); choicesList.add(new Choice(strText, spec.getAttribute("false"), null)); choicesList.add(new Choice(strText, spec.getAttribute("true"), null)); @@ -792,7 +827,7 @@ if (description != null) { - strFieldText = description.getAttribute(TEXT); + strFieldText = getText(description); } return new Input(strVariableName, strSet, choicesList, CHECK_FIELD, strFieldText, iSelectedChoice); @@ -833,7 +868,7 @@ { IXMLElement pwde = pwds.elementAt(i); - strText = pwde.getAttribute(TEXT); + strText = getText(pwde); strSet = pwde.getAttribute(SET); choicesList.add(new Choice(strText, null, strSet)); inputs[i] = new Input(strVariableName, strSet, choicesList, strFieldType, strFieldText, 0); @@ -948,6 +983,51 @@ } return false; } + + /*--------------------------------------------------------------------------*/ + /** + * Extracts the text from an IXMLElement. The text must be defined in the resource + * file under the key defined in the id attribute or as value of the attribute + * txt. + * + * @param element the IXMLElement from which to extract the text. + * @return The text defined in the IXMLElement. If no text can be located, + * null is returned. + */ + /*--------------------------------------------------------------------------*/ + private String getText(IXMLElement element) + { + if (element == null) { return (null); } + + String key = element.getAttribute(KEY); + String text = null; + + if ((key != null) && (idata.langpack != null)) + { + try + { + text = idata.langpack.getString(key); + } + catch (Throwable exception) + { + text = null; + } + } + + // if there is no text in the description, then + // we were unable to retrieve it form the resource. + // In this case try to get the text directly from + // the IXMLElement + if (text == null) + { + text = element.getAttribute(TEXT); + } + + // try to parse the text, and substitute any variable it finds + VariableSubstitutor vs = new VariableSubstitutor(idata.getVariables()); + + return (vs.substitute(text, null)); + } Index: src/lib/com/izforge/izpack/panels/LicencePanelConsoleHelper.java =================================================================== --- src/lib/com/izforge/izpack/panels/LicencePanelConsoleHelper.java (revision 2796) +++ src/lib/com/izforge/izpack/panels/LicencePanelConsoleHelper.java (working copy) @@ -49,7 +49,9 @@ } public boolean runConsole(AutomatedInstallData idata) - { + { + String info = idata.langpack.getString("LicencePanel.info"); + System.out.println(info); String license = null; String resNamePrefix = "LicencePanel.licence"; @@ -84,7 +86,7 @@ } - int i = askToAcceptLicense(); + int i = askToAcceptLicense(idata); if (i == 1) { @@ -126,33 +128,53 @@ } return false; } - - private int askToAcceptLicense() + + private int askToAcceptLicense(AutomatedInstallData idata) { + String accept = idata.langpack.getString("LicencePanel.agree"); + String reject = idata.langpack.getString("LicencePanel.notagree"); + + + System.out.println(0 + " [ ] " + accept); + System.out.println(1 + " [ ] " + reject); + try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - while (true) + boolean bKeepAsking = true; + + while (bKeepAsking) { - System.out.println("press 1 to accept, 2 to reject, 3 to redisplay"); + System.out.println("0 or 1:"); String strIn = br.readLine(); - if (strIn.equals("1")) + // take default value if default value exists and no user input + if (strIn.trim().equals("") ) { - return 1; + continue; } - else if (strIn.equals("2")) + int j = -1; + try { - return 2; + j = Integer.valueOf(strIn).intValue(); } - else if (strIn.equals("3")) { return 3; } + catch (Exception ex) + {} + // take user input if user input is valid + if (j >= 0 && j < 2) + { + if (j == 0) return 1; + if (j == 1) return 2; + + } } - } catch (IOException e) { e.printStackTrace(); + } return 2; + } - + }