Author: chris.laprun(a)jboss.com
Date: 2012-01-31 07:35:53 -0500 (Tue, 31 Jan 2012)
New Revision: 8328
Modified:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java
portal/trunk/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java
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/MultipleConditionsValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.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
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java
Log:
- GTNPORTAL-1673: Fixed runtime issues that were not caught by test suite. Made
AbstractValidator.trimmedValueOrNullIfBypassed method more configurable.
Modified:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -45,7 +45,6 @@
private boolean argsLocalized = true;
-
public abstract String getMessage();
public void setResourceBundle(ResourceBundle resourceBundle)
@@ -53,6 +52,11 @@
this.resourceBundle = resourceBundle;
}
+ protected ResourceBundle getResourceBundle()
+ {
+ return resourceBundle;
+ }
+
public int getType()
{
return type_;
Modified:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -43,6 +43,11 @@
setType(type);
}
+ public String getMessageKey()
+ {
+ return messageKey_;
+ }
+
public String getMessage()
{
String msg = resolveMessage(messageKey_);
Modified:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -25,6 +25,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import java.util.ResourceBundle;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class CompoundApplicationMessage extends AbstractApplicationMessage implements
Serializable
@@ -42,9 +43,20 @@
{
messages.add(initialMessage);
}
+ setType(AbstractApplicationMessage.WARNING);
}
@Override
+ public void setResourceBundle(ResourceBundle resourceBundle)
+ {
+ super.setResourceBundle(resourceBundle);
+ for (AbstractApplicationMessage message : messages)
+ {
+ message.setResourceBundle(resourceBundle);
+ }
+ }
+
+ @Override
public String getMessage()
{
StringBuilder sb = new StringBuilder(255);
@@ -56,9 +68,9 @@
return sb.toString();
}
- public void addMessage(String messageKey, Object[] args, int type)
+ public void addMessage(String messageKey, Object[] args)
{
- messages.add(new ApplicationMessage(messageKey, args, type));
+ messages.add(new ApplicationMessage(messageKey, args,
AbstractApplicationMessage.WARNING));
}
public boolean isEmpty()
Modified: portal/trunk/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl
===================================================================
---
portal/trunk/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl 2012-01-31
12:35:53 UTC (rev 8328)
@@ -51,7 +51,7 @@
}
println " <ul class=\"UITabContent PopupMessageBox $messType\"
$style>";
for(mess in messages) {
- if(mess.messageKey == null) continue;
+ // if(mess.messageKey == null) continue;
println " <li class=\"MessageContainer\">";
println " <span class=\"PopupIcon
${messType}Icon\">";
String msgValue = mess.getMessage();
@@ -61,7 +61,7 @@
println " </li>";
}
println " </ul>";
- return isSelected;
+ return isSelected;
}
%>
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -34,6 +34,9 @@
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public abstract class AbstractValidator implements Validator, Serializable
{
+ protected boolean exceptionOnMissingMandatory = false;
+ protected boolean trimValue = false;
+
protected String getLabelFor(UIFormInput uiInput) throws Exception
{
UIComponent uiComponent = (UIComponent)uiInput;
@@ -44,12 +47,20 @@
label = uiForm.getLabel(label);
}
+ label = label.trim();
+
+ // remove trailing ':' if there is one
+ int index = label.indexOf(':');
+ if(index != -1)
+ {
+ label = label.substring(0, index);
+ }
return label.trim();
}
public void validate(UIFormInput uiInput) throws Exception
{
- String value = trimmedValueOrNullIfBypassed((String)uiInput.getValue(), uiInput);
+ String value = trimmedValueOrNullIfBypassed((String)uiInput.getValue(), uiInput,
exceptionOnMissingMandatory, trimValue);
if (value == null)
{
return;
@@ -75,17 +86,24 @@
protected abstract boolean isValid(String value, UIFormInput uiInput);
- protected String trimmedValueOrNullIfBypassed(String value, UIFormInput uiInput)
+ protected String trimmedValueOrNullIfBypassed(String value, UIFormInput uiInput,
boolean exceptionOnMissingMandatory, boolean trimValue) throws Exception
{
- if (value == null)
+ if (value != null)
{
- return null;
+ String tmp = value.trim();
+ if(trimValue)
+ {
+ value = tmp;
+ }
+
+ value = tmp.isEmpty() ? null : value;
}
- else
+
+ if(exceptionOnMissingMandatory && value == null)
{
-// value = value.trim(); // should values be trimmed before being validated and
saved?
+ throw createMessageException("EmptyFieldValidator.msg.empty-input",
uiInput);
+ }
- return value.trim().isEmpty() ? null : value;
- }
+ return value;
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -62,7 +62,7 @@
}
@Override
- protected String trimmedValueOrNullIfBypassed(String value, UIFormInput uiInput)
+ protected String trimmedValueOrNullIfBypassed(String value, UIFormInput uiInput,
boolean exceptionOnMissingMandatory, boolean trimValue) throws Exception
{
if(!(uiInput instanceof UIFormDateTimeInput))
{
@@ -70,7 +70,7 @@
}
else
{
- return super.trimmedValueOrNullIfBypassed(value, uiInput);
+ return super.trimmedValueOrNullIfBypassed(value, uiInput,
exceptionOnMissingMandatory, trimValue);
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -20,7 +20,6 @@
package org.exoplatform.webui.form.validator;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
@@ -53,16 +52,19 @@
int atIndex = value.indexOf('@');
if (atIndex == -1)
{
- messages.addMessage("EmailAddressValidator.msg.Invalid-input", args,
ApplicationMessage.WARNING);
+ messages.addMessage("EmailAddressValidator.msg.Invalid-input", args);
}
+ else
+ {
+ String localPart = value.substring(0, atIndex);
+ String domainName = value.substring(atIndex + 1);
- String localPart = value.substring(0, atIndex);
- String domainName = value.substring(atIndex + 1);
+ if (!validateLocalPart(localPart.toCharArray()) ||
!validateDomainName(domainName.toCharArray()))
+ {
+ messages.addMessage("EmailAddressValidator.msg.Invalid-input",
args);
+ }
+ }
- if (!validateLocalPart(localPart.toCharArray()) ||
!validateDomainName(domainName.toCharArray()))
- {
- messages.addMessage("EmailAddressValidator.msg.Invalid-input", args,
ApplicationMessage.WARNING);
- }
}
private boolean validateLocalPart(char[] localPart)
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-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -19,7 +19,6 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
@@ -42,7 +41,7 @@
{
if (Character.isDigit(value.charAt(0)) || value.charAt(0) == '-')
{
- messages.addMessage("FirstAndSpecialCharacterNameValidator.msg", new
Object[]{label, uiInput.getBindingField()}, ApplicationMessage.WARNING);
+ messages.addMessage("FirstAndSpecialCharacterNameValidator.msg", new
Object[]{label, uiInput.getBindingField()});
}
for (int i = 0; i < value.length(); i++)
{
@@ -51,7 +50,7 @@
{
continue;
}
- messages.addMessage("IdentifierValidator.msg.Invalid-char", new
Object[]{label}, ApplicationMessage.WARNING);
+ messages.addMessage("IdentifierValidator.msg.Invalid-char", new
Object[]{label});
}
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/MultipleConditionsValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/MultipleConditionsValidator.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/MultipleConditionsValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -34,7 +34,7 @@
{
public void validate(UIFormInput uiInput) throws Exception
{
- String value = trimmedValueOrNullIfBypassed((String)uiInput.getValue(), uiInput);
+ String value = trimmedValueOrNullIfBypassed((String)uiInput.getValue(), uiInput,
exceptionOnMissingMandatory, trimValue);
if (value == null)
{
return;
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -19,7 +19,6 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
@@ -46,11 +45,11 @@
Object[] args = {label};
if (value.charAt(0) == '0' && value.length() > 1)
{
- messages.addMessage("NumberFormatValidator.msg.Invalid-number", args,
ApplicationMessage.WARNING);
+ messages.addMessage("NumberFormatValidator.msg.Invalid-number",
args);
}
else if (value.charAt(0) == '-' && value.length() > 1 &&
value.charAt(1) == '0')
{
- messages.addMessage("NumberFormatValidator.msg.Invalid-number", args,
ApplicationMessage.WARNING);
+ messages.addMessage("NumberFormatValidator.msg.Invalid-number",
args);
}
try
{
@@ -58,7 +57,7 @@
}
catch (NumberFormatException e)
{
- messages.addMessage("NumberFormatValidator.msg.Invalid-number", args,
ApplicationMessage.WARNING);
+ messages.addMessage("NumberFormatValidator.msg.Invalid-number",
args);
return null;
}
}
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -19,7 +19,6 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.web.application.CompoundApplicationMessage;
import java.io.Serializable;
@@ -47,7 +46,7 @@
}
else if(integer < 0)
{
-
messages.addMessage("PositiveNumberFormatValidator.msg.Invalid-number", new
Object[]{label}, ApplicationMessage.WARNING);
+
messages.addMessage("PositiveNumberFormatValidator.msg.Invalid-number", new
Object[]{label});
return null;
}
else
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-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -20,7 +20,6 @@
package org.exoplatform.webui.form.validator;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
@@ -42,7 +41,7 @@
if (Character.isDigit(firstChar) || firstChar == '-' || firstChar ==
'.' || firstChar == '_')
{
Object[] args = {label, uiInput.getBindingField()};
- messages.addMessage("FirstCharacterNameValidator.msg", args,
ApplicationMessage.WARNING);
+ messages.addMessage("FirstCharacterNameValidator.msg", args);
}
for (int i = 0; i < value.length(); i++)
{
@@ -52,7 +51,7 @@
continue;
}
Object[] args = {label};
- messages.addMessage("ResourceValidator.msg.Invalid-char", args,
ApplicationMessage.WARNING);
+ 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-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -17,7 +17,6 @@
package org.exoplatform.webui.form.validator;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
@@ -51,17 +50,17 @@
char[] buff = value.toCharArray();
if (buff.length < min || buff.length > max)
{
- messages.addMessage("StringLengthValidator.msg.length-invalid", new
Object[]{label, min.toString(), max.toString()}, ApplicationMessage.WARNING);
+ messages.addMessage("StringLengthValidator.msg.length-invalid", new
Object[]{label, min.toString(), max.toString()});
}
if (!Character.isLowerCase(buff[0]))
{
- messages.addMessage("FirstCharacterNameValidator.msg", new
Object[]{label}, ApplicationMessage.WARNING);
+ messages.addMessage("FirstCharacterNameValidator.msg", new
Object[]{label});
}
if (!Character.isLetterOrDigit(buff[buff.length - 1]))
{
- messages.addMessage("LastCharacterUsernameValidator.msg", new
Object[]{label, buff[buff.length - 1]}, ApplicationMessage.WARNING);
+ messages.addMessage("LastCharacterUsernameValidator.msg", new
Object[]{label, buff[buff.length - 1]});
}
for (int i = 1; i < buff.length - 1; i++)
@@ -78,16 +77,16 @@
char next = buff[i + 1];
if (isSymbol(next))
{
- messages.addMessage("ConsecutiveSymbolValidator.msg", new
Object[]{label, buff[i], buff[i + 1]}, ApplicationMessage.WARNING);
+ messages.addMessage("ConsecutiveSymbolValidator.msg", new
Object[]{label, buff[i], buff[i + 1]});
}
else if (!Character.isLetterOrDigit(next))
{
- messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label}, ApplicationMessage.WARNING);
+ messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label});
}
}
else
{
- messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label}, ApplicationMessage.WARNING);
+ messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label});
}
}
}
Modified:
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java
===================================================================
---
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java 2012-01-31
12:27:56 UTC (rev 8327)
+++
portal/trunk/webui/core/src/test/java/org/exoplatform/webui/test/validator/TestWebuiValidator.java 2012-01-31
12:35:53 UTC (rev 8328)
@@ -16,11 +16,7 @@
*/
package org.exoplatform.webui.test.validator;
-import java.util.List;
-import java.util.Locale;
-
import junit.framework.TestCase;
-
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.core.UIComponent;
import org.exoplatform.webui.exception.MessageException;
@@ -38,6 +34,9 @@
import org.exoplatform.webui.form.validator.UsernameValidator;
import org.exoplatform.webui.form.validator.Validator;
+import java.util.List;
+import java.util.Locale;
+
/**
* @author <a href="mailto:haint@exoplatform.com">Nguyen Thanh
Hai</a>
*
@@ -109,6 +108,7 @@
public void testEmailValidator()
{
Validator validator = new EmailAddressValidator();
+ assertFalse(expected(validator, "root"));
assertTrue(expected(validator, "root.gtn(a)exoplatform.com"));
assertTrue(expected(validator,
"root.exo.gtn.portal(a)explatform.biz.edu.vn"));
assertTrue(expected(validator,
"root_exo_gtn_portal(a)explatform-edu.biz.vn"));