svn commit: r1648461 - in /portals/jetspeed-2/applications/j2-admin/trunk: pom.xml src/main/java/org/apache/jetspeed/portlets/security/constraints/ValidationSupport.java src/main/webapp/WEB-INF/model/validator-configuration.xml

[email protected]
Newsgroups gmane.comp.jakarta.jetspeed.devel
Message-ID <[email protected]>
Author: taylor
Date: Tue Dec 30 01:27:05 2014
New Revision: 1648461

URL: http://svn.apache.org/r1648461
Log:
JS2-1306: updating dependencies for Velocity 1.7

Added:
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ValidationSupport.java
Modified:
    portals/jetspeed-2/applications/j2-admin/trunk/pom.xml
    portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/model/validator-configuration.xml

Modified: portals/jetspeed-2/applications/j2-admin/trunk/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/pom.xml?rev=1648461&r1=1648460&r2=1648461&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/pom.xml (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/pom.xml Tue Dec 30 01:27:05 2014
@@ -32,10 +32,8 @@
   <properties>
     <!-- Project Dependency Version Properties -->
     <jetspeed-2.version>2.3.0-SNAPSHOT</jetspeed-2.version>
-    <org.apache.portals.bridges.common.version>2.0</org.apache.portals.bridges.common.version>
-    <org.apache.portals.bridges.velocity.version>2.0</org.apache.portals.bridges.velocity.version>
-    <org.apache.portals.bridges.frameworks.version>1.0.4</org.apache.portals.bridges.frameworks.version>
-    <org.apache.portals.bridges.portletfilter.version>1.0.4</org.apache.portals.bridges.portletfilter.version>
+    <org.apache.portals.bridges.common.version>2.1-SNAPSHOT</org.apache.portals.bridges.common.version>
+    <org.apache.portals.bridges.velocity.version>2.1-SNAPSHOT</org.apache.portals.bridges.velocity.version>
     <org.apache.portals.applications.apa-gems.version>1.2-SNAPSHOT</org.apache.portals.applications.apa-gems.version>
     <org.apache.portals.applications.apa-webcontent2.version>2.0-SNAPSHOT</org.apache.portals.applications.apa-webcontent2.version>
     <commons-digester.version>2.1</commons-digester.version>
@@ -44,11 +42,12 @@
     <commons-fileupload.version>1.3.1</commons-fileupload.version>
     <commons-io.version>2.4</commons-io.version>
     <commons-beanutils.version>1.9.2</commons-beanutils.version>
+    <commons-validator.version>1.3.1</commons-validator.version>
     <commons-codec.version>1.6</commons-codec.version>
     <slf4j.version>1.5.6</slf4j.version>
     <javax.servlet.jstl.version>1.1.2</javax.servlet.jstl.version>
-    <javax.servlet.version>2.4</javax.servlet.version>
-    <javax.servlet.jsp.version>2.0</javax.servlet.jsp.version>
+    <javax.servlet.version>3.0.1</javax.servlet.version>
+    <javax.servlet.jsp.version>2.2.1</javax.servlet.jsp.version>
     <log4j.version>1.2.17</log4j.version>
     <portals.portlet2-api-spec.version>1.0</portals.portlet2-api-spec.version>
     <org.apache.pluto.version>2.0.3</org.apache.pluto.version>
@@ -57,7 +56,7 @@
     <taglibs-request.version>1.0.1</taglibs-request.version>
     <taglibs-standard.version>1.1.2</taglibs-standard.version>
     <velocity-tools.version>1.3</velocity-tools.version>
-    <velocity.version>1.6.3</velocity.version>
+    <velocity.version>1.7</velocity.version>
     <xerces.version>2.8.1</xerces.version>
     <wicket.version>1.4.17</wicket.version>
   </properties>
@@ -75,13 +74,13 @@
     </dependency>
     <dependency>
       <groupId>javax.servlet</groupId>
-      <artifactId>servlet-api</artifactId>
+      <artifactId>javax.servlet-api</artifactId>
       <version>${javax.servlet.version}</version>
       <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>javax.servlet.jsp</groupId>
-      <artifactId>jsp-api</artifactId>
+      <artifactId>javax.servlet.jsp-api</artifactId>
       <version>${javax.servlet.jsp.version}</version>
       <scope>provided</scope>
     </dependency>
@@ -143,6 +142,10 @@
       <scope>runtime</scope>
       <exclusions>
         <exclusion>
+          <groupId>javax.servlet</groupId>
+          <artifactId>servlet-api</artifactId>
+        </exclusion>
+        <exclusion>
           <groupId>commons-logging</groupId>
           <artifactId>commons-logging</artifactId>
         </exclusion>
@@ -182,32 +185,6 @@
       </exclusions>
     </dependency>
     <dependency>
-      <groupId>org.apache.portals.bridges</groupId>
-      <artifactId>portals-bridges-frameworks</artifactId>
-      <version>${org.apache.portals.bridges.frameworks.version}</version>
-      <exclusions>
-        <exclusion>
-          <groupId>velocity</groupId>
-          <artifactId>velocity</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>velocity-tools</groupId>
-          <artifactId>velocity-tools</artifactId>
-        </exclusion>
-      </exclusions>      
-    </dependency>
-    <dependency>
-      <groupId>org.apache.portals.bridges</groupId>
-      <artifactId>portals-bridges-portletfilter</artifactId>
-      <version>${org.apache.portals.bridges.portletfilter.version}</version>
-      <exclusions>
-        <exclusion>
-          <groupId>commons-logging</groupId>
-          <artifactId>commons-logging</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>${commons-io.version}</version>
@@ -406,7 +383,12 @@
       <artifactId>apa-webcontent2-portlets</artifactId>
       <version>${org.apache.portals.applications.apa-webcontent2.version}</version>
     </dependency>
-	
+    <dependency>
+      <groupId>commons-validator</groupId>
+      <artifactId>commons-validator</artifactId>
+      <version>${commons-validator.version}</version>
+    </dependency>
+
 	<!-- test dependencies -->
 	<dependency>
 		<groupId>junit</groupId>

Added: portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ValidationSupport.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ValidationSupport.java?rev=1648461&view=auto
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ValidationSupport.java (added)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/java/org/apache/jetspeed/portlets/security/constraints/ValidationSupport.java Tue Dec 30 01:27:05 2014
@@ -0,0 +1,404 @@
+/*
+ * 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.jetspeed.portlets.security.constraints;
+
+import org.apache.commons.beanutils.DynaBean;
+import org.apache.commons.beanutils.PropertyUtils;
+import org.apache.commons.validator.Arg;
+import org.apache.commons.validator.Field;
+import org.apache.commons.validator.Form;
+import org.apache.commons.validator.GenericTypeValidator;
+import org.apache.commons.validator.GenericValidator;
+import org.apache.commons.validator.ValidatorAction;
+import org.apache.commons.validator.ValidatorResources;
+import org.apache.commons.validator.ValidatorResult;
+import org.apache.commons.validator.ValidatorResults;
+
+import java.lang.reflect.InvocationTargetException;
+import java.text.MessageFormat;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+/**
+ * ValidationSupport
+ * 
+ * @author <a href="mailto:[email protected]">David Sean Taylor </a>
+ * @version $Id: ValidationSupport.java 517068 2007-03-12 01:44:37Z ate $
+ */
+public class ValidationSupport
+{
+
+    public static String getValueAsString(Object bean, String property)
+    {
+        Object value = null;
+
+        if (bean instanceof Map)
+        {
+            value = ((Map) bean).get(property);
+        }
+        else if (bean instanceof DynaBean)
+        {
+            value = ((DynaBean) bean).get(property);
+        }
+        else
+        {
+            try
+            {
+                value = PropertyUtils.getProperty(bean, property);
+
+            }
+            catch (IllegalAccessException e)
+            {
+                //log.error(e.getMessage(), e);
+            }
+            catch (InvocationTargetException e)
+            {
+                //log.error(e.getMessage(), e);
+            }
+            catch (NoSuchMethodException e)
+            {
+                //log.error(e.getMessage(), e);
+            }
+        }
+
+        if (value == null) { return null; }
+
+        if (value instanceof String[])
+        {
+            return ((String[]) value).length > 0 ? value.toString() : "";
+
+        }
+        else if (value instanceof Collection)
+        {
+            return ((Collection) value).isEmpty() ? "" : value.toString();
+
+        }
+        else
+        {
+            return value.toString();
+        }
+    }
+
+    /**
+     * Checks if the field is required.
+     * 
+     * @return boolean If the field isn't <code>null</code> and has a length
+     *         greater than zero, <code>true</code> is returned. Otherwise
+     *         <code>false</code>.
+     */
+    public static boolean validateRequired(Object bean, ValidatorAction va, Field field, Map errors,
+            ResourceBundle bundle)
+    {
+        String value = getValueAsString(bean, field.getProperty());
+        boolean valid = !GenericValidator.isBlankOrNull(value);
+        if (!valid)
+        {
+            if (bundle == null)
+            {
+                errors.put(field.getKey(), "Field " + field.getKey() + " is a required field.");
+            }
+            else
+            {
+                String displayName = bundle.getString(field.getArg(0).getKey());
+                if (displayName == null)
+                {
+                    displayName = field.getKey();
+                }
+                Object[] args =
+                { displayName};
+
+                String message = bundle.getString(va.getMsg());
+                if (message == null)
+                {
+                    message = "Field {0} is a required field.";
+                }
+                errors.put(field.getKey(), MessageFormat.format(message, args));
+            }
+        }
+        return valid;
+    }
+
+    public static boolean validateRange(Object bean, ValidatorAction va, Field field, Map errors, ResourceBundle bundle) 
+    {        
+        int value = 0;
+        String result = getValueAsString(bean, field.getProperty());
+        if (result != null)
+        {
+            Integer intValue = GenericTypeValidator.formatInt(result);
+            if (intValue != null)
+            {    
+                value = intValue.intValue();
+            }
+        }
+        
+       String minResult = field.getVarValue("min");
+       if (minResult == null)
+       {
+           minResult = "0";
+       }
+       String maxResult = field.getVarValue("max");
+       if (maxResult == null)
+       {
+           maxResult = "0";
+       }
+       int min = GenericTypeValidator.formatInt(minResult).intValue();
+       int max = GenericTypeValidator.formatInt(maxResult).intValue();
+       
+       boolean valid = GenericValidator.isInRange(value, min, max);
+       if (!valid)
+       {
+           if (bundle == null)
+           {
+               errors.put(field.getKey(), "Field " + field.getKey() + " is out of range: [" + min + "- " + max + "]");
+           }
+           else
+           {
+               String displayName = bundle.getString(field.getArg(0).getKey());
+               if (displayName == null)
+               {
+                   displayName = field.getKey();
+               }
+               Object[] args =
+               { displayName, minResult, maxResult};
+
+               String message = bundle.getString(va.getMsg());
+               if (message == null)
+               {
+                   message = "Field {0} is out of range: [{1} - {2}]";
+               }
+               errors.put(field.getKey(), MessageFormat.format(message, args));
+           }
+       }
+       return valid;
+    }   
+
+    public static boolean validateDoubleRange(Object bean, ValidatorAction va, Field field, Map errors, ResourceBundle bundle)
+    {
+        double value = 0;
+        String result = getValueAsString(bean, field.getProperty());
+        if (result != null)
+        {
+            Double doubleValue = GenericTypeValidator.formatDouble(result);
+            if (doubleValue != null)
+            {    
+                value = doubleValue.doubleValue();
+            }
+        }
+        String minResult = field.getVarValue("min");
+        if (minResult == null)
+        {
+            minResult = "0";
+        }
+        String maxResult = field.getVarValue("max");
+        if (maxResult == null)
+        {
+            maxResult = "0";
+        }
+
+        double min = GenericTypeValidator.formatDouble(minResult).doubleValue();
+        double max = GenericTypeValidator.formatDouble(maxResult).doubleValue();
+        boolean valid = GenericValidator.isInRange(value, min, max);
+        if (!valid)
+        {
+            if (bundle == null)
+            {
+                errors.put(field.getKey(), "Field " + field.getKey() + " is out of range: [" + min + "- " + max + "]");
+            }
+            else
+            {
+                String displayName = bundle.getString(field.getArg(0).getKey());
+                if (displayName == null)
+                {
+                    displayName = field.getKey();
+                }
+                Object[] args =
+                { displayName, minResult, maxResult};
+
+                String message = bundle.getString(va.getMsg());
+                if (message == null)
+                {
+                    message = "Field {0} is out of range: [{1} - {2}]";
+                }
+                errors.put(field.getKey(), MessageFormat.format(message, args));
+            }
+        }
+        return valid;
+    }
+
+    public static boolean validateMask(Object bean, ValidatorAction va, Field field, Map errors, ResourceBundle bundle)
+    {
+        String value = getValueAsString(bean, field.getProperty());
+        
+        String mask = field.getVarValue("mask");
+        if (mask == null)
+        {
+            return true; // no mask provide, let it pass
+        }
+
+        if (GenericValidator.isBlankOrNull(value))
+        {
+            return true; // this is how struts handles it
+        }
+        
+        boolean valid = GenericValidator.matchRegexp(value, mask);
+        if (!valid)
+        {
+            if (bundle == null)
+            {
+                errors.put(field.getKey(), "Field " + field.getKey() + " failed to match validation pattern: " +  mask);
+            }
+            else
+            {
+                String displayName = bundle.getString(field.getArg(0).getKey());
+                if (displayName == null)
+                {
+                    displayName = field.getKey();
+                }
+                Object[] args =
+                { displayName, mask};
+
+                String message = bundle.getString(va.getMsg());
+                if (message == null)
+                {
+                    message = "Field {0} failed to match validation pattern: {2}";
+                }
+                errors.put(field.getKey(), MessageFormat.format(message, args));
+            }
+        }        
+        return valid;
+    }
+
+    public static boolean validateMaxLength(Object bean, ValidatorAction va, Field field, Map errors, ResourceBundle bundle)
+    {
+        String value = getValueAsString(bean, field.getProperty());
+        
+        int max = Integer.parseInt(field.getVarValue("maxlength"));
+
+        if (GenericValidator.isBlankOrNull(value))
+        {
+            return true; 
+        }
+        
+        boolean valid = GenericValidator.maxLength(value, max);        
+        if (!valid)
+        {
+            if (bundle == null)
+            {
+                errors.put(field.getKey(), "Field " + field.getKey() + " surpasses maximum length: " +  max);
+            }
+            else
+            {
+                String displayName = bundle.getString(field.getArg(0).getKey());
+                if (displayName == null)
+                {
+                    displayName = field.getKey();
+                }
+                Object[] args =
+                { displayName, new Integer(max)};
+
+                String message = bundle.getString(va.getMsg());
+                if (message == null)
+                {
+                    message = "Field {0} surpasses maximum length {1}";                    
+                }
+                errors.put(field.getKey(), MessageFormat.format(message, args));
+            }
+        }        
+        return valid;
+    }
+    
+    public static void printResults(Object bean, ValidatorResults results, ValidatorResources resources, String formName)
+    {
+
+        boolean success = true;
+
+        // Start by getting the form for the current locale and Bean.
+        Form form = resources.getForm(Locale.getDefault(), formName);
+
+        System.out.println("\n\nValidating:");
+        System.out.println(bean);
+
+        // Iterate over each of the properties of the Bean which had messages.
+        Iterator propertyNames = results.getPropertyNames().iterator();
+        while (propertyNames.hasNext())
+        {
+            String propertyName = (String) propertyNames.next();
+
+            // Get the Field associated with that property in the Form
+            Field field = form.getField(propertyName);
+
+            // Look up the formatted name of the field from the Field arg0
+            String prettyFieldName = propertyName; //apps.getString(field.getArg(0).getKey());
+
+            // Get the result of validating the property.
+            ValidatorResult result = results.getValidatorResult(propertyName);
+
+            // Get all the actions run against the property, and iterate over
+            // their names.
+            Map actionMap = result.getActionMap();
+            Iterator keys = actionMap.keySet().iterator();
+            while (keys.hasNext())
+            {
+                String actName = (String) keys.next();
+
+                // Get the Action for that name.
+                ValidatorAction action = resources.getValidatorAction(actName);
+
+                // If the result is valid, print PASSED, otherwise print FAILED
+                System.out.println(propertyName + "[" + actName + "] ("
+                        + (result.isValid(actName) ? "PASSED" : "FAILED") + ")");
+
+                //If the result failed, format the Action's message against the
+                // formatted field name
+                if (!result.isValid(actName))
+                {
+                    success = false;
+                    String message = "invalid field"; // apps.getString(action.getMsg());
+                    if (actName.equals("doubleRange"))
+                    {
+                        Arg f1 = field.getArg(1);
+                        Arg f2 = field.getArg(2);
+                        Arg f0 = field.getArg(0);
+                        Object[] args =
+                        { prettyFieldName, field.getVar("min").getValue(), field.getVar("max").getValue()};
+                        System.out.println("     Error message will be: " + MessageFormat.format(message, args));
+                    }
+                    else
+                    {
+                        Object[] args =
+                        { prettyFieldName};
+                        System.out.println("     Error message will be: " + MessageFormat.format(message, args));
+                    }
+
+                }
+            }
+        }
+        if (success)
+        {
+            System.out.println("FORM VALIDATION PASSED");
+        }
+        else
+        {
+            System.out.println("FORM VALIDATION FAILED");
+        }
+
+    }
+
+}
\ No newline at end of file

Modified: portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/model/validator-configuration.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/model/validator-configuration.xml?rev=1648461&r1=1648460&r2=1648461&view=diff
==============================================================================
--- portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/model/validator-configuration.xml (original)
+++ portals/jetspeed-2/applications/j2-admin/trunk/src/main/webapp/WEB-INF/model/validator-configuration.xml Tue Dec 30 01:27:05 2014
@@ -22,27 +22,27 @@
 <form-validation>
    <global>
       <validator name="required"
-                 classname="org.apache.portals.bridges.frameworks.spring.validation.ValidationSupport"
+                 classname="org.apache.jetspeed.portlets.security.constraints.ValidationSupport"
                  method="validateRequired"
                  methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,java.util.Map,java.util.ResourceBundle"
                  msg="errors.required"/>
       <validator name="range"
-                 classname="org.apache.portals.bridges.frameworks.spring.validation.ValidationSupport"
+                 classname="org.apache.jetspeed.portlets.security.constraints.ValidationSupport"
                  method="validateRange"
                  methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,java.util.Map,java.util.ResourceBundle"
                  msg="errors.range"/>
       <validator name="doubleRange"
-                 classname="org.apache.portals.bridges.frameworks.spring.validation.ValidationSupport"
+                 classname="org.apache.jetspeed.portlets.security.constraints.ValidationSupport"
                  method="validateDoubleRange"
                  methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,java.util.Map,java.util.ResourceBundle"
                  msg="errors.range"/>
       <validator name="mask"
-                 classname="org.apache.portals.bridges.frameworks.spring.validation.ValidationSupport"
+                 classname="org.apache.jetspeed.portlets.security.constraints.ValidationSupport"
                  method="validateMask"
                  methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,java.util.Map,java.util.ResourceBundle"
                  msg="errors.mask"/>
       <validator name="maxLength"
-                 classname="org.apache.portals.bridges.frameworks.spring.validation.ValidationSupport"
+                 classname="org.apache.jetspeed.portlets.security.constraints.ValidationSupport"
                  method="validateMaxLength"
                  methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction,org.apache.commons.validator.Field,java.util.Map,java.util.ResourceBundle"
                  msg="errors.maxlength"/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.