Author: chris.laprun(a)jboss.com
Date: 2012-03-14 12:19:24 -0400 (Wed, 14 Mar 2012)
New Revision: 8598
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java
Log:
- GTNPORTAL-2377:
+ Only output one message of each type in CompoundApplicationMessage
+ Fixed UsernameValidator and improved IdentifierValidator and ResourceValidator to fail
fast when we have an error condition in a loop
+ Fixed improper/missing localization in EN and FR properties, would need to be done for
other languages as well
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java 2012-03-14
16:19:17 UTC (rev 8597)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java 2012-03-14
16:19:24 UTC (rev 8598)
@@ -46,11 +46,11 @@
for (int i = 0; i < value.length(); i++)
{
char c = value.charAt(i);
- if (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c ==
'-')
+ if (!Character.isLetter(c) && !Character.isDigit(c) && c !=
'_' && c != '-')
{
- continue;
+ messages.addMessage("IdentifierValidator.msg.Invalid-char", new
Object[]{label});
+ break;
}
- messages.addMessage("IdentifierValidator.msg.Invalid-char", new
Object[]{label});
}
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java 2012-03-14
16:19:17 UTC (rev 8597)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java 2012-03-14
16:19:24 UTC (rev 8598)
@@ -38,7 +38,7 @@
protected void validate(String value, String label, CompoundApplicationMessage
messages, UIFormInput uiInput)
{
char firstChar = value.charAt(0);
- if (Character.isDigit(firstChar) || firstChar == '-' || firstChar ==
'.' || firstChar == '_')
+ if (!Character.isLetter(firstChar))
{
Object[] args = {label, uiInput.getBindingField()};
messages.addMessage("FirstCharacterNameValidator.msg", args);
@@ -46,12 +46,12 @@
for (int i = 0; i < value.length(); i++)
{
char c = value.charAt(i);
- if (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c ==
'-' || c == '.')
+ if (!Character.isLetter(c) && !Character.isDigit(c) && c !=
'_' && c != '-' && c != '.')
{
- continue;
+ Object[] args = {label};
+ messages.addMessage("ResourceValidator.msg.Invalid-char", args);
+ break;
}
- Object[] args = {label};
- messages.addMessage("ResourceValidator.msg.Invalid-char", args);
}
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java 2012-03-14
16:19:17 UTC (rev 8597)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java 2012-03-14
16:19:24 UTC (rev 8598)
@@ -35,6 +35,7 @@
protected static final int DEFAULT_MAX_LENGTH = 30;
protected Integer min = DEFAULT_MIN_LENGTH;
protected Integer max = DEFAULT_MAX_LENGTH;
+ public static final String ALLOWED_SYMBOLS = "'_', '.'";
// required by @Serialized
public UsernameValidator()
@@ -62,19 +63,22 @@
if (!Character.isLowerCase(buff[0]))
{
- messages.addMessage("FirstCharacterNameValidator.msg", new
Object[]{label});
+ messages.addMessage("FirstCharacterUsernameValidator.msg", new
Object[]{label});
}
- if (!Character.isLetterOrDigit(buff[buff.length - 1]))
+ char c = buff[buff.length - 1];
+ if (!isLowerCaseLetterOrDigit(c))
{
- messages.addMessage("LastCharacterUsernameValidator.msg", new
Object[]{label, buff[buff.length - 1]});
+ messages.addMessage("LastCharacterUsernameValidator.msg", new
Object[]{label, c});
}
+ boolean hasConsecutive = false;
+ boolean hasInvalid = false;
for (int i = 1; i < buff.length - 1; i++)
{
- char c = buff[i];
+ c = buff[i];
- if (Character.isLetterOrDigit(c))
+ if (isLowerCaseLetterOrDigit(c))
{
continue;
}
@@ -84,20 +88,43 @@
char next = buff[i + 1];
if (isSymbol(next))
{
- messages.addMessage("ConsecutiveSymbolValidator.msg", new
Object[]{label, buff[i], buff[i + 1]});
+ if (!hasConsecutive)
+ {
+ messages.addMessage("ConsecutiveSymbolValidator.msg", new
Object[]{label, ALLOWED_SYMBOLS});
+ hasConsecutive = true;
+ }
}
else if (!Character.isLetterOrDigit(next))
{
- messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label});
+ if (!hasInvalid)
+ {
+ messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label});
+ hasInvalid = true;
+ }
}
}
else
{
- messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label});
+ if (!hasInvalid)
+ {
+ messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label});
+ hasInvalid = true;
+ }
}
+
+ // if we have both error conditions, fail "fast" instead of going on
+ if (hasConsecutive && hasInvalid)
+ {
+ break;
+ }
}
}
+ private static boolean isLowerCaseLetterOrDigit(char character)
+ {
+ return Character.isDigit(character) || (character >= 'a' &&
character <= 'z');
+ }
+
private static boolean isSymbol(char c)
{
return c == '_' || c == '.';
Show replies by date