1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.data; 26 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Locale ; 32 import java.util.Map ; 33 import java.util.ResourceBundle ; 34 import java.util.SortedMap ; 35 import java.util.regex.Pattern ; 36 import java.text.MessageFormat ; 37 38 import java.awt.GridBagConstraints ; 39 import java.awt.Insets ; 40 import java.awt.Dimension ; 41 import java.awt.Window ; 42 import java.awt.Container ; 43 import java.awt.Component ; 44 import java.awt.Rectangle ; 45 46 import javax.swing.JPanel ; 47 import javax.swing.JLabel ; 48 import javax.swing.JComboBox ; 49 import javax.swing.JCheckBox ; 50 import javax.swing.JComponent ; 51 import javax.swing.JTextField ; 52 import javax.swing.DefaultComboBoxModel ; 53 54 import org.netbeans.modules.j2ee.sun.share.Constants; 55 import org.netbeans.modules.j2ee.sun.share.configbean.ASDDVersion; 56 import org.netbeans.modules.j2ee.sun.share.configbean.Utils; 57 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.GenericTableDialogPanelAccessor; 58 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.ValidationSupport; 59 import org.netbeans.modules.j2ee.sun.share.configbean.customizers.webapp.LocaleMapping; 60 import org.netbeans.modules.j2ee.sun.share.CharsetMapping; 61 62 66 public class DynamicPropertyPanel extends JPanel 67 implements GenericTableDialogPanelAccessor { 68 69 private boolean isEditPopup; 72 private PropertyList theList; 74 private List paramMappings; 75 private boolean hasDescription; 76 private boolean isEditable; 77 78 private JLabel nameRequiredMark; 80 private JLabel nameLabel; 81 private JLabel valueRequiredMark ; 82 private JLabel valueLabel; 83 private JComboBox propertiesCombo; 84 private JComponent customEditor; 85 private JTextField descriptionField; 86 87 private JTextField customTextField; 89 private JComboBox customComboBox; 90 private JCheckBox customCheckBox; 91 private int normalizedHeight; 92 93 private DefaultComboBoxModel propertyListModel; 95 96 private String name; 98 private ParamMapping nameMapping; 99 private String value; 100 private String description; 101 102 private static final ResourceBundle localBundle = ResourceBundle.getBundle( 104 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 106 private ResourceBundle propertyListBundle; 108 109 private static final String TEXT_TRUE="true"; private static final String TEXT_FALSE="false"; 114 115 116 public DynamicPropertyPanel() { 117 } 120 121 126 private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; 128 129 setLayout(new java.awt.GridBagLayout ()); 130 131 } 133 134 137 private void initUserComponents() { 138 139 customTextField = new JTextField (); 142 customComboBox = new JComboBox (); 143 customCheckBox = new JCheckBox (); 144 145 nameRequiredMark = new JLabel (); 146 nameLabel = new JLabel (); 147 propertiesCombo = new JComboBox (); 148 valueRequiredMark = new JLabel (); 149 valueLabel = new JLabel (); 150 customEditor = customTextField; 152 GridBagConstraints gridBagConstraints; 153 154 int textFieldHeight = customTextField.getPreferredSize().height; 155 int comboBoxHeight = customComboBox.getPreferredSize().height; 156 int checkBoxHeight = customCheckBox.getPreferredSize().height; 157 normalizedHeight = Math.max(textFieldHeight, Math.max(comboBoxHeight, checkBoxHeight)); 158 159 nameRequiredMark.setText(localBundle.getString("LBL_RequiredMark")); nameRequiredMark.setLabelFor(propertiesCombo); 163 gridBagConstraints = new GridBagConstraints (); 164 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 165 gridBagConstraints.insets = new Insets (12, 12, 0, 0); 166 nameRequiredMark.getAccessibleContext().setAccessibleName(localBundle.getString("ACSN_RequiredMark")); nameRequiredMark.getAccessibleContext().setAccessibleDescription(localBundle.getString("ACSD_RequiredMark")); add(nameRequiredMark, gridBagConstraints); 169 170 nameLabel.setText(localBundle.getString("LBL_Name_1")); nameLabel.setDisplayedMnemonic(localBundle.getString("MNE_Name").charAt(0)); nameLabel.setLabelFor(propertiesCombo); 173 gridBagConstraints = new GridBagConstraints (); 174 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 175 gridBagConstraints.insets = new Insets (12, 6, 0, 0); 176 add(nameLabel, gridBagConstraints); 177 178 propertiesCombo.setEditable(isEditable); 179 gridBagConstraints = new GridBagConstraints (); 180 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 181 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 182 gridBagConstraints.insets = new Insets (12, 6, 0, 11); 183 gridBagConstraints.weightx = 1.0; 184 propertiesCombo.getAccessibleContext().setAccessibleName(localBundle.getString("ACSN_Name")); propertiesCombo.getAccessibleContext().setAccessibleDescription(localBundle.getString("ACSD_Name")); add(propertiesCombo, gridBagConstraints); 187 188 propertiesCombo.addActionListener(new java.awt.event.ActionListener () { 189 public void actionPerformed(java.awt.event.ActionEvent evt) { 190 handlePropertiesComboActionPerformed(evt); 191 } 192 }); 193 194 int valueBelow = (hasDescription ? 0 : 11); 195 196 valueRequiredMark.setText(localBundle.getString("LBL_RequiredMark")); valueRequiredMark.setLabelFor(customEditor); 198 gridBagConstraints = new GridBagConstraints (); 199 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 200 gridBagConstraints.insets = new Insets (6, 12, valueBelow, 0); 201 valueRequiredMark.getAccessibleContext().setAccessibleName(localBundle.getString("ACSN_RequiredMark")); valueRequiredMark.getAccessibleContext().setAccessibleDescription(localBundle.getString("ACSD_RequiredMark")); add(valueRequiredMark, gridBagConstraints); 204 205 valueLabel.setText(localBundle.getString("LBL_Value_1")); valueLabel.setDisplayedMnemonic(localBundle.getString("MNE_Value").charAt(0)); valueLabel.setLabelFor(customEditor); 208 gridBagConstraints = new GridBagConstraints (); 209 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 210 gridBagConstraints.insets = new Insets (6, 6, valueBelow, 0); 211 add(valueLabel, gridBagConstraints); 212 213 int extraHeight = normalizedHeight - textFieldHeight; 214 int extraBelow = extraHeight/2; 215 int extraAbove = extraHeight-extraBelow; 216 217 gridBagConstraints = new GridBagConstraints (); 218 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 219 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 220 gridBagConstraints.insets = new Insets (extraAbove+6, 6, extraBelow + valueBelow, 11); 221 gridBagConstraints.weightx = 1.0; 222 customTextField.getAccessibleContext().setAccessibleName(localBundle.getString("ACSN_Value")); customTextField.getAccessibleContext().setAccessibleDescription(localBundle.getString("ACSD_Value")); customComboBox.getAccessibleContext().setAccessibleName(localBundle.getString("ACSN_Value")); customComboBox.getAccessibleContext().setAccessibleDescription(localBundle.getString("ACSD_Value")); customCheckBox.getAccessibleContext().setAccessibleName(localBundle.getString("ACSN_Value")); customCheckBox.getAccessibleContext().setAccessibleDescription(localBundle.getString("ACSD_Value")); add(customEditor, gridBagConstraints); 229 230 if(hasDescription) { 231 JLabel descRequiredMark = new JLabel (); 232 JLabel descLabel = new JLabel (); 233 descriptionField = new JTextField (); 234 235 gridBagConstraints = new GridBagConstraints (); 238 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 239 gridBagConstraints.insets = new Insets (6, 12, 11, 0); 240 add(descRequiredMark, gridBagConstraints); 241 242 descLabel.setText(localBundle.getString("LBL_Description_1")); descLabel.setDisplayedMnemonic(localBundle.getString("MNE_Description").charAt(0)); descLabel.setLabelFor(descriptionField); 245 gridBagConstraints = new GridBagConstraints (); 246 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 247 gridBagConstraints.insets = new Insets (6, 6, 11, 0); 248 add(descLabel, gridBagConstraints); 249 250 gridBagConstraints = new GridBagConstraints (); 251 gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; 252 gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; 253 gridBagConstraints.insets = new Insets (6, 6, 11, 11); 254 gridBagConstraints.weightx = 1.0; 255 descriptionField.getAccessibleContext().setAccessibleName(localBundle.getString("ACSN_Description")); descriptionField.getAccessibleContext().setAccessibleDescription(localBundle.getString("ACSD_Description")); add(descriptionField, gridBagConstraints); 258 259 descriptionField.addKeyListener(new java.awt.event.KeyAdapter () { 260 public void keyReleased(java.awt.event.KeyEvent evt) { 261 handleDescriptionFieldKeyReleased(evt); 262 } 263 }); 264 } 265 266 customTextField.addKeyListener(new java.awt.event.KeyAdapter () { 268 public void keyReleased(java.awt.event.KeyEvent evt) { 269 handleCustomTextFieldKeyReleased(evt); 270 } 271 }); 272 273 customCheckBox.addItemListener(new java.awt.event.ItemListener () { 274 public void itemStateChanged(java.awt.event.ItemEvent evt) { 275 handleCustomCheckBoxItemStateChanged(evt); 276 } 277 }); 278 279 customComboBox.addActionListener(new java.awt.event.ActionListener () { 280 public void actionPerformed(java.awt.event.ActionEvent evt) { 281 handleCustomComboBoxActionPerformed(evt); 282 } 283 }); 284 285 buildMappings(); 288 propertyListModel = new DefaultComboBoxModel (); 289 for(Iterator iter = paramMappings.iterator(); iter.hasNext(); ) { 290 propertyListModel.addElement((ParamMapping) iter.next()); 291 } 292 propertiesCombo.setModel(propertyListModel); 293 } 294 295 private void handleCustomTextFieldKeyReleased(java.awt.event.KeyEvent evt) { 296 if(customEditor == customTextField) { 297 value = customTextField.getText(); 298 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 299 } 300 } 301 302 private void handleCustomCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) { 303 if(customEditor == customCheckBox) { 304 value = Utils.interpretCheckboxState(evt) ? TEXT_TRUE : TEXT_FALSE; 305 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 306 } 307 } 308 309 private void handleCustomComboBoxActionPerformed(java.awt.event.ActionEvent evt) { 310 if(customEditor == customComboBox) { 311 if("comboBoxChanged".equals(evt.getActionCommand())) { Object selectedItem = customComboBox.getSelectedItem(); 313 314 if(selectedItem instanceof String ) { 315 value = (String ) selectedItem; 316 } else if(selectedItem instanceof CharsetMapping) { 317 value = ((CharsetMapping) selectedItem).getCharset().toString(); 318 } else if(selectedItem instanceof LocaleMapping) { 319 value = ((LocaleMapping) selectedItem).getLocale().toString(); 320 } 321 322 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 323 } 324 } 325 } 326 327 private void handleDescriptionFieldKeyReleased(java.awt.event.KeyEvent evt) { 328 if(hasDescription) { 329 description = descriptionField.getText(); 330 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 331 } 332 } 333 334 private void handlePropertiesComboActionPerformed(java.awt.event.ActionEvent evt) { 335 if("comboBoxChanged".equals(evt.getActionCommand())) { Object selectedItem = propertyListModel.getSelectedItem(); 337 if(selectedItem instanceof ParamMapping) { 339 nameMapping = (ParamMapping) selectedItem; 341 selectProperty(nameMapping); 342 } else if(selectedItem instanceof String ) { nameMapping = null; 345 name = (String ) selectedItem; 346 347 if(propertyListModel.getIndexOf(selectedItem) == -1) { 349 propertyListModel.addElement(selectedItem); 350 } 351 352 enableTextFields(true); 353 displayCustomEditor(customTextField); 354 } 355 356 firePropertyChange(Constants.USER_DATA_CHANGED, null, null); 357 } 358 } 359 360 private void selectProperty(ParamMapping pm) { 361 PropertyParam param = pm.getParam(); 362 if(param != null) { 363 ParamType paramType = param.getParamType(); 364 String type = paramType.getType(); 365 enableTextFields(true); 366 367 valueRequiredMark.setText(paramType.getRequired().equals(TEXT_TRUE) ? 368 localBundle.getString("LBL_RequiredMark") : ""); String paramLabel = param.getParamLabel(); 370 if(paramLabel != null) { 371 valueLabel.setText(propertyListBundle.getString(paramLabel) + " :"); } else { 373 valueLabel.setText(localBundle.getString("LBL_Value_1")); } 375 376 value = param.getDefaultValue(); 377 378 if(type.equals("boolean")) { customCheckBox.setSelected(value.equals(TEXT_TRUE)); 380 displayCustomEditor(customCheckBox); 381 } else if(type.equals("text")) { customTextField.setText(value); 383 customTextField.setCaretPosition(0); 384 displayCustomEditor(customTextField); 385 } else if(type.equals("number")) { customTextField.setText(value); 387 customTextField.setCaretPosition(0); 388 displayCustomEditor(customTextField); 389 } else if(type.equals("list")) { DefaultComboBoxModel valueListModel = new DefaultComboBoxModel (); 392 Object defaultValue = value; 393 394 if(paramType.isParamCharset()) { 395 SortedMap charsets = CharsetMapping.getSortedAvailableCharsetMappings(); 396 for(Iterator iter = charsets.entrySet().iterator(); iter.hasNext(); ) { 397 CharsetMapping cm = (CharsetMapping) ((Map.Entry ) iter.next()).getValue(); 398 valueListModel.addElement(cm); 399 } 400 401 if(value != null) { 402 defaultValue = CharsetMapping.getCharsetMapping(value); 403 } else { 404 defaultValue = CharsetMapping.getCharsetMapping("UTF8"); 405 } 406 } else if(paramType.isParamLocale()) { 407 SortedMap locales = LocaleMapping.getSortedAvailableLocaleMappings(); 408 for(Iterator iter = locales.entrySet().iterator(); iter.hasNext(); ) { 409 LocaleMapping lm = (LocaleMapping) ((Map.Entry ) iter.next()).getValue(); 410 valueListModel.addElement(lm); 411 } 412 413 if(value != null) { 414 defaultValue = LocaleMapping.getLocaleMapping(value); 415 } else { 416 defaultValue = LocaleMapping.getLocaleMapping(Locale.getDefault()); 417 } 418 } else { 419 for(int i = 0, n = paramType.sizeParamValue(); i < n; i++) { 420 valueListModel.addElement(paramType.getParamValue(i)); 421 } 422 423 if(defaultValue == null) { 425 defaultValue = valueListModel.getElementAt(0); 426 } 427 } 428 429 customComboBox.setModel(valueListModel); 430 customComboBox.setEditable(paramType.getEditable().equals(TEXT_TRUE)); 431 customComboBox.setSelectedItem(defaultValue); 432 433 displayCustomEditor(customComboBox); 434 } 435 436 if(hasDescription) { 438 String defaultDesc = param.getParamDescription(); 439 if(defaultDesc != null) { 440 description = propertyListBundle.getString(defaultDesc); 441 descriptionField.setText(description); 442 descriptionField.setCaretPosition(0); 443 } 444 } 445 } else { 446 enableTextFields(false); 449 displayCustomEditor(customTextField); 450 } 451 } 452 453 private void buildMappings() { 454 List properties = theList.fetchPropertyParamList(); 455 paramMappings = new ArrayList (properties.size()+1); 456 457 if(!isEditable) { 459 paramMappings.add(new ParamMapping(null)); } 461 462 for(Iterator iter = properties.iterator(); iter.hasNext(); ) { 463 PropertyParam pp = (PropertyParam) iter.next(); 464 paramMappings.add(new ParamMapping(pp)); 465 } 466 } 467 468 private void displayCustomEditor(JComponent newCustomEditor) { 469 if(customEditor != newCustomEditor) { 470 int extraHeight = normalizedHeight - newCustomEditor.getPreferredSize().height; 471 int extraBelow = extraHeight/2; 472 int extraAbove = extraHeight-extraBelow; 473 int valueBelow = (hasDescription ? 0 : 11); 474 475 GridBagConstraints constraints = new GridBagConstraints (); 476 constraints.gridwidth = GridBagConstraints.REMAINDER; 477 constraints.fill = GridBagConstraints.HORIZONTAL; 478 constraints.insets = new Insets (extraAbove+6, 6, extraBelow + valueBelow, 11); 479 constraints.weightx = 1.0; 480 481 valueRequiredMark.setLabelFor(newCustomEditor); 483 valueLabel.setLabelFor(newCustomEditor); 484 485 int customEditorIndex = componentIndexOf(customEditor); 487 remove(customEditor); 488 add(newCustomEditor, constraints, customEditorIndex); 489 490 Window parentWindow = getParentWindow(); 493 if(parentWindow != null) { 494 parentWindow.pack(); 495 } 496 497 Rectangle bounds = newCustomEditor.getBounds(null); 506 bounds.y -= extraAbove; 507 bounds.height += extraHeight; 508 repaint(bounds); 509 510 customEditor = newCustomEditor; 511 } 512 } 513 514 private int componentIndexOf(JComponent control) { 515 int result = -1; 516 517 Component [] children = getComponents(); 518 for(int i = 0; i < children.length; i++) { 519 if(control == children[i]) { 520 result = i; 521 break; 522 } 523 } 524 525 return result; 526 } 527 528 private void enableTextFields(boolean flag) { 529 value = null; 530 customTextField.setText(value); 531 customTextField.setEditable(flag); 532 customTextField.setEnabled(flag); 533 534 if(hasDescription) { 535 description = null; 536 descriptionField.setText(description); 537 descriptionField.setEditable(flag); 538 descriptionField.setEnabled(flag); 539 } 540 } 541 542 private Window getParentWindow() { 543 for(Container parent = getParent(); parent != null; parent = parent.getParent()) { 544 if(parent instanceof Window ) { 545 return (Window ) parent; 546 } 547 } 548 549 return null; 550 } 551 552 555 private static final int NAME_FIELD = 0; 557 private static final int VALUE_FIELD = 1; 558 private static final int DESCRIPTION_FIELD = 2; 559 private static final int NUM_FIELDS_NO_DESCRIPTION = 2; private static final int NUM_FIELDS_WITH_DESCRIPTION = 3; 562 public void init(ASDDVersion asVersion, int preferredWidth, List entries, Object data) { 563 theList = (PropertyList) data; 564 hasDescription = theList.getDescription().equals(TEXT_TRUE); 565 isEditable = theList.getEditable().equals(TEXT_TRUE); 566 567 String bundlePath = theList.getBundlePath(); 568 if(bundlePath != null) { 569 propertyListBundle = ResourceBundle.getBundle(bundlePath); 570 } 571 572 initComponents(); 573 initUserComponents(); 574 575 setPreferredSize(new Dimension (preferredWidth, getPreferredSize().height)); 576 577 if(!isEditable) { 578 selectProperty((ParamMapping) paramMappings.get(0)); 581 } 582 } 583 584 public Object [] getValues() { 585 Object [] result; 586 587 if(hasDescription) { 588 result = new Object [NUM_FIELDS_WITH_DESCRIPTION]; 589 } else { 590 result = new Object [NUM_FIELDS_NO_DESCRIPTION]; 591 } 592 593 if(nameMapping != null) { 594 PropertyParam param = nameMapping.getParam(); 595 if(param != null) { 596 result[NAME_FIELD] = param.getParamName(); 597 } else { 598 result[NAME_FIELD] = ""; } 600 } else { 601 result[NAME_FIELD] = name; 602 } 603 604 result[VALUE_FIELD] = value; 605 606 if(hasDescription) { 607 result[DESCRIPTION_FIELD] = description; 608 } 609 610 return result; 611 } 612 613 public void setValues(Object [] values) { 614 if(values == null) { 617 values = new Object [hasDescription ? NUM_FIELDS_WITH_DESCRIPTION : NUM_FIELDS_NO_DESCRIPTION]; 618 values[NAME_FIELD] = null; 619 values[VALUE_FIELD] = null; 620 621 if(hasDescription) { 622 values[DESCRIPTION_FIELD] = null; 623 } 624 625 isEditPopup = false; 626 } else { 627 isEditPopup = true; 628 } 629 630 name = (String ) values[NAME_FIELD]; 638 nameMapping = null; 639 640 if(name != null && name.length() > 0) { 645 for(Iterator iter = paramMappings.iterator(); iter.hasNext(); ) { 646 ParamMapping pm = (ParamMapping) iter.next(); 647 PropertyParam param = pm.getParam(); 648 if(param != null && name.equals(param.getParamName())) { 649 nameMapping = pm; 650 break; 651 } 652 } 653 } else if(paramMappings.size() > 0) { 654 ParamMapping pm = (ParamMapping) paramMappings.get(0); 655 if(pm.getParam() == null) { 656 nameMapping = pm; 657 } 658 } 659 660 if(nameMapping != null) { 661 propertiesCombo.setSelectedItem(nameMapping); 662 } else { 663 propertiesCombo.setSelectedItem(name); 667 } 668 669 if(isEditPopup) { 677 propertiesCombo.setEnabled(false); 680 681 value = (String ) values[VALUE_FIELD]; 682 683 if(customEditor == customCheckBox) { 684 customCheckBox.setSelected(Utils.booleanValueOf(value)); 685 } else if(customEditor == customTextField) { 686 customTextField.setText(value); 687 customTextField.setCaretPosition(0); 688 } else if(customEditor == customComboBox) { 689 customComboBox.setSelectedItem(value); 691 } 692 693 if(hasDescription) { 694 description = (String ) values[DESCRIPTION_FIELD]; 695 descriptionField.setText(description); 696 descriptionField.setCaretPosition(0); 697 } 698 } 699 } 700 701 public boolean requiredFieldsFilled() { 702 return true; 703 } 704 705 public Collection getErrors(ValidationSupport validationSupport) { 706 ArrayList errorList = new ArrayList (); 707 708 if(hasEmptyName()) { 709 errorList.add(localBundle.getString("ERR_NameFieldIsEmpty")); } else if(nameMapping != null) { 711 if(value == null || value.length() == 0) { 713 Object [] args = new Object [1]; 715 args[0] = localBundle.getString("LBL_Value"); 716 errorList.add(MessageFormat.format(localBundle.getString("ERR_SpecifiedFieldIsEmpty"), args)); 717 } else { 718 PropertyParam param = nameMapping.getParam(); ParamType paramType = param.getParamType(); 720 String type = paramType.getType(); 721 String name = param.getParamName(); 722 723 if(type.equals("text")) { validate(value, param.getParamValidator(), name, errorList); 725 } else if(type.equals("number")) { validateNumber(value, paramType.getParamMin(), paramType.getParamMax(), errorList); 727 } else if(type.equals("list")) { validate(value, param.getParamValidator(), name, errorList); 729 } 730 } 731 } 732 733 return errorList; 734 } 735 736 740 private boolean hasEmptyName() { 741 boolean result = true; 742 743 if(nameMapping != null && nameMapping.getParam() != null) { 744 result = false; } else if(nameMapping == null && name != null && name.length() > 0) { 746 result = false; } 748 749 return result; 750 } 751 752 760 private void validateNumber(String theNumber, String paramMin, String paramMax, List errorList) { 761 try { 762 long x = Long.parseLong(theNumber); 763 long min = Long.MIN_VALUE; 764 long max = Long.MAX_VALUE; 765 766 if(paramMin != null) { 767 min = Long.parseLong(paramMin); 768 if(x < min) { 769 Object [] args = new Object [] { theNumber, Long.toString(min) }; 770 errorList.add(MessageFormat.format( 771 localBundle.getString("ERR_NumberTooLow"), args)); } 773 } 774 775 if(paramMax != null) { 776 max = Long.parseLong(paramMax); 777 if(x > max) { 778 Object [] args = new Object [] { theNumber, Long.toString(max) }; 779 errorList.add(MessageFormat.format( 780 localBundle.getString("ERR_NumberTooHigh"), args)); } 782 } 783 } catch(NumberFormatException ex) { 784 Object [] args = new Object [] { theNumber }; 785 errorList.add(MessageFormat.format( 786 localBundle.getString("ERR_NumberInvalid"), args)); } 788 } 789 790 799 private void validate(String value, String validatorName, String propertyName, List errorList) { 800 if(validatorName != null) { 801 Pattern validatorPattern = PropertyListMapping.getValidator(validatorName); 802 if(validatorPattern != null) { 803 if(!validatorPattern.matcher(value).matches()) { 804 Object [] args = new Object [] { propertyName, validatorName }; 805 String propInvalidMsg = localBundle.getString("ERR_PropertyValueInvalid"); errorList.add(MessageFormat.format(propInvalidMsg, args)); 807 } 808 } 809 } 810 } 811 812 } 813 | Popular Tags |