Example #1
0
 public void validate(UIFormInput uiInput) throws Exception {
   if (uiInput.getValue() == null || ((String) uiInput.getValue()).trim().length() == 0) return;
   UIComponent uiComponent = (UIComponent) uiInput;
   UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
   String label;
   try {
     label = uiForm.getLabel(uiInput.getName());
   } catch (Exception e) {
     label = uiInput.getName();
   }
   label = label.trim();
   if (label.charAt(label.length() - 1) == ':') label = label.substring(0, label.length() - 1);
   String s = (String) uiInput.getValue();
   if (s == null || s.trim().length() == 0) {
     Object[] args = {uiInput.getLabel()};
     throw new MessageException(
         new ApplicationMessage(
             "ECMNameValidator.msg.empty-input", args, ApplicationMessage.WARNING));
   }
   for (int i = 0; i < s.length(); i++) {
     char c = s.charAt(i);
     if (Character.isLetter(c)
         || Character.isDigit(c)
         || Character.isSpaceChar(c)
         || c == '_'
         || c == '-'
         || c == '.'
         || c == ':'
         || c == '@'
         || c == '^'
         || c == '['
         || c == ']'
         || c == ',') {
       continue;
     }
     Object[] args = {label};
     throw new MessageException(
         new ApplicationMessage(
             "ECMNameValidator.msg.Invalid-char", args, ApplicationMessage.WARNING));
   }
 }