myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r698701 - in /myfaces/extensions/validator/trunk: component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/ core/src/main/java/org/apache/myfaces/extensions/validator/core/metad...
Date Wed, 24 Sep 2008 19:43:18 GMT
Author: gpetracek
Date: Wed Sep 24 12:43:17 2008
New Revision: 698701

URL: http://svn.apache.org/viewvc?rev=698701&view=rev
Log:
updated trinidad support (client-side validation)

Added:
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/DoubleRangeInitializer.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LongRangeInitializer.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/PatternInitializer.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/ValidatorInitializer.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/DoubleRangeMetaDataExtractor.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/LongRangeMetaDataExtractor.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/PatternMetaDataExtractor.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/ValidatorMetaDataExtractor.java
Modified:
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/InitTrinidadModulePhaseListener.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LengthInitializer.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/RequiredInitializer.java
    myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/TrinidadComponentInitializer.java
    myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/metadata/MetaDataKeys.java
    myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java

Added: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/DoubleRangeInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/DoubleRangeInitializer.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/DoubleRangeInitializer.java
(added)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/DoubleRangeInitializer.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.component.initializer.trinidad;
+
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.trinidad.validator.DoubleRangeValidator;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class DoubleRangeInitializer extends TrinidadComponentInitializer
+{
+    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
+    {
+        boolean informationAdded = false;
+        DoubleRangeValidator lengthValidator = (DoubleRangeValidator)facesContext.getApplication()
+                                            .createValidator("org.apache.myfaces.trinidad.DoubleRange");
+
+        if(metaData.containsKey(MetaDataKeys.RANGE_MIN))
+        {
+            Object min = metaData.get(MetaDataKeys.RANGE_MIN);
+
+            if(min instanceof Double)
+            {
+                lengthValidator.setMinimum((Double)min);
+                informationAdded = true;
+            }
+        }
+
+        if(metaData.containsKey(MetaDataKeys.RANGE_MAX))
+        {
+            Object maxLength = metaData.get(MetaDataKeys.RANGE_MAX);
+
+            if(maxLength instanceof Double)
+            {
+                lengthValidator.setMaximum((Double)maxLength);
+                informationAdded = true;
+            }
+        }
+        if(informationAdded)
+        {
+            ((EditableValueHolder)uiComponent).addValidator(lengthValidator);
+        }
+    }
+}
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/InitTrinidadModulePhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/InitTrinidadModulePhaseListener.java?rev=698701&r1=698700&r2=698701&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/InitTrinidadModulePhaseListener.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/InitTrinidadModulePhaseListener.java
Wed Sep 24 12:43:17 2008
@@ -19,9 +19,9 @@
 package org.apache.myfaces.extensions.validator.component.initializer.trinidad;
 
 import org.apache.myfaces.extensions.validator.core.AbstractStartupConfigListener;
-import org.apache.myfaces.extensions.validator.util.ExtValUtils;
-import org.apache.myfaces.extensions.validator.internal.ToDo;
 import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.util.ExtValUtils;
 
 /**
  * @author Gerhard Petracek

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LengthInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LengthInitializer.java?rev=698701&r1=698700&r2=698701&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LengthInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LengthInitializer.java
Wed Sep 24 12:43:17 2008
@@ -21,9 +21,9 @@
 import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
 import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 
-import javax.faces.context.FacesContext;
-import javax.faces.component.UIComponent;
 import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
 import javax.faces.validator.LengthValidator;
 import java.util.Map;
 
@@ -35,28 +35,40 @@
 {
     public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
     {
+        boolean informationAdded = false;
         LengthValidator lengthValidator = (LengthValidator)facesContext.getApplication()
                                             .createValidator("org.apache.myfaces.trinidad.Length");
 
         if(metaData.containsKey(MetaDataKeys.MIN_LENGTH))
         {
-            lengthValidator.setMinimum((Integer)metaData.get(MetaDataKeys.MIN_LENGTH));
+            Object min = metaData.get(MetaDataKeys.MIN_LENGTH);
+
+            if(min instanceof Integer)
+            {
+                lengthValidator.setMinimum((Integer)min);
+                informationAdded = true;
+            }
         }
 
         if(metaData.containsKey(MetaDataKeys.MAX_LENGTH))
         {
+            Object maxLength = metaData.get(MetaDataKeys.MAX_LENGTH);
 
-            int maxLength = (Integer)metaData.get(MetaDataKeys.MAX_LENGTH);
-
-            if(processComponent(uiComponent))
+            if(maxLength instanceof Integer)
             {
-                ReflectionUtils
-                    .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(),
"setMaximumLength",
-                        new Object[] {maxLength}, new Class[] {int.class});
+                if(processComponent(uiComponent))
+                {
+                    ReflectionUtils
+                        .tryToInvokeMethodOfClassAndMethodName(uiComponent.getClass().getName(),
"setMaximumLength",
+                            new Object[] {maxLength}, new Class[] {int.class});
+                }
+                lengthValidator.setMaximum((Integer)maxLength);
+                informationAdded = true;
             }
-
-            lengthValidator.setMaximum(maxLength);
         }
-        ((EditableValueHolder)uiComponent).addValidator(lengthValidator);
+        if(informationAdded)
+        {
+            ((EditableValueHolder)uiComponent).addValidator(lengthValidator);
+        }
     }
 }

Added: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LongRangeInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LongRangeInitializer.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LongRangeInitializer.java
(added)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/LongRangeInitializer.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.component.initializer.trinidad;
+
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.trinidad.validator.LongRangeValidator;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class LongRangeInitializer extends TrinidadComponentInitializer
+{
+    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
+    {
+        boolean informationAdded = false;
+        LongRangeValidator lengthValidator = (LongRangeValidator)facesContext.getApplication()
+                                            .createValidator("org.apache.myfaces.trinidad.LongRange");
+
+        if(metaData.containsKey(MetaDataKeys.RANGE_MIN))
+        {
+            Object min = metaData.get(MetaDataKeys.RANGE_MIN);
+
+            if(min instanceof Long)
+            {
+                lengthValidator.setMinimum((Long)min);
+                informationAdded = true;
+            }
+        }
+
+        if(metaData.containsKey(MetaDataKeys.RANGE_MAX))
+        {
+            Object maxLength = metaData.get(MetaDataKeys.RANGE_MAX);
+
+            if(maxLength instanceof Long)
+            {
+                lengthValidator.setMaximum((Long)maxLength);
+                informationAdded = true;
+            }
+        }
+        if(informationAdded)
+        {
+            ((EditableValueHolder)uiComponent).addValidator(lengthValidator);
+        }
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/PatternInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/PatternInitializer.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/PatternInitializer.java
(added)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/PatternInitializer.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.component.initializer.trinidad;
+
+import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.trinidad.validator.RegExpValidator;
+
+import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class PatternInitializer implements ComponentInitializer
+{
+    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
+    {
+        if(!metaData.containsKey(MetaDataKeys.PATTERN))
+        {
+            return;
+        }
+
+        String[] patterns = (String[])metaData.get(MetaDataKeys.PATTERN);
+
+        RegExpValidator regExpValidator;
+
+        for(String pattern : patterns)
+        {
+            regExpValidator = (RegExpValidator)facesContext.getApplication()
+                                                .createValidator("org.apache.myfaces.trinidad.RegExp");
+
+            regExpValidator.setPattern(pattern);
+            regExpValidator.setMessageDetailNoMatch((String)metaData.get(
+                MetaDataKeys.PATTERN_VALIDATION_ERROR_MESSAGE));
+
+            ((EditableValueHolder)uiComponent).addValidator(regExpValidator);
+        }
+    }
+}
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/RequiredInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/RequiredInitializer.java?rev=698701&r1=698700&r2=698701&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/RequiredInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/RequiredInitializer.java
Wed Sep 24 12:43:17 2008
@@ -21,9 +21,9 @@
 import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
 import org.apache.myfaces.extensions.validator.util.ReflectionUtils;
 
-import javax.faces.context.FacesContext;
-import javax.faces.component.UIComponent;
 import javax.faces.component.EditableValueHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
 import java.util.Map;
 
 /**

Modified: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/TrinidadComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/TrinidadComponentInitializer.java?rev=698701&r1=698700&r2=698701&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/TrinidadComponentInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/TrinidadComponentInitializer.java
Wed Sep 24 12:43:17 2008
@@ -22,9 +22,9 @@
 
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
-import java.util.Map;
-import java.util.List;
 import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Gerhard Petracek
@@ -43,6 +43,10 @@
     {
         componentInitializers.add(new RequiredInitializer());
         componentInitializers.add(new LengthInitializer());
+        componentInitializers.add(new LongRangeInitializer());
+        componentInitializers.add(new DoubleRangeInitializer());
+        componentInitializers.add(new PatternInitializer());
+        //componentInitializers.add(new ValidatorInitializer());
     }
 
     public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)

Added: myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/ValidatorInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/ValidatorInitializer.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/ValidatorInitializer.java
(added)
+++ myfaces/extensions/validator/trunk/component-support/trinidad-support/src/main/java/org/apache/myfaces/extensions/validator/component/initializer/trinidad/ValidatorInitializer.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.component.initializer.trinidad;
+
+import org.apache.myfaces.extensions.validator.core.initializer.component.ComponentInitializer;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.extensions.validator.internal.Priority;
+import org.apache.myfaces.extensions.validator.internal.ToDo;
+import org.apache.myfaces.extensions.validator.internal.UsageCategory;
+import org.apache.myfaces.extensions.validator.internal.UsageInformation;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+@UsageInformation(value = UsageCategory.INTERNAL)
+@ToDo(value = Priority.LOW, description = "impl. trinidad e-mail validator")
+public class ValidatorInitializer implements ComponentInitializer
+{
+    public void configureComponent(FacesContext facesContext, UIComponent uiComponent, Map<String,
Object> metaData)
+    {
+        if(!metaData.containsKey(MetaDataKeys.CUSTOM))
+        {
+            return;
+        }
+
+        Object value = metaData.get(MetaDataKeys.CUSTOM);
+
+        if(!(value instanceof List))
+        {
+            return;
+        }
+
+        for(Object currentValue : (List)value)
+        {
+            if(!(currentValue instanceof String))
+            {
+                continue;
+            }
+
+            if(MetaDataKeys.EMAIL.equals(currentValue))
+            {
+                //TODO
+            }
+        }
+    }
+}
\ No newline at end of file

Modified: myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/metadata/MetaDataKeys.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/metadata/MetaDataKeys.java?rev=698701&r1=698700&r2=698701&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/metadata/MetaDataKeys.java
(original)
+++ myfaces/extensions/validator/trunk/core/src/main/java/org/apache/myfaces/extensions/validator/core/metadata/MetaDataKeys.java
Wed Sep 24 12:43:17 2008
@@ -19,6 +19,8 @@
 package org.apache.myfaces.extensions.validator.core.metadata;
 
 /**
+ * helper for frequent meta-data keys
+ *
  * @author Gerhard Petracek
  * @since 1.x.1
  */
@@ -31,4 +33,13 @@
 
     static final String MIN_LENGTH = "min_length";
     static final String MAX_LENGTH = "max_length";
+
+    static final String RANGE_MIN = "range_min";
+    static final String RANGE_MAX = "range_max";
+
+    static final String PATTERN = "pattern";
+    static final String PATTERN_VALIDATION_ERROR_MESSAGE = "pattern_validation_error_message";
+    static final String EMAIL = "email";
+
+    static final String CUSTOM = "custom";
 }

Modified: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java?rev=698701&r1=698700&r2=698701&view=diff
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
(original)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/HtmlCoreComponentsComponentInitializer.java
Wed Sep 24 12:43:17 2008
@@ -76,12 +76,16 @@
     {
         if(metaData.containsKey(MetaDataKeys.MAX_LENGTH))
         {
-            int maxLength = (Integer)metaData.get(MetaDataKeys.MAX_LENGTH);
+            Object maxLength = metaData.get(MetaDataKeys.MAX_LENGTH);
 
+            if(!(maxLength instanceof Integer))
+            {
+                return;
+            }
             if(uiComponent instanceof HtmlInputText)
             {
                 HtmlInputText htmlInputText = (HtmlInputText)uiComponent;
-                htmlInputText.setMaxlength(maxLength);
+                htmlInputText.setMaxlength((Integer)maxLength);
             }
         }
     }

Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/DoubleRangeMetaDataExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/DoubleRangeMetaDataExtractor.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/DoubleRangeMetaDataExtractor.java
(added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/DoubleRangeMetaDataExtractor.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.baseval.metadata.extractor;
+
+import org.apache.myfaces.extensions.validator.baseval.annotation.DoubleRange;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class DoubleRangeMetaDataExtractor implements MetaDataExtractor
+{
+    public Map<String, Object> extractMetaData(Annotation annotation)
+    {
+        Map<String, Object> results = new HashMap<String, Object>();
+        double minimum = ((DoubleRange)annotation).minimum();
+
+        results.put(MetaDataKeys.RANGE_MIN, minimum);
+        results.put(MetaDataKeys.RANGE_MAX, ((DoubleRange)annotation).maximum());
+
+        if(minimum > 0)
+        {
+            results.put(MetaDataKeys.REQUIRED, true);
+        }
+
+        return results;
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/LongRangeMetaDataExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/LongRangeMetaDataExtractor.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/LongRangeMetaDataExtractor.java
(added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/LongRangeMetaDataExtractor.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.baseval.metadata.extractor;
+
+import org.apache.myfaces.extensions.validator.baseval.annotation.Length;
+import org.apache.myfaces.extensions.validator.baseval.annotation.LongRange;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class LongRangeMetaDataExtractor implements MetaDataExtractor
+{
+    public Map<String, Object> extractMetaData(Annotation annotation)
+    {
+        Map<String, Object> results = new HashMap<String, Object>();
+        long minimum = ((LongRange)annotation).minimum();
+
+        results.put(MetaDataKeys.RANGE_MIN, minimum);
+        results.put(MetaDataKeys.RANGE_MAX, ((LongRange)annotation).maximum());
+
+        if(minimum > 0)
+        {
+            results.put(MetaDataKeys.REQUIRED, true);
+        }
+
+        return results;
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/PatternMetaDataExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/PatternMetaDataExtractor.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/PatternMetaDataExtractor.java
(added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/PatternMetaDataExtractor.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.baseval.metadata.extractor;
+
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
+import org.apache.myfaces.extensions.validator.core.validation.strategy.ValidationStrategy;
+import org.apache.myfaces.extensions.validator.baseval.annotation.Pattern;
+import org.apache.myfaces.extensions.validator.util.FactoryUtils;
+
+import javax.faces.context.FacesContext;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Locale;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class PatternMetaDataExtractor implements MetaDataExtractor
+{
+    public Map<String, Object> extractMetaData(Annotation annotation)
+    {
+        Map<String, Object> results = new HashMap<String, Object>();
+        results.put(MetaDataKeys.PATTERN, ((Pattern)annotation).value());
+
+        String validationErrorMsgKey = ((Pattern)annotation).validationErrorMsgKey();
+        Locale currentLocale = FacesContext.getCurrentInstance().getViewRoot().getLocale();
+
+        ValidationStrategy validationStrategy = FactoryUtils.getValidationStrategyFactory().create(annotation);
+
+        String validationErrorMsg = FactoryUtils.getMessageResolverFactory()
+                                        .create(validationStrategy).getMessage(validationErrorMsgKey,
currentLocale);
+        results.put(MetaDataKeys.PATTERN_VALIDATION_ERROR_MESSAGE, validationErrorMsg);
+        return results;
+    }
+}
\ No newline at end of file

Added: myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/ValidatorMetaDataExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/ValidatorMetaDataExtractor.java?rev=698701&view=auto
==============================================================================
--- myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/ValidatorMetaDataExtractor.java
(added)
+++ myfaces/extensions/validator/trunk/validation-modules/property-validation/src/main/java/org/apache/myfaces/extensions/validator/baseval/metadata/extractor/ValidatorMetaDataExtractor.java
Wed Sep 24 12:43:17 2008
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.extensions.validator.baseval.metadata.extractor;
+
+import org.apache.myfaces.extensions.validator.baseval.annotation.DoubleRange;
+import org.apache.myfaces.extensions.validator.baseval.annotation.Validator;
+import org.apache.myfaces.extensions.validator.core.metadata.MetaDataKeys;
+import org.apache.myfaces.extensions.validator.core.metadata.extractor.MetaDataExtractor;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Gerhard Petracek
+ * @since 1.x.1
+ */
+public class ValidatorMetaDataExtractor implements MetaDataExtractor
+{
+    public Map<String, Object> extractMetaData(Annotation annotation)
+    {
+        Map<String, Object> results = new HashMap<String, Object>();
+        Class[] validators = ((Validator)annotation).value();
+
+        List<String> value = new ArrayList<String>();
+
+        for(Class currentClass : validators)
+        {
+            if(currentClass.getSimpleName().toLowerCase().contains(MetaDataKeys.EMAIL))
+            {
+                value.add(MetaDataKeys.EMAIL);
+            }
+            value.add(currentClass.getName());
+        }
+
+        results.put(MetaDataKeys.CUSTOM, value);
+
+        return results;
+    }
+}
\ No newline at end of file



Mime
View raw message