[izpack-changes] r2009 - izpack-src/trunk/src/lib/com/izforge/izpack/panels
noreply at berlios.de
noreply at berlios.de
Thu Jan 24 20:30:39 CET 2008
Author: jgordon
Date: 2008-01-24 20:30:35 +0100 (Thu, 24 Jan 2008)
New Revision: 2009
Modified:
izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
Log:
Added auto-install info for selected directory
Added error messages for no directory and not a directory
Added showMessage() method to encapsulate message dialog
Added auto-install info for selected file
Added error messages for no file and not a file
Added JavaDoc comments for specifying PasswordEqualityValidator and PasswordKeystoreValidator
Added use of multiple validators for password field
Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java 2008-01-24 19:29:48 UTC (rev 2008)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java 2008-01-24 19:30:35 UTC (rev 2009)
@@ -76,6 +76,8 @@
import com.izforge.izpack.util.OsConstraint;
import com.izforge.izpack.util.OsVersion;
import com.izforge.izpack.util.VariableSubstitutor;
+import java.util.ArrayList;
+import java.util.List;
/*---------------------------------------------------------------------------*/
/**
@@ -1060,13 +1062,16 @@
File ffile = new File(file);
if (ffile.isDirectory()){
idata.setVariable((String) field[POS_VARIABLE],file);
+ entries.add(new TextValuePair((String) field[POS_VARIABLE],file));
return true;
}
else {
+ showMessage("dir.notdirectory");
return false;
}
}
else {
+ showMessage("dir.nodirectory");
return false;
}
}
@@ -1078,6 +1083,13 @@
}
}
+ private void showMessage(String messageType)
+ {
+ JOptionPane.showMessageDialog(parent, parent.langpack.getString("UserInputPanel." + messageType + ".message"),
+ parent.langpack.getString("UserInputPanel." + messageType + ".caption"),
+ JOptionPane.WARNING_MESSAGE);
+ }
+
private boolean readFileField(Object[] field)
{
try {
@@ -1088,13 +1100,16 @@
File ffile = new File(file);
if (ffile.isFile()){
idata.setVariable((String) field[POS_VARIABLE],file);
+ entries.add(new TextValuePair((String) field[POS_VARIABLE],file));
return true;
}
else {
+ showMessage("file.notfile");
return false;
}
}
else {
+ showMessage("file.nofile");
return false;
}
}
@@ -1973,8 +1988,24 @@
* <processor class="com.izforge.sample.PWDEncryptor"/>
* </field>
*
+ * </pre>
+ * Additionally, parameters and multiple validators can be used to provide
+ * separate validation and error messages for each case.
+ * <pre>
*
- *
+ * <field type="password" align="left" variable="keystore.password">
+ * <spec>
+ * <pwd txt="Keystore Password:" size="25" set=""/>
+ * <pwd txt="Retype Password:" size="25" set=""/>
+ * </spec>
+ * <validator class="com.izforge.izpack.util.PasswordEqualityValidator" txt="Both keystore passwords must match." id="key for the error text"/>
+ * <validator class="com.izforge.izpack.util.PasswordKeystoreValidator" txt="Could not validate keystore with password and alias provided." id="key for the error text">
+ * <param name="keystoreFile" value="${existing.ssl.keystore}"/>
+ * <param name="keystoreType" value="JKS"/>
+ * <param name="keystoreAlias" value="${keystore.key.alias}"/>
+ * </validator>
+ * </field>
+ *
* </pre>
*
* @param spec a <code>XMLElement</code> containing the specification for the set of password
@@ -1986,12 +2017,15 @@
Vector forPacks = spec.getChildrenNamed(SELECTEDPACKS);
Vector forOs = spec.getChildrenNamed(OS);
String variable = spec.getAttribute(VARIABLE);
- String validator = null;
String message = null;
String processor = null;
XMLElement element = null;
PasswordGroup group = null;
int size = 0;
+ // For multiple validator support
+ Vector validatorsElem = null;
+ List validatorsList = new ArrayList();
+ int vsize = 0;
// ----------------------------------------------------
// get the description and add it to the list of UI
@@ -2003,11 +2037,36 @@
// ----------------------------------------------------
// get the validator and processor if they are defined
// ----------------------------------------------------
- element = spec.getFirstChildNamed(VALIDATOR);
- if (element != null)
+
+ validatorsElem = spec.getChildrenNamed(VALIDATOR);
+ if (validatorsElem != null && validatorsElem.size() > 0)
{
- validator = element.getAttribute(CLASS);
- message = getText(element);
+ vsize = validatorsElem.size();
+ for (int i = 0; i < vsize; i++)
+ {
+ element = (XMLElement) validatorsElem.get(i);
+ String validator = element.getAttribute(CLASS);
+ message = getText(element);
+ HashMap validateParamMap = new HashMap();
+ // ----------------------------------------------------------
+ // check and see if we have any parameters for this validator.
+ // If so, then add them to validateParamMap.
+ // ----------------------------------------------------------
+ Vector validateParams = element.getChildrenNamed(RULE_PARAM);
+ if (validateParams != null && validateParams.size() > 0)
+ {
+ Iterator iter = validateParams.iterator();
+ while (iter.hasNext())
+ {
+ element = (XMLElement) iter.next();
+ String paramName = element.getAttribute(RULE_PARAM_NAME);
+ String paramValue = element.getAttribute(RULE_PARAM_VALUE);
+ // System.out.println("Adding parameter: "+paramName+"="+paramValue);
+ validateParamMap.put(paramName, paramValue);
+ }
+ }
+ validatorsList.add(new ValidatorContainer(validator, message, validateParamMap));
+ }
}
element = spec.getFirstChildNamed(PROCESSOR);
@@ -2016,7 +2075,7 @@
processor = element.getAttribute(CLASS);
}
- group = new PasswordGroup(validator, processor);
+ group = new PasswordGroup(idata, validatorsList, processor);
// ----------------------------------------------------
// extract the specification details
@@ -2067,8 +2126,14 @@
TwoColumnConstraints constraints2 = new TwoColumnConstraints();
constraints2.position = TwoColumnConstraints.EAST;
- uiElements.add(new Object[] { null, PWD_FIELD, variable, constraints2, field,
- forPacks, forOs, null, null, message, group});
+ // Removed message to support pulling from multiple validators
+ uiElements.add(new Object[]{null, PWD_FIELD, variable, constraints2, field,
+ forPacks, forOs, null, null, null, group
+ });
+ // Original
+// uiElements.add(new Object[]{null, PWD_FIELD, variable, constraints2, field,
+// forPacks, forOs, null, null, message, group
+// });
group.addField(field);
}
}
@@ -2097,7 +2162,8 @@
{
group = (PasswordGroup) field[POS_GROUP];
variable = (String) field[POS_VARIABLE];
- message = (String) field[POS_MESSAGE];
+ // Removed to support grabbing the message from multiple validators
+ // message = (String) field[POS_MESSAGE];
}
catch (Throwable exception)
{
@@ -2106,16 +2172,40 @@
if ((variable == null) || (passwordGroupsRead.contains(group))) { return (true); }
passwordGroups.add(group);
- boolean success = !validating || group.validateContents();
+
+ //boolean success = !validating || group.validateContents();
+ boolean success = !validating;
+
+ // Use each validator to validate contents
if (!success)
{
- showWarningMessageDialog(parentFrame, message);
- return (false);
+ int size = group.validatorSize();
+ // System.out.println("Found "+(size)+" validators");
+ for (int i = 0; i < size; i++)
+ {
+ success = group.validateContents(i);
+ if (!success)
+ {
+ JOptionPane.showMessageDialog(parentFrame, group.getValidatorMessage(i),
+ parentFrame.langpack.getString("UserInputPanel.error.caption"),
+ JOptionPane.WARNING_MESSAGE);
+ break;
+ }
+ }
}
- idata.setVariable(variable, group.getPassword());
- entries.add(new TextValuePair(variable, group.getPassword()));
- return (true);
+// // Changed to show messages for each validator
+// if (!success) {
+// JOptionPane.showMessageDialog(parentFrame, message, parentFrame.langpack.getString("UserInputPanel.error.caption"), JOptionPane.WARNING_MESSAGE);
+// return (false);
+// }
+
+ if (success)
+ {
+ idata.setVariable(variable, group.getPassword());
+ entries.add(new TextValuePair(variable, group.getPassword()));
+ }
+ return success;
}
/*--------------------------------------------------------------------------*/
More information about the izpack-changes
mailing list