[gatein-commits] gatein SVN: r8245 - in components/wsrp/trunk: admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Dec 13 08:54:38 EST 2011


Author: chris.laprun at jboss.com
Date: 2011-12-13 08:54:37 -0500 (Tue, 13 Dec 2011)
New Revision: 8245

Modified:
   components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/LocalizedStringConverter.java
   components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java
   components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource.properties
   components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource_fr.properties
   components/wsrp/trunk/admin-gui/src/main/webapp/jsf/producer/producer.xhtml
   components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java
Log:
- GTNWSRP-275: made ProducerBean implement registration property name/hint/label validation.

Modified: components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/LocalizedStringConverter.java
===================================================================
--- components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/LocalizedStringConverter.java	2011-12-13 11:31:04 UTC (rev 8244)
+++ components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/LocalizedStringConverter.java	2011-12-13 13:54:37 UTC (rev 8245)
@@ -1,6 +1,6 @@
 /*
  * JBoss, a division of Red Hat
- * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -43,6 +43,11 @@
 
    public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object o)
    {
-      return o == null ? null : ((LocalizedString)o).getValue();
+      return getAsString(o);
    }
+
+   static String getAsString(Object localizedString)
+   {
+      return localizedString == null ? null : ((LocalizedString)localizedString).getValue();
+   }
 }

Modified: components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java
===================================================================
--- components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java	2011-12-13 11:31:04 UTC (rev 8244)
+++ components/wsrp/trunk/admin-gui/src/main/java/org/gatein/wsrp/admin/ui/ProducerBean.java	2011-12-13 13:54:37 UTC (rev 8245)
@@ -30,14 +30,17 @@
 import org.gatein.wsrp.producer.config.ProducerConfigurationService;
 import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
 import org.gatein.wsrp.producer.config.impl.ProducerRegistrationRequirementsImpl;
+import org.gatein.wsrp.registration.LocalizedString;
 import org.gatein.wsrp.registration.RegistrationPropertyDescription;
 
+import javax.faces.application.FacesMessage;
 import javax.faces.component.UIComponent;
 import javax.faces.component.html.HtmlDataTable;
 import javax.faces.context.FacesContext;
 import javax.faces.event.ActionEvent;
 import javax.faces.event.ValueChangeEvent;
 import javax.faces.model.SelectItem;
+import javax.faces.validator.ValidatorException;
 import javax.xml.namespace.QName;
 import java.io.Serializable;
 import java.util.ArrayList;
@@ -53,6 +56,7 @@
  */
 public class ProducerBean extends ManagedBean implements Serializable
 {
+   private static final String REGISTRATION_PROPERTY_TYPE = "REGISTRATION_PROPERTY_TYPE";
    private transient ProducerConfigurationService configurationService;
    private String policyClassName;
    private String validatorClassName;
@@ -285,12 +289,13 @@
 
    protected String getObjectTypeName()
    {
-      return null; // default implementation as not used
+      return REGISTRATION_PROPERTY_TYPE;
    }
 
    public boolean isAlreadyExisting(String objectName)
    {
-      return false; // default implementation as not used
+      // allow for edit of properties since they will be replaced anyway
+      return false;
    }
 
    private LocalProducerConfiguration getLocalConfiguration()
@@ -315,6 +320,25 @@
       return beanContext.getServerAddress() + "/wsrp-producer/v2/MarkupService?wsdl";
    }
 
+   public void validate(FacesContext facesContext, UIComponent uiComponent, Object o)
+   {
+      String toValidate = null;
+      if (o instanceof String)
+      {
+         toValidate = (String)o;
+      }
+      else if (o instanceof LocalizedString)
+      {
+         toValidate = LocalizedStringConverter.getAsString(o);
+      }
+
+      final String validated = this.checkNameValidity(toValidate, uiComponent.getClientId(facesContext));
+      if (validated == null)
+      {
+         throw new ValidatorException(new FacesMessage()); // need a non-null FacesMessage to avoid NPE
+      }
+   }
+
    private static class LocalProducerConfiguration
    {
       private List<RegistrationPropertyDescription> registrationProperties;

Modified: components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource.properties
===================================================================
--- components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource.properties	2011-12-13 11:31:04 UTC (rev 8244)
+++ components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource.properties	2011-12-13 13:54:37 UTC (rev 8245)
@@ -177,6 +177,7 @@
 bean_support_unexpected_error = An unexpected error occured:
 bean_support_cause = Cause:
 CONSUMER_TYPE = Consumer
+REGISTRATION_PROPERTY_TYPE = registration property
 
 # ConsumerBean
 bean_consumer_null_id = No identifier was specified to resolve a consumer from. Please refresh the app and try again.
@@ -221,6 +222,6 @@
 
 org.jboss.portal.object.name.admin.WSRP=WSRP
 
-INVALID_NAME_ERROR=''{0}'' is an invalid {1} name: Cannot be null, empty or contain '/', '.', '\\', '<', '>', '(', ')', '=' or '%5c'
+INVALID_NAME_ERROR=''{0}'' is an invalid {1} name or value: Cannot be null, empty or contain '/', '.', '\\', '<', '>', '(', ')', '=' or '%5c'
 DUPLICATE_ERROR=A {1} named ''{0}'' already exists! 
 unavailable_service = WSRP service is unavailble. Please activate it before using this portlet.

Modified: components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource_fr.properties
===================================================================
--- components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource_fr.properties	2011-12-13 11:31:04 UTC (rev 8244)
+++ components/wsrp/trunk/admin-gui/src/main/webapp/WEB-INF/classes/locale/portlet/Resource_fr.properties	2011-12-13 13:54:37 UTC (rev 8245)
@@ -143,7 +143,7 @@
 consumers_table_reload=Recharger consommateurs
 CONSUMER_TYPE=Consommateur
 DUPLICATE_ERROR=Un {1} nomm\u00e9 ''{0}'' existe d\u00e9j\u00e0!
-INVALID_NAME_ERROR=''{0}'' est un nom invalide pour un {1} : Ne peut pas \u00eatre null, vide ou contenir '/', '.', '\\', '<', '>', '(', ')', '=' ou '%5c'
+INVALID_NAME_ERROR=''{0}'' est un nom ou une valuer invalide pour un {1} \: Ne peut pas u00eatre null, vide ou contenir '/', '.', '\\', '<', '>', '(', ')', '\=' ou '%5c'
 edit_consumer_timeout=Timeout des opŽrations WS:
 edit_consumer_timeout_milliseconds=(millisecondes avant timeout)
 consumers_table_action_import=Importer
@@ -184,4 +184,5 @@
 producer_config_wsdl_v1=Adresse WSDL pour le Producteur WSRP v1:
 producer_config_wsdl_v2=Adresse WSDL pour le Producteur WSRP v2:
 unavailable_service=Le service WSRP n''est pas disponible. Veuillez l''activer avant d'utiliser cette portlet.
-bean_consumer_null_id=Aucun identifiant disponible pour rŽcupŽrer un consommateur. Veuillez rafra”chir l'application et rŽessayer.
\ No newline at end of file
+bean_consumer_null_id=Aucun identifiant disponible pour rŽcupŽrer un consommateur. Veuillez rafra”chir l'application et rŽessayer.
+REGISTRATION_PROPERTY_TYPE=propriu00e9tu00e9 d'enregistrement
\ No newline at end of file

Modified: components/wsrp/trunk/admin-gui/src/main/webapp/jsf/producer/producer.xhtml
===================================================================
--- components/wsrp/trunk/admin-gui/src/main/webapp/jsf/producer/producer.xhtml	2011-12-13 11:31:04 UTC (rev 8244)
+++ components/wsrp/trunk/admin-gui/src/main/webapp/jsf/producer/producer.xhtml	2011-12-13 13:54:37 UTC (rev 8245)
@@ -111,7 +111,8 @@
                                styleClass="UIGrid ConsumerGrid" width="100%">
                      <h:column>
                         <f:facet name="header">#{i18n.producer_config_reg_prop_name}</f:facet>
-                        <h:inputText id="name" value="#{property.nameAsString}" size="21"/>
+                        <h:inputText id="name" value="#{property.nameAsString}" validator="#{producer.validate}"
+                                     size="21"/>
                      </h:column>
                      <h:column>
                         <f:facet name="header">#{i18n.producer_config_reg_prop_type}</f:facet>
@@ -121,11 +122,11 @@
                      </h:column>
                      <h:column>
                         <f:facet name="header">#{i18n.producer_config_reg_prop_label}</f:facet>
-                        <h:inputText id="label" value="#{property.label}" size="21"/>
+                        <h:inputText id="label" value="#{property.label}" validator="#{producer.validate}" size="21"/>
                      </h:column>
                      <h:column>
                         <f:facet name="header">#{i18n.producer_config_reg_prop_hint}</f:facet>
-                        <h:inputText id="hint" value="#{property.hint}" size="21"/>
+                        <h:inputText id="hint" value="#{property.hint}" validator="#{producer.validate}" size="21"/>
                      </h:column>
                      <h:column>
                         <f:facet name="header">#{i18n.producer_config_reg_prop_action}</f:facet>

Modified: components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java
===================================================================
--- components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java	2011-12-13 11:31:04 UTC (rev 8244)
+++ components/wsrp/trunk/common/src/main/java/org/gatein/wsrp/registration/RegistrationPropertyDescription.java	2011-12-13 13:54:37 UTC (rev 8245)
@@ -38,6 +38,14 @@
  */
 public class RegistrationPropertyDescription implements PropertyDescription
 {
+   public static final ParameterValidation.ValidationErrorHandler HANDLER = new ParameterValidation.ValidationErrorHandler(null)
+   {
+      @Override
+      protected String internalValidationErrorHandling(String failedValue)
+      {
+         throw new IllegalArgumentException(failedValue + " is not a valid RegistrationPropertyDescription name");
+      }
+   };
    private String key;
    private QName name;
    private QName type;
@@ -173,7 +181,8 @@
 
    public void setNameAsString(String name)
    {
-      setName(new QName(name));
+      final String sanitizedName = ParameterValidation.sanitizeFromPatternWithHandler(name, ParameterValidation.XSS_CHECK, HANDLER);
+      setName(new QName(sanitizedName));
    }
 
    public String getNameAsString()



More information about the gatein-commits mailing list