[portal-commits] JBoss Portal SVN: r12981 - in branches/JBoss_Portal_AS5_Deployer/faces: src/main and 4 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Fri Mar 6 18:22:15 EST 2009


Author: mwringe
Date: 2009-03-06 18:22:14 -0500 (Fri, 06 Mar 2009)
New Revision: 12981

Added:
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/ManagedBeanTestCase.java
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/MessageFormatTestCase.java
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/JSFFunctorTestCase.java
Removed:
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/JSFFunctorTestCase.java
Modified:
   branches/JBoss_Portal_AS5_Deployer/faces/.classpath
   branches/JBoss_Portal_AS5_Deployer/faces/build.xml
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
   branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/ManagedBean.java
Log:
Merge JBoss_Portal_Branch_2_7 changes (rev range 12254:12964) into JBoss_Portal_AS5_Deployer branch

Modified: branches/JBoss_Portal_AS5_Deployer/faces/.classpath
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/.classpath	2009-03-06 23:22:10 UTC (rev 12980)
+++ branches/JBoss_Portal_AS5_Deployer/faces/.classpath	2009-03-06 23:22:14 UTC (rev 12981)
@@ -15,8 +15,7 @@
 	<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/portlet/lib/portal-portlet-bridge-lib.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/portlet/lib/portal-portlet-lib.jar" sourcepath="/module-portlet-trunk"/>
 	<classpathentry kind="lib" path="/thirdparty/portlet/lib/portlet-api.jar"/>
-	<classpathentry kind="lib" path="/thirdparty/sun-jsf/lib/jsf-api.jar"/>
-	<classpathentry kind="lib" path="/thirdparty/sun-jsf/lib/jsf-impl.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/web/lib/jsp-api.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/glassfish/jsf/lib/jsf-api.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: branches/JBoss_Portal_AS5_Deployer/faces/build.xml
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/build.xml	2009-03-06 23:22:10 UTC (rev 12980)
+++ branches/JBoss_Portal_AS5_Deployer/faces/build.xml	2009-03-06 23:22:14 UTC (rev 12981)
@@ -92,8 +92,8 @@
          <path refid="jboss.portal/modules/common.classpath"/>
          <path refid="jboss.portal/modules/portlet.classpath"/>
          <path refid="sun.servlet.classpath"/>
-         <path refid="sun.jsf.classpath"/>
-         <path refid="sun.jstl.classpath"/>
+         <path refid="glassfish.jsf.classpath"/>
+         <path refid="glassfish.jstl.classpath"/>
          <path refid="facelets.facelets.classpath"/>
          <path refid="el.el.classpath"/>
          <path refid="apache.log4j.classpath"/>

Modified: branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java	2009-03-06 23:22:10 UTC (rev 12980)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/BeanContext.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2007, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2009, 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.                                                   *
@@ -52,6 +52,11 @@
     */
    public abstract String getParameter(String key);
 
+   /**
+    * @param target
+    * @param message
+    * @param severity
+    */
    protected abstract void createMessage(String target, String message, Object severity);
 
    protected abstract Object getErrorSeverity();
@@ -60,24 +65,33 @@
 
    protected abstract Locale getLocale();
 
-   public void createErrorMessage(String message, Object... params)
+   public void createErrorMessage(String localizedMessageId, Object... params)
    {
-      createLocalizedMessage(STATUS, message, getErrorSeverity(), params);
+      createLocalizedMessage(STATUS, localizedMessageId, getErrorSeverity(), params);
    }
 
-   protected void createErrorMessage(String target, String message, Object... params)
+   public void createTargetedErrorMessage(String target, String localizedMessageId, Object... params)
    {
-      createLocalizedMessage(target, message, getErrorSeverity(), params);
+      createLocalizedMessage(target, localizedMessageId, getErrorSeverity(), params);
    }
 
-   protected void createLocalizedMessage(String target, String message, Object severity, Object... params)
+   /**
+    * Adds a localized message using the appropriate severity to the identified target in the context. This method
+    * accepts an arbitrary number of arguments to be passed as parameters of localized strings.
+    *
+    * @param target             the target in this context that will receive the new message
+    * @param localizedMessageId a resource bundle identifier identifying which the localized string to use as a message
+    * @param severity           an object representing the severity of the message (typically FacesMessage.Severity)
+    * @param params             additional parameters to be passed to replace tokens in localized strings
+    */
+   protected void createLocalizedMessage(String target, String localizedMessageId, Object severity, Object... params)
    {
-      createMessage(target, getMessageFromBundle(message, params), severity);
+      createMessage(target, getMessageFromBundle(localizedMessageId, params), severity);
    }
 
-   public String getMessageFromBundle(String message, Object... params)
+   public String getMessageFromBundle(String localizedMessageId, Object... params)
    {
-      return getLocalizedMessage(message, getLocale(), params);
+      return getLocalizedMessage(localizedMessageId, getLocale(), params);
    }
 
    public static String getLocalizedMessage(String localizationKey, Locale locale, Object... params)
@@ -91,6 +105,17 @@
       createErrorMessageFrom(STATUS, e);
    }
 
+   /**
+    * Creates a localized error message targeting the specified object in the context and using the specified error
+    * information. This method looks for two specific resource bundle entries to localize the message, {@link
+    * #UNEXPECTED_ERROR} and {@link #CAUSE}, using the following format for the message: <code>result of {@link
+    * #getLocalizedMessageOrExceptionName(Throwable)} for the exception\n[localized value associated with {@link
+    * #CAUSE}result of {@link #getLocalizedMessageOrExceptionName(Throwable)} for the exception's cause if the cause
+    * exists]
+    *
+    * @param target the contextual object target by the message to be created
+    * @param e      the exception that we want to display as an error message
+    */
    public void createErrorMessageFrom(String target, Exception e)
    {
       Throwable cause = e.getCause();
@@ -99,6 +124,14 @@
       createMessage(target, message, getErrorSeverity());
    }
 
+   /**
+    * Retrieves a localized message associated with the specified Throwable.
+    *
+    * @param e the Throwable for which a localized message is to be retrieved
+    * @return the localized message associated with the specified Throwable if it exists or the localized value
+    *         associated with the {@link #UNEXPECTED_ERROR} resource bundle entry to which is appended the Throwable
+    *         class name.
+    */
    private String getLocalizedMessageOrExceptionName(Throwable e)
    {
       String localizedMessage = e.getLocalizedMessage();
@@ -109,14 +142,14 @@
       return localizedMessage;
    }
 
-   protected void createInfoMessage(String target, String message)
+   protected void createInfoMessage(String target, String localizedMessageId)
    {
-      createLocalizedMessage(target, message, getInfoSeverity());
+      createLocalizedMessage(target, localizedMessageId, getInfoSeverity());
    }
 
-   public void createInfoMessage(String message)
+   public void createInfoMessage(String localizedMessageId)
    {
-      createInfoMessage(STATUS, message);
+      createInfoMessage(STATUS, localizedMessageId);
    }
 
    /**
@@ -174,7 +207,7 @@
       }
 
       getFromSession(name, newValue.getClass(), sessionMap, "Provided object: " + newValue
-              + " is not compatible with previously assigned '" + name + "' object: " + CURRENT_PLACEHOLDER);
+         + " is not compatible with previously assigned '" + name + "' object: " + CURRENT_PLACEHOLDER);
       sessionMap.put(name, newValue);
       return newValue;
    }
@@ -192,7 +225,7 @@
    public <T> T getFromSession(String name, Class<T> expectedClass)
    {
       return getFromSession(name, expectedClass, getSessionMap(), "Current object:" + CURRENT_PLACEHOLDER
-              + " is not compatible with expected class " + expectedClass + " for '" + name + "'");
+         + " is not compatible with expected class " + expectedClass + " for '" + name + "'");
    }
 
    /**

Modified: branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java	2009-03-06 23:22:10 UTC (rev 12980)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/JSFBeanContext.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2007, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2009, 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.                                                   *
@@ -23,7 +23,11 @@
 
 package org.jboss.portal.faces.gui;
 
+import org.jboss.portal.common.util.ParameterValidation;
+
 import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIViewRoot;
 import javax.faces.context.FacesContext;
 import java.util.Locale;
 import java.util.Map;
@@ -37,17 +41,32 @@
 {
    public String getParameter(String key)
    {
-      Map pmap = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
+      return getParameter(key, FacesContext.getCurrentInstance());
+   }
+
+   public static String getParameter(String key, FacesContext facesContext)
+   {
+      Map pmap = facesContext.getExternalContext().getRequestParameterMap();
       return (String)pmap.get(key);
    }
 
    public Map<String, Object> getSessionMap()
    {
-      return FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
+      return JSFBeanContext.getSessionMap(FacesContext.getCurrentInstance());
    }
 
+   public static Map<String, Object> getSessionMap(FacesContext facesContext)
+   {
+      return facesContext.getExternalContext().getSessionMap();
+   }
+
    protected void createMessage(String target, String message, Object severity)
    {
+      if (ParameterValidation.isNullOrEmpty(target))
+      {
+         target = STATUS;
+      }
+
       FacesMessage.Severity jsfSeverity;
       if (severity instanceof FacesMessage.Severity)
       {
@@ -58,8 +77,22 @@
          jsfSeverity = FacesMessage.SEVERITY_ERROR;
       }
 
+      // Get the component id from the target
+      FacesContext facesContext = FacesContext.getCurrentInstance();
+      UIViewRoot viewRoot = facesContext.getViewRoot();
+      UIComponent component = viewRoot.findComponent(target);
+      if (component != null)
+      {
+         target = component.getClientId(facesContext);
+      }
+      else
+      {
+         // todo: do something better here
+         System.out.println("Couldn't resolve component target: " + target);
+      }
+
       FacesMessage msg = new FacesMessage(jsfSeverity, message, message);
-      FacesContext.getCurrentInstance().addMessage(target, msg);
+      facesContext.addMessage(target, msg);
    }
 
    protected Object getErrorSeverity()

Modified: branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/ManagedBean.java
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/ManagedBean.java	2009-03-06 23:22:10 UTC (rev 12980)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/gui/ManagedBean.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -1,6 +1,6 @@
 /******************************************************************************
  * JBoss, a division of Red Hat                                               *
- * Copyright 2007, Red Hat Middleware, LLC, and individual                    *
+ * Copyright 2009, 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.                                                   *
@@ -24,6 +24,7 @@
 package org.jboss.portal.faces.gui;
 
 import org.apache.log4j.Logger;
+import org.jboss.portal.common.util.ParameterValidation;
 
 
 /**
@@ -31,14 +32,118 @@
  * @version $Revision$
  * @since 2.6
  */
-public class ManagedBean
+public abstract class ManagedBean
 {
    protected Logger log = Logger.getLogger(getClass());
 
    protected BeanContext beanContext;
+   public static final String INVALID_NAME = "INVALID_NAME_ERROR";
+   public static final String DUPLICATE = "DUPLICATE_ERROR";
 
    public void setBeanContext(BeanContext beanContext)
    {
       this.beanContext = beanContext;
    }
+
+   public String checkNameValidity(String name, String targetForErrorMessage)
+   {
+      if (ParameterValidation.isNullOrEmpty(name))
+      {
+         beanContext.createTargetedErrorMessage(targetForErrorMessage, INVALID_NAME, name, getLocalizedType());
+         return null;
+      }
+      else
+      {
+         // Trim name
+         name = name.trim();
+
+         // "sanitize" name: if it's invalid, return null and output message
+         name = ParameterValidation.sanitizeFromPatternWithHandler(name, ParameterValidation.XSS_CHECK,
+            new MessageValidationHandler(null, targetForErrorMessage, name));
+
+         // we got an invalid name, fail!
+         if (name == null)
+         {
+            return null;
+         }
+
+         // Check for duplicate
+         if (isAlreadyExisting(name))
+         {
+            beanContext.createTargetedErrorMessage(targetForErrorMessage, DUPLICATE, name, getLocalizedType());
+            return null;
+         }
+
+         return name;
+      }
+   }
+
+   private String getLocalizedType()
+   {
+      return beanContext.getMessageFromBundle(getObjectTypeName());
+   }
+
+   protected abstract String getObjectTypeName();
+
+   public abstract boolean isAlreadyExisting(String objectName);
+
+   /**
+    * @param oldValue
+    * @param newValue
+    * @return
+    * @todo public for test cases
+    */
+   public boolean isOldAndNewDifferent(Object oldValue, Object newValue)
+   {
+      oldValue = normalizeStringIfNeeded(oldValue);
+      newValue = normalizeStringIfNeeded(newValue);
+
+      return (oldValue != null && !oldValue.equals(newValue)) || (oldValue == null && newValue != null);
+   }
+
+   /**
+    * Normalizes String by considering empty String as null as JSF would give either and trim non-null Strings.
+    *
+    * @param value
+    * @return
+    * @todo public for test cases
+    */
+   public Object normalizeStringIfNeeded(Object value)
+   {
+      if (value == null)
+      {
+         return null;
+      }
+      else
+      {
+         if (value instanceof String)
+         {
+            String stringValue = (String)value;
+            return stringValue.length() == 0 ? null : stringValue.trim();
+         }
+         else
+         {
+            return value;
+         }
+      }
+   }
+
+   private class MessageValidationHandler extends ParameterValidation.ValidationErrorHandler
+   {
+      private String targetForErrorMessage;
+      private String validatedName;
+
+      private MessageValidationHandler(String defaultValue, String targetForErrorMessage, String validatedName)
+      {
+         super(defaultValue);
+         this.targetForErrorMessage = targetForErrorMessage;
+         this.validatedName = validatedName;
+      }
+
+      protected String internalValidationErrorHandling(String s)
+      {
+         beanContext.createTargetedErrorMessage(targetForErrorMessage, INVALID_NAME, validatedName, getLocalizedType());
+         return null;
+      }
+   }
 }

Copied: branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java (from rev 12964, branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java)
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java	                        (rev 0)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/faces/util/JSFFunctor.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -0,0 +1,126 @@
+/*
+* 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.jboss.portal.faces.util;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Allows to call a parameterized function in JSF EL expressions. See <a href="http://wiki.apache.org/myfaces/Parameters_In_EL_Functions">http://wiki.apache.org/myfaces/Parameters_In_EL_Functions</a>
+ * for more details. A better alternative would be to use JBoss-EL if it was available from the standard JBoss
+ * repository...
+ *
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public abstract class JSFFunctor implements Map<String, Object>
+{
+
+   /** Removes white spaces and periods from identifiers so that we can assign them to HTML id attributes. */
+   public static final JSFFunctor ID_SANITIZER = new JSFFunctor()
+   {
+      private String recent;
+      private String recentSanitized;
+
+      @Override
+      public Object get(Object parameter)
+      {
+         if (parameter instanceof String)
+         {
+            if (parameter.equals(recent))
+            {
+               return recentSanitized;
+            }
+
+            String id = (String)parameter;
+            recent = id;
+            recentSanitized = id.replace(' ', '_').replace('.', '_');
+            return recentSanitized;
+         }
+         return null;
+      }
+   };
+
+   public int size()
+   {
+      return 0;
+   }
+
+   public boolean isEmpty()
+   {
+      return false;
+   }
+
+   public boolean containsKey(Object key)
+   {
+      return false;
+   }
+
+   public boolean containsValue(Object value)
+   {
+      return false;
+   }
+
+   /**
+    * This is where the functor works. Subclasses need to implement the function logic here, the parameter being the
+    * specified parameter.
+    *
+    * @param parameter the value that will be used to compute the result of the function we want to implement
+    * @return the result of the funtion for the specified value
+    */
+   public abstract Object get(Object parameter);
+
+   public Object put(String key, Object value)
+   {
+      return null;
+   }
+
+   public Object remove(Object key)
+   {
+      return null;
+   }
+
+   public void putAll(Map<? extends String, ? extends Object> m)
+   {
+   }
+
+   public void clear()
+   {
+   }
+
+   public Set<String> keySet()
+   {
+      return null;
+   }
+
+   public Collection<Object> values()
+   {
+      return null;
+   }
+
+   public Set<Entry<String, Object>> entrySet()
+   {
+      return null;
+   }
+}

Copied: branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/ManagedBeanTestCase.java (from rev 12964, branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/test/faces/ManagedBeanTestCase.java)
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/ManagedBeanTestCase.java	                        (rev 0)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/ManagedBeanTestCase.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2009, 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.jboss.portal.test.faces;
+
+import junit.framework.TestCase;
+import org.jboss.portal.faces.gui.ManagedBean;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class ManagedBeanTestCase extends TestCase
+{
+   private ManagedBean bean;
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      bean = new ManagedBean()
+      {
+         @Override
+         protected String getObjectTypeName()
+         {
+            return "test";
+         }
+
+         @Override
+         public boolean isAlreadyExisting(String objectName)
+         {
+            return false;
+         }
+      };
+   }
+
+   public void testNormalizeStringIfNeeded()
+   {
+      assertEquals("foo", bean.normalizeStringIfNeeded("foo"));
+      assertEquals("foo", bean.normalizeStringIfNeeded("  foo  "));
+      assertEquals("foo", bean.normalizeStringIfNeeded("\t\nfoo\t"));
+      assertNull(bean.normalizeStringIfNeeded(null));
+      assertEquals(bean, bean.normalizeStringIfNeeded(bean));
+   }
+
+   public void testIsOldAndNewDifferent()
+   {
+      assertTrue(bean.isOldAndNewDifferent("foo", null));
+      assertTrue(bean.isOldAndNewDifferent(null, "foo"));
+      assertFalse(bean.isOldAndNewDifferent(null, null));
+   }
+}

Copied: branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/MessageFormatTestCase.java (from rev 12964, branches/JBoss_Portal_Branch_2_7/faces/src/main/org/jboss/portal/test/faces/MessageFormatTestCase.java)
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/MessageFormatTestCase.java	                        (rev 0)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/org/jboss/portal/test/faces/MessageFormatTestCase.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -0,0 +1,51 @@
+/*
+* 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.jboss.portal.test.faces;
+
+import junit.framework.TestCase;
+
+import java.text.MessageFormat;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class MessageFormatTestCase extends TestCase
+{
+   public void testFormat()
+   {
+      String input = "''{0}'' is not a valid URL: {1}";
+      String output = "'foo' is not a valid URL: bar";
+      assertEquals(output, MessageFormat.format(input, new String[] {"foo", "bar"}));
+
+
+      // Don't forget to escape single quotes in localization files if there are parameters to be interpreted
+      input = "Couldn't reload producer configuration. Cause: {0}";
+      output = "Couldnt reload producer configuration. Cause: {0}";
+      assertEquals(output, MessageFormat.format(input, new String[]{"foo"}));
+
+      input = "Couldn''t reload producer configuration. Cause: {0}";
+      output = "Couldn't reload producer configuration. Cause: foo";
+      assertEquals(output, MessageFormat.format(input, new String[]{"foo"}));
+   }
+}

Copied: branches/JBoss_Portal_AS5_Deployer/faces/src/main/util (from rev 12964, branches/JBoss_Portal_Branch_2_7/faces/src/main/util)

Deleted: branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/JSFFunctorTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_7/faces/src/main/util/JSFFunctorTestCase.java	2009-03-06 20:30:12 UTC (rev 12964)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/JSFFunctorTestCase.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -1,63 +0,0 @@
-/*
-* 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 util;
-
-import junit.framework.TestCase;
-import org.jboss.portal.faces.util.JSFFunctor;
-
-/**
- * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision$
- */
-public class JSFFunctorTestCase extends TestCase
-{
-   private JSFFunctor functor = JSFFunctor.ID_SANITIZER;
-
-   public void testGet()
-   {
-      assertNull(functor.get(null));
-      assertEquals("foo_bar", functor.get("foo bar"));
-      assertEquals("foo_bar", functor.get("foo.bar"));
-      assertEquals("foo______bar", functor.get("foo     .bar"));
-      assertEquals("foo_bar_baz_boo", functor.get("foo.bar baz.boo"));
-   }
-
-   public void testSimplePerformance()
-   {
-      for (int i = 0; i < 500000; i++)
-      {
-         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
-      }
-   }
-
-   public void testRepeatedPerformance()
-   {
-      for (int i = 0; i < 100000; i++)
-      {
-         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
-         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
-         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
-         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
-      }
-   }
-}

Copied: branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/JSFFunctorTestCase.java (from rev 12964, branches/JBoss_Portal_Branch_2_7/faces/src/main/util/JSFFunctorTestCase.java)
===================================================================
--- branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/JSFFunctorTestCase.java	                        (rev 0)
+++ branches/JBoss_Portal_AS5_Deployer/faces/src/main/util/JSFFunctorTestCase.java	2009-03-06 23:22:14 UTC (rev 12981)
@@ -0,0 +1,63 @@
+/*
+* 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 util;
+
+import junit.framework.TestCase;
+import org.jboss.portal.faces.util.JSFFunctor;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision$
+ */
+public class JSFFunctorTestCase extends TestCase
+{
+   private JSFFunctor functor = JSFFunctor.ID_SANITIZER;
+
+   public void testGet()
+   {
+      assertNull(functor.get(null));
+      assertEquals("foo_bar", functor.get("foo bar"));
+      assertEquals("foo_bar", functor.get("foo.bar"));
+      assertEquals("foo______bar", functor.get("foo     .bar"));
+      assertEquals("foo_bar_baz_boo", functor.get("foo.bar baz.boo"));
+   }
+
+   public void testSimplePerformance()
+   {
+      for (int i = 0; i < 500000; i++)
+      {
+         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+      }
+   }
+
+   public void testRepeatedPerformance()
+   {
+      for (int i = 0; i < 100000; i++)
+      {
+         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+         assertEquals("foo" + i + "_bar", functor.get("foo" + i + " bar"));
+      }
+   }
+}




More information about the portal-commits mailing list