Author: chris.laprun(a)jboss.com
Date: 2012-02-09 14:14:27 -0500 (Thu, 09 Feb 2012)
New Revision: 8417
Added:
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MultipleConditionsValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NaturalLanguageValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java
Modified:
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupMembershipForm.java
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PasswordStringLengthValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/StringLengthValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/URLValidator.java
epp/portal/branches/EPP_5_2_Branch/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIAccountInputSet.java
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIApplication.java
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIPopupMessages.java
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/exception/MessageException.java
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
Log:
- JBEPP-650: Applied changes from GTNPORTAL-1673
Added:
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/AbstractApplicationMessage.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -0,0 +1,102 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.web.application;
+
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.Serializable;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Dang Van Minh
+ * minhdv81(a)yahoo.com
+ * Jun 7, 2006
+ */
+public abstract class AbstractApplicationMessage implements Serializable
+{
+ private static Log log = ExoLogger.getLogger(ApplicationMessage.class);
+
+ final public static int ERROR = 0, WARNING = 1, INFO = 2;
+
+ private int type_ = INFO;
+
+ private transient ResourceBundle resourceBundle;
+
+ private boolean argsLocalized = true;
+
+ public abstract String getMessage();
+
+ public void setResourceBundle(ResourceBundle resourceBundle)
+ {
+ this.resourceBundle = resourceBundle;
+ }
+
+ protected ResourceBundle getResourceBundle()
+ {
+ return resourceBundle;
+ }
+
+ public int getType()
+ {
+ return type_;
+ }
+
+ public void setType(int type)
+ {
+ this.type_ = type;
+ }
+
+ public void setArgsLocalized(boolean argsLocalized)
+ {
+ this.argsLocalized = argsLocalized;
+ }
+
+ public boolean isArgsLocalized()
+ {
+ return argsLocalized;
+ }
+
+ protected String resolveMessage(String key)
+ {
+ if (key == null && resourceBundle == null)
+ {
+ return key;
+ }
+
+ String value;
+ try
+ {
+ value = resourceBundle.getString(key);
+ }
+ catch (MissingResourceException ex)
+ {
+ if (PropertyManager.isDevelopping())
+ {
+ log.warn("Can not find resource bundle for key : " + key);
+ }
+ value = key.substring(key.lastIndexOf('.') + 1);
+ }
+ return value;
+ }
+}
Modified:
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,140 +1,69 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
package org.exoplatform.web.application;
-import org.exoplatform.commons.utils.PropertyManager;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
import java.io.Serializable;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-/**
- * Created by The eXo Platform SARL
- * Author : Dang Van Minh
- * minhdv81(a)yahoo.com
- * Jun 7, 2006
- */
-public class ApplicationMessage implements Serializable
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public class ApplicationMessage extends AbstractApplicationMessage implements
Serializable
{
- private static Log log = ExoLogger.getLogger(ApplicationMessage.class);
-
- final public static int ERROR = 0, WARNING = 1, INFO = 2;
+ private final String messageKey_;
+ private final Object[] messageArgs_;
- private int type_ = INFO;
-
- private String messageKey_;
-
- private ResourceBundle resourceBundle;
-
- private Object[] messageArgs_;
-
- private boolean argsLocalized = true;
-
public ApplicationMessage(String key, Object[] args)
{
- messageKey_ = key;
- messageArgs_ = args;
+ this.messageKey_ = key;
+ this.messageArgs_ = args;
}
public ApplicationMessage(String key, Object[] args, int type)
{
- this(key, args);
- type_ = type;
+ this.messageKey_ = key;
+ this.messageArgs_ = args;
+ setType(type);
}
+ public String getMessageKey()
+ {
+ return messageKey_;
+ }
+
public String getMessage()
{
String msg = resolveMessage(messageKey_);
if (msg != null && messageArgs_ != null)
{
- for(int i = 0; i < messageArgs_.length; i++)
+ for (int i = 0; i < messageArgs_.length; i++)
{
- String arg = messageArgs_ [i].toString();
- if (isArgsLocalized())
+ String arg = messageArgs_[i].toString();
+ if (isArgsLocalized())
{
arg = resolveMessage(arg);
}
- msg = msg.replace("{" + i + "}", arg);
- }
- }
-
- return msg;
- }
-
- public void setResourceBundle(ResourceBundle resourceBundle)
- {
- this.resourceBundle = resourceBundle;
- }
-
- public String getMessageKey()
- {
- return messageKey_;
- }
-
- public Object[] getMessageAruments()
- {
- return messageArgs_;
- }
-
- public int getType()
- {
- return type_;
- }
-
- public void setType(int type)
- {
- this.type_ = type;
- }
-
- public void setArgsLocalized(boolean argsLocalized)
- {
- this.argsLocalized = argsLocalized;
- }
-
- public boolean isArgsLocalized()
- {
- return argsLocalized;
- }
-
- private String resolveMessage(String key)
- {
- if (key == null && resourceBundle == null)
- {
- return key;
- }
-
- String value;
- try
- {
- value = resourceBundle.getString(key);
- }
- catch (MissingResourceException ex)
- {
- if (PropertyManager.isDevelopping())
- {
- log.warn("Can not find resource bundle for key : " + key);
+ msg = msg.replace("{" + i + "}", arg);
}
- value = key.substring(key.lastIndexOf('.') + 1);
}
- return value;
+
+ return msg;
}
}
Added:
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/component/web/controller/src/main/java/org/exoplatform/web/application/CompoundApplicationMessage.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -0,0 +1,80 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, Red Hat Middleware, LLC, and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+*/
+
+package org.exoplatform.web.application;
+
+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
+{
+ private List<AbstractApplicationMessage> messages = new
ArrayList<AbstractApplicationMessage>(5);
+
+ public CompoundApplicationMessage()
+ {
+ this(null);
+ }
+
+ public CompoundApplicationMessage(AbstractApplicationMessage initialMessage)
+ {
+ if(initialMessage != null)
+ {
+ 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);
+ for (AbstractApplicationMessage message : messages)
+ {
+ sb.append(message.getMessage()).append('\n');
+ }
+
+ return sb.toString();
+ }
+
+ public void addMessage(String messageKey, Object[] args)
+ {
+ messages.add(new ApplicationMessage(messageKey, args,
AbstractApplicationMessage.WARNING));
+ }
+
+ public boolean isEmpty()
+ {
+ return messages.isEmpty();
+ }
+}
Modified:
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -18,8 +18,6 @@
*/
package org.exoplatform.account.webui.component;
-import javax.portlet.PortletPreferences;
-
import org.exoplatform.portal.webui.CaptchaValidator;
import org.exoplatform.services.organization.Query;
import org.exoplatform.services.organization.User;
@@ -31,12 +29,13 @@
import org.exoplatform.webui.form.UIFormInputWithActions;
import org.exoplatform.webui.form.UIFormStringInput;
import org.exoplatform.webui.form.validator.EmailAddressValidator;
-import org.exoplatform.webui.form.validator.ExpressionValidator;
import org.exoplatform.webui.form.validator.MandatoryValidator;
import org.exoplatform.webui.form.validator.PasswordStringLengthValidator;
-import org.exoplatform.webui.form.validator.ResourceValidator;
import org.exoplatform.webui.form.validator.StringLengthValidator;
+import org.exoplatform.webui.form.validator.UserConfigurableValidator;
+import javax.portlet.PortletPreferences;
+
/**
* @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
* @version $Id$
@@ -62,10 +61,9 @@
public UIRegisterInputSet(String name) throws Exception{
super(name);
-
+
addUIFormInput(new UIFormStringInput(USER_NAME, USER_NAME,
null).addValidator(MandatoryValidator.class)
- .addValidator(StringLengthValidator.class, 3,
30).addValidator(ResourceValidator.class)
- .addValidator(ExpressionValidator.class,
"^[\\p{L}][\\p{L}._\\-\\d]+$",
"ResourceValidator.msg.Invalid-char"));
+ .addValidator(UserConfigurableValidator.class,
UserConfigurableValidator.USERNAME));
addUIFormInput(new UIFormStringInput(PASSWORD, PASSWORD,
null).setType(UIFormStringInput.PASSWORD_TYPE)
.addValidator(MandatoryValidator.class).addValidator(PasswordStringLengthValidator.class,
6, 30));
Modified:
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupMembershipForm.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupMembershipForm.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/portlet/exoadmin/src/main/java/org/exoplatform/organization/webui/component/UIGroupMembershipForm.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,6 +19,7 @@
package org.exoplatform.organization.webui.component;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.services.organization.Group;
import org.exoplatform.services.organization.Membership;
import org.exoplatform.services.organization.MembershipHandler;
@@ -26,7 +27,6 @@
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.organization.User;
import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.ComponentConfigs;
import org.exoplatform.webui.config.annotation.EventConfig;
@@ -36,13 +36,12 @@
import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
import org.exoplatform.webui.core.model.SelectItemOption;
import org.exoplatform.webui.event.Event;
-import org.exoplatform.webui.event.EventListener;
import org.exoplatform.webui.event.Event.Phase;
+import org.exoplatform.webui.event.EventListener;
import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormSelectBox;
import org.exoplatform.webui.form.UIFormStringInput;
-import org.exoplatform.webui.form.validator.ExpressionValidator;
-import org.exoplatform.webui.form.validator.MandatoryValidator;
+import org.exoplatform.webui.form.validator.UserConfigurableValidator;
import org.exoplatform.webui.organization.account.UIUserSelector;
import java.util.ArrayList;
@@ -76,9 +75,7 @@
public UIGroupMembershipForm() throws Exception
{
- addUIFormInput(new UIFormStringInput(USER_NAME, USER_NAME,
null).addValidator(MandatoryValidator.class)
- .addValidator(ExpressionValidator.class,
"^\\p{L}[\\p{L}\\d._\\-\\s*,\\s*]+$",
- "UIGroupMembershipForm.msg.Invalid-char"));
+ addUIFormInput(new UIFormStringInput(USER_NAME, USER_NAME,
null).addValidator(UserConfigurableValidator.class,
UserConfigurableValidator.GROUPMEMBERSHIP,
UserConfigurableValidator.GROUP_MEMBERSHIP_LOCALIZATION_KEY));
addUIFormInput(new UIFormSelectBox("membership", "membership",
listOption).setSize(1));
UIPopupWindow searchUserPopup = addChild(UIPopupWindow.class,
"SearchUser", "SearchUser");
searchUserPopup.setWindowSize(640, 0);
Modified:
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/webui/core/UIPopupMessages.gtmpl 2012-02-09
19:14:27 UTC (rev 8417)
@@ -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;
}
%>
Added:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/AbstractValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2012, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.webui.form.validator;
+
+import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.exception.MessageException;
+import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.webui.form.UIFormInput;
+
+import java.io.Serializable;
+
+/** @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;
+ UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
+ String label = uiInput.getName();
+ if (uiForm != null)
+ {
+ 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,
exceptionOnMissingMandatory, trimValue);
+ if (value == null)
+ {
+ return;
+ }
+
+ if (!isValid(value, uiInput))
+ {
+ throw createMessageException(value, uiInput);
+ }
+ }
+
+ protected MessageException createMessageException(String value, UIFormInput uiInput)
throws Exception
+ {
+ return new MessageException(new ApplicationMessage(getMessageLocalizationKey(),
getMessageArgs(value, uiInput), ApplicationMessage.WARNING));
+ }
+
+ protected Object[] getMessageArgs(String value, UIFormInput uiInput) throws Exception
+ {
+ return new Object[]{getLabelFor(uiInput)};
+ }
+
+ protected abstract String getMessageLocalizationKey();
+
+ protected abstract boolean isValid(String value, UIFormInput uiInput);
+
+ protected String trimmedValueOrNullIfBypassed(String value, UIFormInput uiInput,
boolean exceptionOnMissingMandatory, boolean trimValue) throws Exception
+ {
+ if (value != null)
+ {
+ String tmp = value.trim();
+ if(trimValue)
+ {
+ value = tmp;
+ }
+
+ value = tmp.isEmpty() ? null : value;
+ }
+
+ if(exceptionOnMissingMandatory && value == null)
+ {
+ throw createMessageException("EmptyFieldValidator.msg.empty-input",
uiInput);
+ }
+
+ return value;
+ }
+}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/DateTimeValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -19,77 +19,64 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormDateTimeInput;
import org.exoplatform.webui.form.UIFormInput;
-import java.text.DateFormat;
+import java.io.Serializable;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
/**
* Created by The eXo Platform SARL
* Author : Tran The Trong
* trongtt(a)gmail.com
* May 15, 2007
- *
+ *
* Validates whether a date is in a correct format
*/
-public class DateTimeValidator implements Validator
+public class DateTimeValidator extends AbstractValidator implements Serializable
{
- static private final String SPLIT_REGEX = "/|\\s+|:";
+ @Override
+ protected String getMessageLocalizationKey()
+ {
+ return "DateTimeValidator.msg.Invalid-input";
+ }
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- return;
- String s = (String)uiInput.getValue();
- DateFormat stFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
UIFormDateTimeInput uiDateInput = (UIFormDateTimeInput)uiInput;
SimpleDateFormat sdf = new SimpleDateFormat(uiDateInput.getDatePattern_().trim());
-
- UIForm uiForm = ((UIComponent)uiInput).getAncestorOfType(UIForm.class);
- String label;
+ // Specify whether or not date/time parsing is to be lenient.
+ sdf.setLenient(false);
try
{
- label = uiForm.getId() + ".label." + uiInput.getName();
+ sdf.parse(value);
+ return true;
}
- catch (Exception e)
+ catch (ParseException e)
{
- label = uiInput.getName();
+ return false;
}
- Object[] args = {label, s};
+ }
- try
+ @Override
+ protected String trimmedValueOrNullIfBypassed(String value, UIFormInput uiInput,
boolean exceptionOnMissingMandatory, boolean trimValue) throws Exception
+ {
+ if(!(uiInput instanceof UIFormDateTimeInput))
{
- // Specify whether or not date/time parsing is to be lenient.
- sdf.setLenient(false);
- sdf.parse(s);
+ return null;
}
- catch (Exception e)
+ else
{
- throw new MessageException(new
ApplicationMessage("DateTimeValidator.msg.Invalid-input", args,
ApplicationMessage.WARNING));
+ return super.trimmedValueOrNullIfBypassed(value, uiInput,
exceptionOnMissingMandatory, trimValue);
}
}
- private boolean isValidDateTime(String dateTime)
+ @Override
+ protected Object[] getMessageArgs(String value, UIFormInput uiInput) throws Exception
{
- String[] arr = dateTime.split(SPLIT_REGEX, 7);
- int valid = Integer.parseInt(arr[0]);
- if (valid < 1 || valid > 12)
- return false;
- Calendar date = new GregorianCalendar(Integer.parseInt(arr[2]), valid - 1, 1);
- if (Integer.parseInt(arr[1]) > date.getActualMaximum(Calendar.DAY_OF_MONTH))
- return false;
- if (arr.length > 3
- && (Integer.parseInt(arr[3]) > 23 || Integer.parseInt(arr[4]) > 59
|| Integer.parseInt(arr[5]) > 59))
- return false;
- return true;
+ return new Object[]{getLabelFor(uiInput), value};
}
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/EmailAddressValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,11 +19,8 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
/**
@@ -33,34 +30,109 @@
* Jun 7, 2006
*
* Validates whether an email is in the correct format
+ * Valid characters that can be used in a domain name are:
+ * a-z
+ * 0-9
+ * - (dash) or . (dot) but not as a starting or ending character
+ * . (dot) as a separator for the textual portions of a domain name
+ *
+ * Valid characters that can be used in a domain name are:
+ * a-z
+ * 0-9
+ * _ (underscore) or . (dot) but not as a starting or ending character
*/
@Serialized
-public class EmailAddressValidator implements Validator
+public class EmailAddressValidator extends MultipleConditionsValidator
{
- static private final String EMAIL_REGEX =
"[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*(a)[_A-Za-z0-9-.]+";
+ @Override
+ protected void validate(String value, String label, CompoundApplicationMessage
messages, UIFormInput uiInput)
+ {
+ Object[] args = {label};
+ int atIndex = value.indexOf('@');
+ if (atIndex == -1)
+ {
+ messages.addMessage("EmailAddressValidator.msg.Invalid-input", args);
+ }
+ else
+ {
+ String localPart = value.substring(0, atIndex);
+ String domainName = value.substring(atIndex + 1);
- public void validate(UIFormInput uiInput) throws Exception
+ if (!validateLocalPart(localPart.toCharArray()) ||
!validateDomainName(domainName.toCharArray()))
+ {
+ messages.addMessage("EmailAddressValidator.msg.Invalid-input",
args);
+ }
+ }
+
+ }
+
+ private boolean validateLocalPart(char[] localPart)
{
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ if(!Character.isLetter(localPart[0]) ||
!Character.isLetterOrDigit(localPart[localPart.length - 1]))
{
- label = uiForm.getId() + ".label." + uiInput.getName();
+ return false;
}
- catch (Exception e)
+
+ for(int i = 1; i < localPart.length -1; i++)
{
- label = uiInput.getName();
+ char c = localPart[i];
+ char next = localPart[i+1];
+
+ if(Character.isLetterOrDigit(c) || (isLocalPartSymbol(c) &&
Character.isLetterOrDigit(next)))
+ {
+ continue;
+ }
+ else
+ {
+ return false;
+ }
}
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- return;
- String s = (String)uiInput.getValue();
- if (s.matches(EMAIL_REGEX))
- return;
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("EmailAddressValidator.msg.Invalid-input", args,
- ApplicationMessage.WARNING));
+ return true;
}
+
+ private boolean validateDomainName(char[] domainName)
+ {
+ if(!Character.isLetter(domainName[0]) ||
!Character.isLetterOrDigit(domainName[domainName.length - 1]))
+ {
+ return false;
+ }
+
+ //Check if there is no non-alphabet following the last dot
+ boolean foundValidLastDot = false;
+ for(int i = 1; i < domainName.length -1; i++)
+ {
+ char c = domainName[i];
+ char next = domainName[i+1];
+
+ if(c == '.')
+ {
+ foundValidLastDot = true;
+ }
+ else if(!Character.isLetter(c))
+ {
+ foundValidLastDot = false;
+ }
+
+ if(Character.isLetterOrDigit(c) || (isDomainNameSymbol(c) &&
Character.isLetterOrDigit(next)))
+ {
+ continue;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ return foundValidLastDot;
+ }
+
+ private boolean isLocalPartSymbol(char c)
+ {
+ return c == '_' || c == '.';
+ }
+
+ private boolean isDomainNameSymbol(char c)
+ {
+ return c == '-' || c == '.';
+ }
}
\ No newline at end of file
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ExpressionValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -19,25 +19,24 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
/**
* Created by The eXo Platform SARL
* Author : Le Bien Thuy
* lebienthuy(a)gmail.com
* Oct 10, 2007
- *
+ *
* Validates whether this value matches one regular expression.
*/
@Serialized
-public class ExpressionValidator implements Validator
+public class ExpressionValidator extends AbstractValidator
{
- private String expression_;
+ private Matcher matcher;
private String key_;
@@ -46,44 +45,34 @@
{
}
- public ExpressionValidator(final String expression)
+ public ExpressionValidator(final String regex)
{
- expression_ = expression;
+ matcher = Pattern.compile(regex).matcher("");
key_ = "ExpressionValidator.msg.value-invalid";
}
- public ExpressionValidator(final String exp, final String key)
+ public ExpressionValidator(final String regex, final String key)
{
- expression_ = exp;
+ matcher = Pattern.compile(regex).matcher("");
key_ = key;
}
- public void validate(final UIFormInput uiInput) throws Exception
+ @Override
+ protected String getMessageLocalizationKey()
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- {
- return;
- }
-
- String value = ((String)uiInput.getValue()).trim();
- if (value.matches(expression_))
- {
- return;
- }
+ return key_;
+ }
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
- {
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- Object[] args = {label};
- throw new MessageException(new ApplicationMessage(key_, args,
ApplicationMessage.WARNING));
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ matcher.reset(value);
+ return matcher.matches();
}
+
+ @Override
+ protected Object[] getMessageArgs(String value, UIFormInput uiInput) throws Exception
+ {
+ return new Object[]{getLabelFor(uiInput), matcher.pattern().toString()};
+ }
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/IdentifierValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,10 +19,7 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
import java.io.Serializable;
@@ -33,44 +30,27 @@
* minhdv81(a)yahoo.com
* Jun 7, 2006
*
- * Validates whether the value is composed of letters, numbers or '_'
+ * Validates whether the value is composed of letters, digit , '_' or
'-'h
+ * First character could not be digit or '-'
*/
-public class IdentifierValidator implements Validator, Serializable
+public class IdentifierValidator extends MultipleConditionsValidator implements
Serializable
{
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected void validate(String value, String label, CompoundApplicationMessage
messages, UIFormInput uiInput)
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- return;
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ if (Character.isDigit(value.charAt(0)) || value.charAt(0) == '-')
{
- label = uiForm.getId() + ".label." + uiInput.getName();
+ messages.addMessage("FirstAndSpecialCharacterNameValidator.msg", new
Object[]{label, uiInput.getBindingField()});
}
- catch (Exception e)
+ for (int i = 0; i < value.length(); i++)
{
- label = uiInput.getName();
- }
- String s = (String)uiInput.getValue();
- if (Character.isDigit(s.charAt(0)) || s.charAt(0) == '-')
- {
- Object[] args = {label, uiInput.getBindingField()};
- throw new MessageException(new
ApplicationMessage("FirstAndSpecialCharacterNameValidator.msg", args,
- ApplicationMessage.WARNING));
- }
- for (int i = 0; i < s.length(); i++)
- {
- char c = s.charAt(i);
+ char c = value.charAt(i);
if (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c ==
'-')
{
continue;
}
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("IdentifierValidator.msg.Invalid-char", args,
- ApplicationMessage.WARNING));
+ messages.addMessage("IdentifierValidator.msg.Invalid-char", new
Object[]{label});
}
}
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MandatoryValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,10 +19,6 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
import java.io.Serializable;
@@ -38,31 +34,27 @@
* is mandatory in your form, add it this validator. A '*' character will be
automatically added
* during the rendering phase to specify the user
*/
-public class MandatoryValidator implements Validator, Serializable
+public class MandatoryValidator extends AbstractValidator implements Serializable
{
public void validate(UIFormInput uiInput) throws Exception
{
- if ((uiInput.getValue() != null) &&
((String)uiInput.getValue()).trim().length() > 0)
+ String value = (String)uiInput.getValue();
+ if (value == null || value.trim().isEmpty())
{
- return;
+ throw createMessageException("EmptyFieldValidator.msg.empty-input",
uiInput);
}
+ }
- //modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
- {
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- label = label.trim();
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("EmptyFieldValidator.msg.empty-input", args,
- ApplicationMessage.WARNING));
+ @Override
+ protected String getMessageLocalizationKey()
+ {
+ return "EmptyFieldValidator.msg.empty-input";
}
+
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ throw new UnsupportedOperationException("Unneeded by this
implementation");
+ }
}
Added:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MultipleConditionsValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MultipleConditionsValidator.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/MultipleConditionsValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2012, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.webui.form.validator;
+
+import org.exoplatform.web.application.CompoundApplicationMessage;
+import org.exoplatform.webui.exception.MessageException;
+import org.exoplatform.webui.form.UIFormInput;
+
+import java.io.Serializable;
+
+/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
+public abstract class MultipleConditionsValidator extends AbstractValidator implements
Serializable
+{
+ public void validate(UIFormInput uiInput) throws Exception
+ {
+ String value = trimmedValueOrNullIfBypassed((String)uiInput.getValue(), uiInput,
exceptionOnMissingMandatory, trimValue);
+ if (value == null)
+ {
+ return;
+ }
+
+ String label = getLabelFor(uiInput);
+
+ CompoundApplicationMessage messages = new CompoundApplicationMessage();
+
+ validate(value, label, messages, uiInput);
+
+ if (!messages.isEmpty())
+ {
+ throw new MessageException(messages);
+ }
+ }
+
+ protected abstract void validate(String value, String label,
CompoundApplicationMessage messages, UIFormInput uiInput);
+
+ @Override
+ protected String getMessageLocalizationKey()
+ {
+ throw new UnsupportedOperationException("Unneeded by this
implementation");
+ }
+
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ throw new UnsupportedOperationException("Unneeded by this
implementation");
+ }
+}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NameValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,10 +19,6 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
import java.io.Serializable;
@@ -35,36 +31,29 @@
*
* Validates whether this value is composed of letters, numbers, '_',
'-', '.' or '*'
*/
-public class NameValidator implements Validator, Serializable
+public class NameValidator extends AbstractValidator implements Serializable
{
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected String getMessageLocalizationKey()
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- return;
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ return "NameValidator.msg.Invalid-char";
+ }
+
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ for (int i = 0; i < value.length(); i++)
{
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- String s = (String)uiInput.getValue();
- for (int i = 0; i < s.length(); i++)
- {
- char c = s.charAt(i);
+ char c = value.charAt(i);
if (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c ==
'-' || c == '.' || c == '*')
{
continue;
}
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("NameValidator.msg.Invalid-char", args));
+ return false;
}
+
+ return true;
}
}
Added:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NaturalLanguageValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NaturalLanguageValidator.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NaturalLanguageValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -0,0 +1,52 @@
+/**
+ * Copyright (C) 2003-2011 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.webui.form.validator;
+
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.webui.form.UIFormInput;
+
+/**
+ * @author <a href="mailto:haint@exoplatform.com">Nguyen Thanh
Hai</a>
+ * @datOct 11, 2011
+ *
+ * Validates whether this value is composed of letters or spaces
+ */
+@Serialized
+public class NaturalLanguageValidator extends AbstractValidator
+{
+
+ @Override
+ protected String getMessageLocalizationKey()
+ {
+ return "NaturalLanguageValidator.msg.Invalid-char";
+ }
+
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ for (int i = 0; i < value.length(); i++)
+ {
+ char c = value.charAt(i);
+ if (Character.isLetter(c) || Character.isSpaceChar(c))
+ {
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
+}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NullFieldValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,12 +19,10 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
+import java.io.Serializable;
+
/**
* Created by The eXo Platform SARL
* Author : Dang Van Minh
@@ -33,26 +31,26 @@
*
* Validates whether this value is null
*/
-public class NullFieldValidator implements Validator
+public class NullFieldValidator extends AbstractValidator implements Serializable
{
public void validate(UIFormInput uiInput) throws Exception
{
- if ((uiInput.getValue() != null))
- return;
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ if ((uiInput.getValue() == null))
{
- label = uiForm.getId() + ".label." + uiInput.getName();
+ throw createMessageException(null, uiInput);
}
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("EmptyFieldValidator.msg.empty-input", args));
}
+
+ @Override
+ protected String getMessageLocalizationKey()
+ {
+ return "EmptyFieldValidator.msg.empty-input";
+ }
+
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ throw new UnsupportedOperationException("Unneeded by this
implementation");
+ }
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/NumberFormatValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -19,51 +19,47 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
+import java.io.Serializable;
+
/**
* Created by The eXo Platform SARL
* Author : Dang Van Minh
* minhdv81(a)yahoo.com
* Jun 7, 2006
- *
+ *
* Validates whether this number is in a correct format
*/
-public class NumberFormatValidator implements Validator
+public class NumberFormatValidator extends MultipleConditionsValidator implements
Serializable
{
+ @Override
+ protected void validate(String value, String label, CompoundApplicationMessage
messages, UIFormInput uiInput)
+ {
+ validateInteger(value, label, messages);
+ }
- public void validate(UIFormInput uiInput) throws Exception
+ protected Integer validateInteger(String value, String label,
CompoundApplicationMessage messages)
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).length() == 0)
- return;
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ Object[] args = {label};
+ if (value.charAt(0) == '0' && value.length() > 1)
{
- label = uiForm.getId() + ".label." + uiInput.getName();
+ messages.addMessage("NumberFormatValidator.msg.Invalid-number",
args);
}
- catch (Exception e)
+ else if (value.charAt(0) == '-' && value.length() > 1 &&
value.charAt(1) == '0')
{
- label = uiInput.getName();
+ messages.addMessage("NumberFormatValidator.msg.Invalid-number",
args);
}
- label = label.trim();
- String s = (String)uiInput.getValue();
- for (int i = 0; i < s.length(); i++)
+ try
{
- char c = s.charAt(i);
- if (Character.isDigit(c) || (s.charAt(0) == '-' && i == 0
&& s.length() > 1))
- {
- continue;
- }
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("NumberFormatValidator.msg.Invalid-number", args));
+ return Integer.parseInt(value);
}
+ catch (NumberFormatException e)
+ {
+ messages.addMessage("NumberFormatValidator.msg.Invalid-number",
args);
+ return null;
+ }
}
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PasswordStringLengthValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PasswordStringLengthValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PasswordStringLengthValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,12 +19,7 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
-import org.exoplatform.webui.form.UIFormInput;
/**
* Created by The eXo Platform SARL
@@ -35,18 +30,8 @@
* Validates whether this value has a length between min and max
*/
@Serialized
-public class PasswordStringLengthValidator implements Validator
+public class PasswordStringLengthValidator extends StringLengthValidator
{
- /**
- * The minimum number of characters in this String
- */
- private Integer min_ = 0;
-
- /**
- * The maximum number of characters in this String
- */
- private Integer max_ = 0;
-
// For @Serialized needs
public PasswordStringLengthValidator()
{
@@ -54,40 +39,17 @@
public PasswordStringLengthValidator(Integer max)
{
- max_ = max;
+ super(max);
}
public PasswordStringLengthValidator(Integer min, Integer max)
{
- min_ = min;
- max_ = max;
+ super(min, max);
}
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected String getValue(String value)
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- return;
- if ((uiInput.getValue() != null))
- {
- int length = ((String)uiInput.getValue()).length();
- if (min_ <= length && max_ >= length)
- return;
- }
-
- //modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
- {
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- Object[] args = {label, min_.toString(), max_.toString()};
- throw new MessageException(new
ApplicationMessage("StringLengthValidator.msg.length-invalid", args,
- ApplicationMessage.WARNING));
+ return value;
}
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/PositiveNumberFormatValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,12 +19,10 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
-import org.exoplatform.webui.form.UIFormInput;
+import org.exoplatform.web.application.CompoundApplicationMessage;
+import java.io.Serializable;
+
/**
* Created by The eXo Platform SARL
* Author : Vu Duy Tu
@@ -34,43 +32,26 @@
* Validates whether this number is positive or 0
*/
-public class PositiveNumberFormatValidator implements Validator
+public class PositiveNumberFormatValidator extends NumberFormatValidator implements
Serializable
{
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected Integer validateInteger(String value, String label,
CompoundApplicationMessage messages)
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).length() == 0)
- return;
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ Integer integer = super.validateInteger(value, label, messages);
+
+ if(integer == null)
{
- label = uiForm.getId() + ".label." + uiInput.getName();
+ return null;
}
- catch (Exception e)
+ else if(integer < 0)
{
- label = uiInput.getName();
+
messages.addMessage("PositiveNumberFormatValidator.msg.Invalid-number", new
Object[]{label});
+ return null;
}
- String s = (String)uiInput.getValue();
- boolean error = false;
- for (int i = 0; i < s.length(); i++)
+ else
{
- char c = s.charAt(i);
- if (Character.isDigit(c) || (s.charAt(0) == '-' && i == 0))
- {
- error = true;
- continue;
- }
- error = false;
- Object[] args = {label, uiInput.getBindingField()};
- throw new MessageException(new
ApplicationMessage("NumberFormatValidator.msg.Invalid-number", args));
+ return integer;
}
- if (error == true && s.charAt(0) == '-')
- {
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("PositiveNumberFormatValidator.msg.Invalid-number", args));
- }
}
}
\ No newline at end of file
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/ResourceValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -19,11 +19,8 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.web.application.CompoundApplicationMessage;
import org.exoplatform.webui.form.UIFormInput;
/**
@@ -31,46 +28,30 @@
* Author : dang.tung
* tungcnw(a)gmail.com
* 14 March, 2006
- *
+ *
* Validates whether the value is composed of letters, numbers or '_'
*/
@Serialized
-public class ResourceValidator implements Validator
+public class ResourceValidator extends MultipleConditionsValidator
{
-
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected void validate(String value, String label, CompoundApplicationMessage
messages, UIFormInput uiInput)
{
- if (uiInput == null || ((String)uiInput.getValue()).trim().length() == 0)
- return;
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ char firstChar = value.charAt(0);
+ if (Character.isDigit(firstChar) || firstChar == '-' || firstChar ==
'.' || firstChar == '_')
{
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- String s = (String)uiInput.getValue();
- if (Character.isDigit(s.charAt(0)) || s.charAt(0) == '-' || s.charAt(0) ==
'.' || s.charAt(0) == '_')
- {
Object[] args = {label, uiInput.getBindingField()};
- throw new MessageException(new
ApplicationMessage("FirstCharacterNameValidator.msg", args,
- ApplicationMessage.WARNING));
+ messages.addMessage("FirstCharacterNameValidator.msg", args);
}
- for (int i = 0; i < s.length(); i++)
+ for (int i = 0; i < value.length(); i++)
{
- char c = s.charAt(i);
+ char c = value.charAt(i);
if (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c ==
'-' || c == '.')
{
continue;
}
Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("ResourceValidator.msg.Invalid-char", args,
- ApplicationMessage.WARNING));
+ messages.addMessage("ResourceValidator.msg.Invalid-char", args);
}
}
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/SpecialCharacterValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -19,50 +19,37 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
/**
* Created by The eXo Platform SARL
* Author : dang.tung
* tungcnw(a)gmail.com
- * Dec 12, 2007
+ * Dec 12, 2007
*/
@Serialized
-public class SpecialCharacterValidator implements Validator
+public class SpecialCharacterValidator extends AbstractValidator
{
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected String getMessageLocalizationKey()
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- return;
- // modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
+ return "SpecialCharacterValidator.msg.Invalid-char";
+ }
+
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ for (int i = 0; i < value.length(); i++)
{
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- String s = (String)uiInput.getValue();
- for (int i = 0; i < s.length(); i++)
- {
- char c = s.charAt(i);
+ char c = value.charAt(i);
if (Character.isLetter(c) || Character.isDigit(c) || c == '_' || c ==
'-' || Character.isSpaceChar(c))
{
continue;
}
- Object[] args = {label};
- throw new MessageException(new
ApplicationMessage("SpecialCharacterValidator.msg.Invalid-char", args,
- ApplicationMessage.WARNING));
+ return false;
}
+ return true;
}
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/StringLengthValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/StringLengthValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/StringLengthValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -19,34 +19,30 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.form.UIFormInput;
-import java.io.Serializable;
-
/**
* Created by The eXo Platform SARL
* Author : Dang Van Minh
- * minhdv81(a)yahoo.com
+ * minhdv81(a)yahoo.com
* Jun 7, 2006
- *
+ * <p/>
* Validates whether this value has a length between min and max
*/
-public class StringLengthValidator implements Validator, Serializable
+@Serialized
+public class StringLengthValidator extends AbstractValidator
{
- /**
- * The minimum number of characters in this String
- */
+ /** The minimum number of characters in this String */
private Integer min_ = 0;
- /**
- * The maximum number of characters in this String
- */
+ /** The maximum number of characters in this String */
private Integer max_ = 0;
+ public StringLengthValidator()
+ {
+ }
+
public StringLengthValidator(Integer max)
{
max_ = max;
@@ -58,31 +54,27 @@
max_ = max;
}
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected String getMessageLocalizationKey()
{
- if (uiInput.getValue() == null || ((String)uiInput.getValue()).trim().length() ==
0)
- return;
- if ((uiInput.getValue() != null))
- {
- int length = ((String)uiInput.getValue()).trim().length();
- if (min_ <= length && max_ >= length)
- return;
- }
+ return "StringLengthValidator.msg.length-invalid";
+ }
- //modified by Pham Dinh Tan
- UIComponent uiComponent = (UIComponent)uiInput;
- UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
- String label;
- try
- {
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- Object[] args = {label, min_.toString(), max_.toString()};
- throw new MessageException(new
ApplicationMessage("StringLengthValidator.msg.length-invalid", args,
- ApplicationMessage.WARNING));
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
+ {
+ int length = getValue(value).length();
+ return min_ <= length && max_ >= length;
}
+
+ protected String getValue(String value)
+ {
+ return value.trim();
+ }
+
+ @Override
+ protected Object[] getMessageArgs(String value, UIFormInput uiInput) throws Exception
+ {
+ return new Object[]{getLabelFor(uiInput), min_.toString(), max_.toString()};
+ }
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/URLValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/URLValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/URLValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,69 +19,37 @@
package org.exoplatform.webui.form.validator;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
-import org.exoplatform.webui.form.UIFormInput;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import java.io.Serializable;
-
/**
* Created by The eXo Platform SAS
* Author : Tan Pham Dinh
* pdtanit(a)gmail.com
* Oct 30, 2008
*/
-public class URLValidator implements Validator, Serializable
+@Serialized
+public class URLValidator extends ExpressionValidator
{
-
+
static private final String IP_REGEX =
-
"(((25[0-5])|(2[0-4][0-9])|([01]?[0-9]?[0-9]))\\.){3}((25[0-5])|(2[0-4][0-9])|([01]?[0-9]?[0-9]))";
-
- // static public final String URL_REGEX =
- // "^(ht|f)tp(s?)://(\\w+:\\w+@)?(("+ IP_REGEX
+")|((www.)?(\\S+\\.){1,2}(\\w{2,5}))|([a-zA-Z][-a-zA-Z0-9]+))" +
- // "(:\\d{1,5})?($|((/[-+%.\\w\\d
]+)*/?((\\.\\w+)?($|\\?([-.:+\\w\\d%/]+=[-.:+\\w\\d%/]+)(&[-.:+\\w\\d%/]+=[-.:+\\w\\d%/]+)*))?))"
;
+
"(((((25[0-5])|(2[0-4][0-9])|([01]?[0-9]?[0-9]))\\.){3}((25[0-4])|(2[0-4][0-9])|((1?[1-9]?[1-9])|([1-9]0))))|(0\\.){3}0)";
+
static public final String URL_REGEX = "^((ht|f)tp(s?)://)" //protocol
- + "(\\w+:\\w+@)?" //username:password@
+ + "(\\w+(:\\w+)?@)?" //username:password@
+ "(" + IP_REGEX //ip
+
"|([0-9a-z_!~*'()-]+\\.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\\.[a-z]{2,6}"
//domain like
www.exoplatform.org
+ "|([a-zA-Z][-a-zA-Z0-9]+))" // domain like localhost
+ "(:[0-9]{1,5})?" // port number :8080
+ "((/?)|(/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+/?)$"; //uri
+ private static final String DEFAULT_KEY = "URLValidator.msg.invalid-url";
- private String key_;
-
public URLValidator()
{
- key_ = "URLValidator.msg.invalid-url";
+ this(DEFAULT_KEY);
}
public URLValidator(String key)
{
- if (key != null)
- key_ = key;
+ super(URL_REGEX, key != null ? key : DEFAULT_KEY);
}
-
- public void validate(UIFormInput uiInput) throws Exception
- {
- if ((uiInput.getValue() == null) || (uiInput.getValue().toString().trim().length()
== 0))
- return;
- String s = uiInput.getValue().toString().trim();
- if (s.matches(URL_REGEX))
- return;
-
- UIForm uiForm = ((UIComponent)uiInput).getAncestorOfType(UIForm.class);
- String label;
- try
- {
- label = uiForm.getId() + ".label." + uiInput.getName();
- }
- catch (Exception e)
- {
- label = uiInput.getName();
- }
- Object[] args = {label};
- throw new MessageException(new ApplicationMessage(key_, args,
ApplicationMessage.WARNING));
- }
}
Added:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UserConfigurableValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -0,0 +1,195 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2012, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.exoplatform.webui.form.validator;
+
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.portal.pom.config.Utils;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.web.application.CompoundApplicationMessage;
+import org.exoplatform.webui.form.UIFormInput;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.regex.Pattern;
+
+/**
+ * A user-configurable validator. Several aspects of this validator can be configured via
properties in the
+ * configuration.properties file found in the GateIn configuration directory
(${gatein.conf.dir}. The validator
+ * supports several configurations that can be activated when a validator instance is
created by passing it the name of
+ * the configuration to be activated. A configuration is created by adding an entry in
configuration.properties using
+ * the {@link #KEY_PREFIX} prefix followed by the name of the configuration, a period
'.' and the name of the
+ * validation aspect to modify.
+ * <p/>
+ * Currently supported validation aspects, where {configuration} is a configuration's
name:
+ * <ul>
+ * <li>{@link #KEY_PREFIX}{configuration}.length.min: the minimal length of the
validated field</li>
+ * <li>{@link #KEY_PREFIX}{configuration}.length.max: the maximal length of the
validated field</li>
+ * <li>{@link #KEY_PREFIX}{configuration}.regexp: the regular expression to which
the validated field must conform</li>
+ * <li>{@link #KEY_PREFIX}{configuration}.format.message: a message to display
providing details about the format of
+ * values the regular expression allows in case the validated field doesn't conform
to it</li>
+ * </ul>
+ *
+ * Currently used configurations in the code are defined by the {@link #USERNAME} and
{@link #GROUPMEMBERSHIP} names.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ */
+@Serialized
+public class UserConfigurableValidator extends MultipleConditionsValidator
+{
+ protected static Log log = ExoLogger.getLogger(UserConfigurableValidator.class);
+
+ public static final String USERNAME = "username";
+ public static final String GROUPMEMBERSHIP = "groupmembership";
+ public static final String DEFAULT_LOCALIZATION_KEY =
"ExpressionValidator.msg.value-invalid";
+ public static final String GROUP_MEMBERSHIP_VALIDATION_REGEX =
"^\\p{L}[\\p{L}\\d._\\-\\s*,\\s*]+$";
+ public static final String GROUP_MEMBERSHIP_LOCALIZATION_KEY =
"UIGroupMembershipForm.msg.Invalid-char";
+
+ private static Map<String, ValidatorConfiguration> configurations = new
HashMap<String, ValidatorConfiguration>(3);
+
+ public static final String KEY_PREFIX = "gatein.validators.";
+
+ static
+ {
+ String gateinConfDir = System.getProperty("gatein.conf.dir");
+ File conf = new File(gateinConfDir, "configuration.properties");
+ if (conf.exists())
+ {
+ try
+ {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream(conf));
+ int length = KEY_PREFIX.length();
+ for (Object objectKey : properties.keySet())
+ {
+ String key = (String)objectKey;
+ if (key.startsWith(KEY_PREFIX))
+ {
+ // extract property key
+ String propertyKey = key.substring(length, key.indexOf('.',
length));
+ if (!configurations.containsKey(propertyKey))
+ {
+ configurations.put(propertyKey, new
ValidatorConfiguration(propertyKey, properties));
+ }
+ }
+ }
+ }
+ catch (IOException e)
+ {
+ log.info(e.getLocalizedMessage());
+ log.debug(e);
+ }
+ }
+ }
+
+ private final String validatorName;
+ private final String localizationKey;
+
+ // needed by @Serialized
+ public UserConfigurableValidator()
+ {
+ this(USERNAME, DEFAULT_LOCALIZATION_KEY);
+ }
+
+ public UserConfigurableValidator(String configurationName, String
messageLocalizationKey)
+ {
+ this.exceptionOnMissingMandatory = true;
+ this.trimValue = true;
+ localizationKey = messageLocalizationKey != null ? messageLocalizationKey :
DEFAULT_LOCALIZATION_KEY;
+ this.validatorName = configurationName != null ? configurationName : USERNAME;
+ }
+
+ public UserConfigurableValidator(String configurationName)
+ {
+ this(configurationName, DEFAULT_LOCALIZATION_KEY);
+ }
+
+ @Override
+ protected void validate(String value, String label, CompoundApplicationMessage
messages, UIFormInput uiInput)
+ {
+ ValidatorConfiguration configuration = configurations.get(validatorName);
+
+ if (configuration == null)
+ {
+ // we don't have a user-configured validator for this validator name
+
+ if (USERNAME.equals(validatorName))
+ {
+ // if the validator name is USERNAME constant, we have a username to validate
with the original, non-configured behavior
+ UsernameValidator.validate(value, label, messages,
UsernameValidator.DEFAULT_MIN_LENGTH, UsernameValidator.DEFAULT_MAX_LENGTH);
+ }
+ else
+ {
+ // else, we assume that we need to validate a group membership, replicating
original behavior
+ if (!Pattern.matches(GROUP_MEMBERSHIP_VALIDATION_REGEX, value))
+ {
+ messages.addMessage(localizationKey, new Object[]{label});
+ }
+ }
+ }
+ else
+ {
+ // otherwise, use the user-provided configuration
+
+ if (value.length() < configuration.minLength || value.length() >
configuration.maxLength)
+ {
+ messages.addMessage("StringLengthValidator.msg.length-invalid", new
Object[]{label, configuration.minLength.toString(), configuration.maxLength.toString()});
+ }
+
+ if (!Pattern.matches(configuration.pattern, value))
+ {
+ messages.addMessage(localizationKey, new Object[]{label,
configuration.formatMessage});
+ }
+ }
+ }
+
+ private static class ValidatorConfiguration
+ {
+ private Integer minLength;
+ private Integer maxLength;
+ private String pattern;
+ private String formatMessage;
+
+ private ValidatorConfiguration(String propertyKey, Properties properties)
+ {
+ // used to assign backward compatible default values
+ boolean isUser = USERNAME.equals(propertyKey);
+ String prefixedKey = KEY_PREFIX + propertyKey;
+
+ String property = properties.getProperty(prefixedKey +
".length.min");
+ minLength = property != null ? Integer.valueOf(property) : (isUser ?
UsernameValidator.DEFAULT_MIN_LENGTH : 0);
+
+ property = properties.getProperty(prefixedKey + ".length.max");
+ maxLength = property != null ? Integer.valueOf(property) : (isUser ?
UsernameValidator.DEFAULT_MAX_LENGTH : Integer.MAX_VALUE);
+
+ pattern = properties.getProperty(prefixedKey + ".regexp",
Utils.USER_NAME_VALIDATOR_REGEX);
+ formatMessage = properties.getProperty(prefixedKey +
".format.message", pattern);
+ }
+
+ }
+}
Added:
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java
(rev 0)
+++
epp/portal/branches/EPP_5_2_Branch/webui/core/src/main/java/org/exoplatform/webui/form/validator/UsernameValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -0,0 +1,105 @@
+/**
+ * Copyright (C) 2003-2011 eXo Platform SAS.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,
see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.webui.form.validator;
+
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.web.application.CompoundApplicationMessage;
+import org.exoplatform.webui.form.UIFormInput;
+
+/**
+ * Validate username whether the value is only alpha lower, digit, dot and underscore
with first, last character is
+ * alpha lower or digit and cannot contain consecutive underscore, dot or both.
+ *
+ * @author <a href="mailto:haint@exoplatform.com">Nguyen Thanh
Hai</a>
+ * @date Sep 28, 2011
+ */
+
+@Serialized
+public class UsernameValidator extends MultipleConditionsValidator
+{
+ protected static final int DEFAULT_MIN_LENGTH = 3;
+ protected static final int DEFAULT_MAX_LENGTH = 30;
+ protected Integer min = DEFAULT_MIN_LENGTH;
+ protected Integer max = DEFAULT_MAX_LENGTH;
+
+ // required by @Serialized
+ public UsernameValidator()
+ {
+ }
+
+ public UsernameValidator(Integer min, Integer max)
+ {
+ this.min = min;
+ this.max = max;
+ }
+
+ protected void validate(String value, String label, CompoundApplicationMessage
messages, UIFormInput uiInput)
+ {
+ validate(value, label, messages, min, max);
+ }
+
+ static void validate(String value, String label, CompoundApplicationMessage messages,
Integer min, Integer max)
+ {
+ char[] buff = value.toCharArray();
+ if (buff.length < min || buff.length > max)
+ {
+ 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});
+ }
+
+ if (!Character.isLetterOrDigit(buff[buff.length - 1]))
+ {
+ messages.addMessage("LastCharacterUsernameValidator.msg", new
Object[]{label, buff[buff.length - 1]});
+ }
+
+ for (int i = 1; i < buff.length - 1; i++)
+ {
+ char c = buff[i];
+
+ if (Character.isLetterOrDigit(c))
+ {
+ continue;
+ }
+
+ if (isSymbol(c))
+ {
+ char next = buff[i + 1];
+ if (isSymbol(next))
+ {
+ 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});
+ }
+ }
+ else
+ {
+ messages.addMessage("UsernameValidator.msg.Invalid-char", new
Object[]{label});
+ }
+ }
+ }
+
+ private static boolean isSymbol(char c)
+ {
+ return c == '_' || c == '.';
+ }
+}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIAccountInputSet.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIAccountInputSet.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/eXo/src/main/java/org/exoplatform/webui/organization/UIAccountInputSet.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -20,7 +20,6 @@
package org.exoplatform.webui.organization;
import org.exoplatform.commons.serialization.api.annotations.Serialized;
-import org.exoplatform.portal.pom.config.Utils;
import org.exoplatform.services.organization.OrganizationService;
import org.exoplatform.services.organization.Query;
import org.exoplatform.services.organization.User;
@@ -30,11 +29,10 @@
import org.exoplatform.webui.form.UIFormInputWithActions;
import org.exoplatform.webui.form.UIFormStringInput;
import org.exoplatform.webui.form.validator.EmailAddressValidator;
-import org.exoplatform.webui.form.validator.ExpressionValidator;
import org.exoplatform.webui.form.validator.MandatoryValidator;
import org.exoplatform.webui.form.validator.PasswordStringLengthValidator;
-import org.exoplatform.webui.form.validator.ResourceValidator;
import org.exoplatform.webui.form.validator.StringLengthValidator;
+import org.exoplatform.webui.form.validator.UserConfigurableValidator;
/**
* Created by The eXo Platform SARL
@@ -61,8 +59,7 @@
super(name);
//setComponentConfig(getClass(), null) ;
addUIFormInput(new UIFormStringInput(USERNAME, "userName",
null).addValidator(MandatoryValidator.class)
- .addValidator(StringLengthValidator.class, 3,
30).addValidator(ResourceValidator.class).addValidator(
- ExpressionValidator.class, Utils.USER_NAME_VALIDATOR_REGEX,
"ResourceValidator.msg.Invalid-char"));
+ .addValidator(UserConfigurableValidator.class,
UserConfigurableValidator.USERNAME));
addUIFormInput(new UIFormStringInput(PASSWORD1X, "password",
null).setType(UIFormStringInput.PASSWORD_TYPE)
.addValidator(MandatoryValidator.class).addValidator(PasswordStringLengthValidator.class,
6, 30));
addUIFormInput(new UIFormStringInput(PASSWORD2X, "password",
null).setType(UIFormStringInput.PASSWORD_TYPE)
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIApplication.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIApplication.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIApplication.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,11 +19,12 @@
package org.exoplatform.webui.core;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
+import org.exoplatform.web.application.AbstractApplicationMessage;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.exception.MessageException;
import java.io.Writer;
@@ -82,7 +83,7 @@
return uiPopupMessages_;
}
- public void addMessage(ApplicationMessage message)
+ public void addMessage(AbstractApplicationMessage message)
{
getUIPopupMessages().addMessage(message);
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIPopupMessages.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIPopupMessages.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/core/UIPopupMessages.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,10 +19,11 @@
package org.exoplatform.webui.core;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.web.application.AbstractApplicationMessage;
import org.exoplatform.web.application.ApplicationMessage;
import org.exoplatform.web.application.RequestContext;
import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.commons.serialization.api.annotations.Serialized;
import org.exoplatform.webui.config.annotation.ComponentConfig;
import org.exoplatform.webui.config.annotation.EventConfig;
import org.exoplatform.webui.event.Event;
@@ -48,53 +49,53 @@
/**
* The error messages
*/
- private List<ApplicationMessage> errors_;
+ private List<AbstractApplicationMessage> errors_;
/**
* The warning messages
*/
- private List<ApplicationMessage> warnings_;
+ private List<AbstractApplicationMessage> warnings_;
/**
* The info messages
*/
- private List<ApplicationMessage> infos_;
+ private List<AbstractApplicationMessage> infos_;
public UIPopupMessages()
{
- errors_ = new ArrayList<ApplicationMessage>();
- warnings_ = new ArrayList<ApplicationMessage>();
- infos_ = new ArrayList<ApplicationMessage>();
+ errors_ = new ArrayList<AbstractApplicationMessage>();
+ warnings_ = new ArrayList<AbstractApplicationMessage>();
+ infos_ = new ArrayList<AbstractApplicationMessage>();
setShowMask(true);
setShow(true);
}
- public List<ApplicationMessage> getErrors()
+ public List<AbstractApplicationMessage> getErrors()
{
return errors_;
}
- public void setErrors(List<ApplicationMessage> errors_)
+ public void setErrors(List<AbstractApplicationMessage> errors_)
{
this.errors_ = errors_;
}
- public List<ApplicationMessage> getInfos()
+ public List<AbstractApplicationMessage> getInfos()
{
return infos_;
}
- public void setInfos(List<ApplicationMessage> infos_)
+ public void setInfos(List<AbstractApplicationMessage> infos_)
{
this.infos_ = infos_;
}
- public List<ApplicationMessage> getWarnings()
+ public List<AbstractApplicationMessage> getWarnings()
{
return warnings_;
}
- public void setWarnings(List<ApplicationMessage> warnings_)
+ public void setWarnings(List<AbstractApplicationMessage> warnings_)
{
this.warnings_ = warnings_;
}
@@ -104,7 +105,7 @@
super.processRender(context);
}
- public void addMessage(ApplicationMessage msg)
+ public void addMessage(AbstractApplicationMessage msg)
{
msg.setResourceBundle(getResourceBundle());
switch (msg.getType())
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/exception/MessageException.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/exception/MessageException.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/framework/src/main/java/org/exoplatform/webui/exception/MessageException.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -19,7 +19,7 @@
package org.exoplatform.webui.exception;
-import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.web.application.AbstractApplicationMessage;
/**
* Created by The eXo Platform SARL
@@ -32,14 +32,14 @@
public class MessageException extends Exception
{
- private ApplicationMessage message;
+ private AbstractApplicationMessage message;
- public MessageException(ApplicationMessage message)
+ public MessageException(AbstractApplicationMessage message)
{
this.message = message;
}
- public ApplicationMessage getDetailMessage()
+ public AbstractApplicationMessage getDetailMessage()
{
return message;
}
Modified:
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
===================================================================
---
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java 2012-02-09
19:04:37 UTC (rev 8416)
+++
epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java 2012-02-09
19:14:27 UTC (rev 8417)
@@ -1,16 +1,16 @@
/**
* Copyright (C) 2009 eXo Platform SAS.
- *
+ *
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
- *
+ *
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
- *
+ *
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
@@ -19,61 +19,49 @@
package org.exoplatform.portal.webui;
-import org.exoplatform.web.application.ApplicationMessage;
+import nl.captcha.Captcha;
import org.exoplatform.webui.application.portlet.PortletRequestContext;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.exception.MessageException;
-import org.exoplatform.webui.form.UIForm;
import org.exoplatform.webui.form.UIFormInput;
-import org.exoplatform.webui.form.validator.Validator;
+import org.exoplatform.webui.form.validator.AbstractValidator;
-import nl.captcha.Captcha;
-
-import java.io.Serializable;
-
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
+import java.io.Serializable;
/**
* @author <a href="mailto:theute@redhat.com">Thomas Heute</a>
- * Validator for Captcha content.
- * Checks that the user input is equals to the content displayed by the
- * distorted image.
+ * Validator for Captcha content.
+ * Checks that the user input is equals to the content displayed by the
+ * distorted image.
*/
-public class CaptchaValidator implements Validator, Serializable
+public class CaptchaValidator extends AbstractValidator implements Serializable
{
- public void validate(UIFormInput uiInput) throws Exception
+ @Override
+ protected boolean isValid(String value, UIFormInput uiInput)
{
PortletRequestContext ctx = PortletRequestContext.getCurrentInstance();
PortletRequest req = ctx.getRequest();
PortletSession session = req.getPortletSession();
- Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);
+ Captcha captcha = (Captcha)session.getAttribute(Captcha.NAME);
- if ((captcha != null) && (captcha.isCorrect((String) uiInput.getValue())))
- {
- return;
- }
+ return ((captcha != null) && (captcha.isCorrect(value)));
+ }
- //modified by Pham Dinh Tan
- 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();
+ protected String getMessageLocalizationKey()
+ {
+ return "CaptchaValidator.msg.Invalid-input";
+ }
+
+ @Override
+ protected Object[] getMessageArgs(String value, UIFormInput uiInput) throws Exception
+ {
+ String label = getLabelFor(uiInput);
if (label.charAt(label.length() - 1) == ':')
+ {
label = label.substring(0, label.length() - 1);
- Object[] args =
- {label, uiInput.getBindingField()};
- throw new MessageException(new
ApplicationMessage("CaptchaValidator.msg.Invalid-input", args,
- ApplicationMessage.WARNING));
+ }
+ return new Object[]{label, uiInput.getBindingField()};
}
}